test: add unit test

This commit is contained in:
Kamil Myśliwiec
2024-11-25 13:48:54 +01:00
parent 21279a9c49
commit ab660c7edd

View File

@@ -113,11 +113,26 @@ describe('ServerNats', () => {
[pattern]: messageHandler,
});
});
it('should subscribe to each acknowledge patterns', () => {
it('should subscribe to every pattern', () => {
server.bindEvents(natsClient);
expect(subscribeSpy.calledWith(pattern)).to.be.true;
});
it('should use a per pattern queue if provided', () => {
const queue = 'test';
untypedServer.messageHandlers = objectToMap({
[pattern]: Object.assign(messageHandler, {
extras: {
queue,
},
}),
});
server.bindEvents(natsClient);
const lastCall = subscribeSpy.lastCall;
expect(lastCall.args[1].queue).to.be.eql(queue);
});
it('should fill the subscriptions array properly', () => {
server.bindEvents(natsClient);
expect(server['subscriptions'].length).to.be.equals(1);