Skip to content

Commit

Permalink
fix: e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avsetsin committed Nov 2, 2022
1 parent b7ee5df commit 977368e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/tests_and_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ jobs:
run: yarn lint
- name: Run tests
run: yarn test

- name: Create e2e docker containers
run: docker-compose up -d

- name: Run e2e transports
run: docker-compose -f docker-compose.test.yml up -d
- name: Run e2e tests
run: yarn test:e2e

Expand Down
22 changes: 17 additions & 5 deletions src/transport/kafka/kafka.transport.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { Test, TestingModule } from '@nestjs/testing';
import { LoggerService } from '@nestjs/common';
import { LoggerModule } from 'common/logger';
import { ConfigModule } from 'common/config';
import { MockProviderModule } from 'provider';
import { KafkaTransport } from './kafka.transport';
import { Kafka } from 'kafkajs';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { MessageType } from '../../messages';

describe('KafkaTransport', () => {
let transport: KafkaTransport;
let moduleRef: TestingModule;
let loggerService: LoggerService;

beforeEach(async () => {
moduleRef = await Test.createTestingModule({
imports: [ConfigModule.forRoot(), LoggerModule],
imports: [
ConfigModule.forRoot(),
MockProviderModule.forRoot(),
LoggerModule,
],
providers: [
KafkaTransport,
{
Expand All @@ -27,6 +35,10 @@ describe('KafkaTransport', () => {
}).compile();

transport = moduleRef.get(KafkaTransport);
loggerService = moduleRef.get(WINSTON_MODULE_NEST_PROVIDER);

jest.spyOn(loggerService, 'log').mockImplementation(() => undefined);
jest.spyOn(loggerService, 'debug').mockImplementation(() => undefined);
});

afterEach(async () => {
Expand All @@ -38,13 +50,13 @@ describe('KafkaTransport', () => {
it('should send two messages to topic and read two messages from topic', async () => {
const receivedMessages: any[] = [];

await transport.publish('test', { label: 'first' }, MessageType.PING);
await transport.publish('test', { label: 'second' }, MessageType.PING);

await transport.subscribe('test', MessageType.PING, async (msg) => {
receivedMessages.push(msg);
});

await transport.publish('test', { label: 'first' }, MessageType.PING);
await transport.publish('test', { label: 'second' }, MessageType.PING);

await new Promise<void>(async (resolve) => {
setTimeout(resolve, 3000);
});
Expand All @@ -54,6 +66,6 @@ describe('KafkaTransport', () => {
expect(receivedMessages[0].label).toBe('first');
expect(receivedMessages[1]).toHaveProperty('label');
expect(receivedMessages[1].label).toBe('second');
});
}, 10_000);
});
});

0 comments on commit 977368e

Please sign in to comment.