From eeebe82085c40edbef64c288e7e207c21218a067 Mon Sep 17 00:00:00 2001 From: suyash97 Date: Mon, 27 Jun 2022 19:35:17 +0530 Subject: [PATCH 1/2] Added changes for E2E tests --- apps/api/src/app/app.controller.spec.ts | 19 +++++++++++++++- apps/api/src/app/app.service.spec.ts | 2 +- apps/api/test/app.e2e.spec.ts | 30 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 apps/api/test/app.e2e.spec.ts diff --git a/apps/api/src/app/app.controller.spec.ts b/apps/api/src/app/app.controller.spec.ts index 6a607278..dcd0e7b6 100644 --- a/apps/api/src/app/app.controller.spec.ts +++ b/apps/api/src/app/app.controller.spec.ts @@ -3,14 +3,17 @@ import { createMock } from '@golevelup/ts-jest'; import { AppController } from './app.controller'; import { AppService } from './app.service'; -import { RedisService } from 'nestjs-redis'; +import { RedisHealthModule } from '@liaoliaots/nestjs-redis/health'; +import { RedisService } from '@liaoliaots/nestjs-redis'; import { PrismaService } from './prisma.service'; +import { PrismaHealthIndicator } from './prisma/prisma.health'; import { RouterService } from './router/router.service'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { TerminusModule } from '@nestjs/terminus'; import { ClientsModule, Transport } from '@nestjs/microservices'; import { TelemetryService } from './telemetry/telemetry.service'; import { PosthogModule } from 'nestjs-posthog'; +import { RedisModule } from '@liaoliaots/nestjs-redis'; describe('AppController', () => { let controller: AppController; @@ -33,6 +36,18 @@ describe('AppController', () => { isGlobal: true, envFilePath: ['.env.local', '.env'], }), + RedisModule.forRootAsync({ + useFactory: (config: ConfigService) => { + return { + readyLog: true, + config: { + name: 'db', + url: config.get('REDIS_URI'), + } + }; + }, + inject: [ConfigService], + }), ClientsModule.registerAsync([ { name: 'CLICK_SERVICE', @@ -64,6 +79,7 @@ describe('AppController', () => { }, inject: [ConfigService], }), + RedisHealthModule, ], controllers: [AppController], providers: [ @@ -71,6 +87,7 @@ describe('AppController', () => { ConfigService, { provide: RedisService, useValue: mockRedisService }, PrismaService, + PrismaHealthIndicator, RouterService, TelemetryService ], diff --git a/apps/api/src/app/app.service.spec.ts b/apps/api/src/app/app.service.spec.ts index 88033d92..1fb8b901 100644 --- a/apps/api/src/app/app.service.spec.ts +++ b/apps/api/src/app/app.service.spec.ts @@ -1,5 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { RedisService } from 'nestjs-redis'; +import { RedisService } from '@liaoliaots/nestjs-redis'; import { AppService } from './app.service'; import { PrismaService } from './prisma.service'; diff --git a/apps/api/test/app.e2e.spec.ts b/apps/api/test/app.e2e.spec.ts new file mode 100644 index 00000000..8ae06c81 --- /dev/null +++ b/apps/api/test/app.e2e.spec.ts @@ -0,0 +1,30 @@ +import * as supertest from 'supertest'; + +import { Test, TestingModule } from '@nestjs/testing'; + +import { AppModule } from './../src/app/app.module'; +import { INestApplication } from '@nestjs/common'; + +describe('AppController (e2e)', () => { + let app: INestApplication; + + beforeEach(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + // add mock data to prisma + }); + it('/sr/{code} e2e', () => { + return supertest(app.getHttpServer()) + .get('/sr/vlr') + .expect(200) + }); + it('/{hashid} e2e', () => { + return supertest(app.getHttpServer()) + .get('/198') + .expect(200) + }); +}); \ No newline at end of file From 55b9cec6d6205c1ced1c7a39c0d7c2fe738a961d Mon Sep 17 00:00:00 2001 From: suyash97 Date: Mon, 27 Jun 2022 21:56:56 +0530 Subject: [PATCH 2/2] Update package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index a5386780..fae86cee 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "reflect-metadata": "^0.1.13", "regenerator-runtime": "0.13.7", "rxjs": "^7.0.0", + "supertest": "^6.2.3", "tslib": "^2.3.0" }, "devDependencies": {