Skip to content

Commit 4ec8e34

Browse files
test(microservices) fix unit tests
1 parent 4796023 commit 4ec8e34

4 files changed

Lines changed: 21 additions & 18 deletions

File tree

packages/microservices/server/server-nats.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ export class ServerNats extends Server implements CustomTransportStrategy {
4141

4242
public bindEvents(client: Client) {
4343
const queue = this.getOptionsProp<NatsOptions>(this.options, 'queue');
44-
const subscribe = (channel: string) => {
45-
if (queue) {
46-
return client.subscribe(
47-
channel,
48-
{ queue },
49-
this.getMessageHandler(channel, client).bind(this),
50-
);
51-
}
52-
client.subscribe(
53-
channel,
54-
this.getMessageHandler(channel, client).bind(this),
55-
);
56-
};
57-
const registeredPatterns = Object.keys(this.messageHandlers);
44+
const subscribe = queue
45+
? (channel: string) =>
46+
client.subscribe(
47+
channel,
48+
{ queue },
49+
this.getMessageHandler(channel, client).bind(this),
50+
)
51+
: (channel: string) =>
52+
client.subscribe(
53+
channel,
54+
this.getMessageHandler(channel, client).bind(this),
55+
);
56+
57+
const registeredPatterns = [...this.messageHandlers.keys()];
5858
registeredPatterns.forEach(channel => subscribe(channel));
5959
}
6060

packages/microservices/test/server/server-nats.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('ServerNats', () => {
5252
subscribe: subscribeSpy,
5353
};
5454
});
55-
it('should subscribe each acknowledge patterns', () => {
55+
it('should subscribe to each acknowledge patterns', () => {
5656
const pattern = 'test';
5757
const handler = sinon.spy();
5858

packages/microservices/test/server/server-rmq.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ describe('ServerRMQ', () => {
9393
});
9494
it('should call handler if exists in handlers object', async () => {
9595
const handler = sinon.spy();
96-
(server as any).messageHandlers = {
96+
const objectToMap = obj =>
97+
new Map(Object.keys(obj).map(key => [key, obj[key]]) as any);
98+
99+
(server as any).messageHandlers = objectToMap({
97100
[JSON.stringify(pattern)]: handler as any,
98-
};
101+
});
99102
await server.handleMessage(msg);
100103
expect(handler.calledOnce).to.be.true;
101104
});

packages/microservices/test/server/server-tcp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('ServerTCP', () => {
7272
new Map(Object.keys(obj).map(key => [key, obj[key]]) as any);
7373

7474
(server as any).messageHandlers = objectToMap({
75-
[JSON.stringify(msg.pattern)]: handler as any,
75+
[msg.pattern]: handler as any,
7676
});
7777
server.handleMessage(socket, msg);
7878
expect(handler.calledOnce).to.be.true;

0 commit comments

Comments
 (0)