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 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
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: '',
};

const response = await request(app.getHttpServer())
Fixed Show fixed Hide fixed
.post('/auth/register')
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.send(createItemDto)
.expect(JSON.stringify({
register: true,
}))
.expect(HttpStatus.OK)
});
});
109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dev:backend": "npx nx run backend:serve:development",
"dev:workers": "npx nx run workers:serve:development",
"dev:cron": "npx nx run cron:serve:development",
"test:backend": "nx test --project backend -- --silent=false --verbose=false",
"start:prod": "node dist/apps/backend/main.js",
"start:prod:frontend": "nx run frontend:serve:production",
"start:prod:workers": "node dist/apps/workers/main.js",
Expand Down Expand Up @@ -192,6 +193,7 @@
"prisma": "^5.8.1",
"react-refresh": "^0.10.0",
"sass": "1.62.1",
"supertest": "^7.0.0",
"ts-jest": "^29.1.0",
"ts-node": "10.9.1",
"typescript": "5.5.4",
Expand Down