|
| 1 | +import { expect } from 'chai'; |
| 2 | +import * as sinon from 'sinon'; |
| 3 | +import { NO_MESSAGE_HANDLER } from '../../constants'; |
| 4 | +import { ServerTCP } from '../../server/server-tcp'; |
| 5 | +import { ServerKafka } from '../../server'; |
| 6 | +import { Consumer, IHeaders, KafkaMessage } from '../../external/kafka.interface'; |
| 7 | + |
| 8 | +describe('ServerKafka', () => { |
| 9 | + let server: ServerKafka; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + server = new ServerKafka({}); |
| 13 | + }); |
| 14 | + |
| 15 | + afterEach(() => { |
| 16 | + server.close(); |
| 17 | + }); |
| 18 | + describe('close', () => { |
| 19 | + it('should close server', () => { |
| 20 | + server.close(); |
| 21 | + expect(server.consumer).to.be.null; |
| 22 | + expect(server.producer).to.be.null; |
| 23 | + expect(server.client).to.be.null; |
| 24 | + }); |
| 25 | + }); |
| 26 | + describe('listen', () => { |
| 27 | + it('should start server', async () => { |
| 28 | + const callback = sinon.spy(); |
| 29 | + await server.listen(callback); |
| 30 | + expect(callback.called).to.be.true; |
| 31 | + }); |
| 32 | + it('should have kafka, producer and consumer connected', async () => { |
| 33 | + await server.listen(() => {}); |
| 34 | + expect(server.client).to.be.not.null; |
| 35 | + expect(server.producer).to.be.not.null; |
| 36 | + expect(server.consumer).to.be.not.null; |
| 37 | + }); |
| 38 | + }); |
| 39 | +}); |
0 commit comments