Add unit and e2e tests for PaymentsController, PaymentsService, and AppController

This commit is contained in:
Jose Eduardo 2025-08-03 20:58:02 -04:00
parent 86798bfd42
commit 1d2fdd470b
4 changed files with 72 additions and 0 deletions

View File

@ -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>(PaymentsController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -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>(PaymentsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

25
test/app.e2e-spec.ts Normal file
View File

@ -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<App>;
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!');
});
});

9
test/jest-e2e.json Normal file
View File

@ -0,0 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}