From 1d2fdd470bea653b39647bb56ff0b6de13598360 Mon Sep 17 00:00:00 2001 From: jos3duardo Date: Sun, 3 Aug 2025 20:58:02 -0400 Subject: [PATCH] Add unit and e2e tests for PaymentsController, PaymentsService, and AppController --- .../tests/payments.controller.spec.ts | 20 +++++++++++++++ .../payments/tests/payments.service.spec.ts | 18 +++++++++++++ test/app.e2e-spec.ts | 25 +++++++++++++++++++ test/jest-e2e.json | 9 +++++++ 4 files changed, 72 insertions(+) create mode 100644 src/modules/payments/tests/payments.controller.spec.ts create mode 100644 src/modules/payments/tests/payments.service.spec.ts create mode 100644 test/app.e2e-spec.ts create mode 100644 test/jest-e2e.json diff --git a/src/modules/payments/tests/payments.controller.spec.ts b/src/modules/payments/tests/payments.controller.spec.ts new file mode 100644 index 0000000..339d86a --- /dev/null +++ b/src/modules/payments/tests/payments.controller.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { PaymentsController } from '../payments.controller'; +import { PaymentsService } from '../payments.service'; + +describe('PaymentsController', () => { + let controller: PaymentsController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [PaymentsController], + providers: [PaymentsService], + }).compile(); + + controller = module.get(PaymentsController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/modules/payments/tests/payments.service.spec.ts b/src/modules/payments/tests/payments.service.spec.ts new file mode 100644 index 0000000..11b09a5 --- /dev/null +++ b/src/modules/payments/tests/payments.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { PaymentsService } from '../payments.service'; + +describe('PaymentsService', () => { + let service: PaymentsService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [PaymentsService], + }).compile(); + + service = module.get(PaymentsService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts new file mode 100644 index 0000000..4df6580 --- /dev/null +++ b/test/app.e2e-spec.ts @@ -0,0 +1,25 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import * as request from 'supertest'; +import { App } from 'supertest/types'; +import { AppModule } from './../src/app.module'; + +describe('AppController (e2e)', () => { + let app: INestApplication; + + beforeEach(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + }); + + it('/ (GET)', () => { + return request(app.getHttpServer()) + .get('/') + .expect(200) + .expect('Hello World!'); + }); +}); diff --git a/test/jest-e2e.json b/test/jest-e2e.json new file mode 100644 index 0000000..e9d912f --- /dev/null +++ b/test/jest-e2e.json @@ -0,0 +1,9 @@ +{ + "moduleFileExtensions": ["js", "json", "ts"], + "rootDir": ".", + "testEnvironment": "node", + "testRegex": ".e2e-spec.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + } +}