Skip to content

Commit

Permalink
fix tests, harness, and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tmthecoder committed Sep 13, 2024
1 parent 0ffc63d commit 99f0557
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
3 changes: 1 addition & 2 deletions packages/api-gateway/src/modules/email/email.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -76,7 +76,6 @@ export class EmailController implements OnModuleInit {
subdomain,
});

console.log(res);
return lastValueFrom(res);
}

Expand Down
46 changes: 9 additions & 37 deletions packages/api-gateway/test/email.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,15 +69,15 @@ 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: '[email protected]',
})
.expect(401);
});
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: '[email protected]',
Expand All @@ -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: '[email protected]',
Expand All @@ -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')
Expand Down Expand Up @@ -400,31 +385,18 @@ 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);
});

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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 99f0557

Please sign in to comment.