import NatsAdaptor from "../src/adaptors/nats"; import { Message } from "../src/messages"; import Service from "../src/service"; let srv!: Service; const serviceName = "test-service"; const adaptorName = "nats"; const subject = "test"; const dataExpected = "hello world"; const statusCodeExpected = 200; beforeEach(() => { srv = new Service(serviceName); }); afterEach(async () => { await srv.stop(); }); test('nats adaptor', async () => { srv.addAdaptor(adaptorName, new NatsAdaptor({ servers: ['127.0.0.1:4222'] })); srv.subscribe(adaptorName, subject, async (msg: Message) => { return {data: msg.data, statusCode: statusCodeExpected}; }); await srv.listen(); const res = await srv.request(adaptorName, {service: serviceName, subject: subject, data: dataExpected}); expect(res.data).toBe(dataExpected); expect(res.statusCode).toBe(statusCodeExpected); });