From 99f0557838a9efd3a64f3b4314d562ac50877c43 Mon Sep 17 00:00:00 2001 From: Tejas Mehta Date: Thu, 12 Sep 2024 20:15:15 -0400 Subject: [PATCH] fix tests, harness, and clean up --- .../src/modules/email/email.controller.ts | 3 +- packages/api-gateway/test/email.e2e-spec.ts | 46 ++++--------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/packages/api-gateway/src/modules/email/email.controller.ts b/packages/api-gateway/src/modules/email/email.controller.ts index 3e7aff04..3f7a5927 100644 --- a/packages/api-gateway/src/modules/email/email.controller.ts +++ b/packages/api-gateway/src/modules/email/email.controller.ts @@ -54,7 +54,7 @@ export class EmailController implements OnModuleInit { }) @ApiUnauthorizedResponse({ description: 'Unauthorized' }) @ApiBadRequestResponse({ description: 'Bad Request' }) - @Post('register') + @Post('/register-sender') async registerSenderAddress(@Body('') params: RegisterEmailModel) { return new RegisterEmailResponse(params.email); } @@ -76,7 +76,6 @@ export class EmailController implements OnModuleInit { subdomain, }); - console.log(res); return lastValueFrom(res); } diff --git a/packages/api-gateway/test/email.e2e-spec.ts b/packages/api-gateway/test/email.e2e-spec.ts index 34f5a968..2977adb6 100644 --- a/packages/api-gateway/test/email.e2e-spec.ts +++ b/packages/api-gateway/test/email.e2e-spec.ts @@ -53,14 +53,14 @@ describe('Email Registration Routes', () => { it('Registers an email without a body', () => { const token = jwt.sign({}, 'secret'); return request(app.getHttpServer()) - .post('/email/register') + .post('/email/register-sender') .set('Authorization', 'Bearer ' + token) .expect(400); }); it('Has been called with a malformed emaiil', () => { const token = jwt.sign({}, 'secret'); return request(app.getHttpServer()) - .post('/email/register') + .post('/email/register-sender') .set('Authorization', 'Bearer ' + token) .send({ email: 'invalidemail', // Malformed email @@ -69,7 +69,7 @@ describe('Email Registration Routes', () => { }); it('Registration endpoint called with no Authorization header', () => { return request(app.getHttpServer()) - .post('/email/register') + .post('/email/register-sender') .send({ email: 'validemail@example.com', }) @@ -77,7 +77,7 @@ describe('Email Registration Routes', () => { }); it('Registration endpoint called with an invalid JWT', () => { return request(app.getHttpServer()) - .post('/email/register') + .post('/email/register-sender') .set('Authorization', 'Bearer invalid.jwt.token') .send({ email: 'validemail@example.com', @@ -88,7 +88,7 @@ describe('Email Registration Routes', () => { // Assuming 'valid.jwt.token' is a placeholder for a valid JWT obtained in a way relevant to your test setup const token = jwt.sign({}, 'secret'); return request(app.getHttpServer()) - .post('/email/register') + .post('/email/register-sender') .set('Authorization', 'Bearer ' + token) .send({ email: 'validemail@example.com', @@ -98,21 +98,6 @@ describe('Email Registration Routes', () => { }); describe('Email Sending Route', () => { - let app: INestApplication; - - beforeAll(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication(); - await app.init(); - }); - - afterAll(async () => { - await app.close(); - }); - it('should return 401 when Authorization header is missing', async () => { return request(app.getHttpServer()) .post('/email/send') @@ -400,23 +385,10 @@ describe('Email Sending Route', () => { }); describe('Domain Registration Routes', () => { - let app: NestApplication; - beforeAll(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication(); - await app.init(); - }); - - afterAll(async () => { - await app.close(); - }); it('Registers a domain without a domain parameter', () => { const token = jwt.sign({}, 'secret'); return request(app.getHttpServer()) - .post('/registerDomain') + .post('/email/register-domain') .set('Authorization', 'Bearer ' + token) .expect(400); }); @@ -424,7 +396,7 @@ describe('Domain Registration Routes', () => { it('Registers a domain with valid parameters', () => { const token = jwt.sign({}, 'secret'); return request(app.getHttpServer()) - .post('/registerDomain') + .post('/email/register-domain') .set('Authorization', 'Bearer ' + token) .send({ domain: 'example.com', @@ -435,7 +407,7 @@ describe('Domain Registration Routes', () => { it('Registration endpoint called with no Authorization header', () => { return request(app.getHttpServer()) - .post('/registerDomain') + .post('/email/register-domain') .send({ domain: 'example.com', subdomain: 'sub', @@ -445,7 +417,7 @@ describe('Domain Registration Routes', () => { it('Registration endpoint called with an invalid JWT', () => { return request(app.getHttpServer()) - .post('/registerDomain') + .post('/email/register-domain') .set('Authorization', 'Bearer invalid.jwt.token') .send({ domain: 'example.com',