Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add first e2e test for AuthController #331

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/backend/__mocks__/@prisma/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PrismockClient } from 'prismock';

export * from '@prisma/client';
export { PrismockClient as PrismaClient };
54 changes: 54 additions & 0 deletions apps/backend/test/api/routes/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from '../../../src/api/routes/auth.controller';
import { AuthService } from '../../../src/services/auth/auth.service';
import { UsersService } from '@gitroom/nestjs-libraries/database/prisma/users/users.service';
import { UsersRepository } from '@gitroom/nestjs-libraries/database/prisma/users/users.repository';
import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.service';
import { OrganizationRepository } from '@gitroom/nestjs-libraries/database/prisma/organizations/organization.repository';
import { NotificationService } from '@gitroom/nestjs-libraries/database/prisma/notifications/notification.service';
import { NotificationsRepository } from '@gitroom/nestjs-libraries/database/prisma/notifications/notifications.repository';
import { EmailService } from '@gitroom/nestjs-libraries/services/email.service';
import { PrismaRepository, PrismaService } from '@gitroom/nestjs-libraries/database/prisma/prisma.service';
import { HttpStatus, INestApplication, ValidationPipe } from '@nestjs/common';
import request from 'supertest';

describe('AuthController (e2e)', () => {
let app: INestApplication;

beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
providers: [AuthService, UsersService, OrganizationService, NotificationService, EmailService, UsersRepository, OrganizationRepository, NotificationsRepository, PrismaRepository, PrismaService],
}).compile();

app = moduleFixture.createNestApplication();
app.useGlobalPipes(new ValidationPipe({transform: true})); // Optional: for request validation
await app.init();
});

afterAll(async () => {
if (app != null) {
await app.close();
}
});

it('register a user', async () => {
const createItemDto = {
email: '[email protected]',
company: 'none',
password: 'nothing',
provider: 'LOCAL',
providerToken: '',
};

await request(app.getHttpServer())
.post('/auth/register')
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.send(createItemDto)
.expect(JSON.stringify({
register: true,
}))
.expect(HttpStatus.OK)
});
});
Loading