-
Notifications
You must be signed in to change notification settings - Fork 0
LAU-27: add integration tests for auth and workspace resolvers #23
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
Changes from all commits
9ca535f
fa5e13e
3cc5b51
c2d7c0b
7addc39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,247 @@ | ||||||||||
| import { Test, TestingModule } from '@nestjs/testing'; | ||||||||||
| import { AuthModule, MainAuthGuard } from '@launchline/core-auth'; | ||||||||||
| import request from 'supertest'; | ||||||||||
| import { INestApplication, HttpStatus } from '@nestjs/common'; | ||||||||||
| import { MockConfigModule } from '../support/config.module.mock'; | ||||||||||
| import { MockCommonModule } from '../support/common.module.mock'; | ||||||||||
| import { DB_CONNECTION, user, otp } from '@launchline/core-common'; | ||||||||||
| import { NodePgDatabase } from 'drizzle-orm/node-postgres'; | ||||||||||
| import { eq } from 'drizzle-orm'; | ||||||||||
| import { Pool } from 'pg'; | ||||||||||
| import { MockDbModule } from '../support/db.module.mock'; | ||||||||||
| import { MockRedisModule } from '../support/redis.module.mock'; | ||||||||||
| import { MockEventBusModule } from '../support/eventbus.module.mock'; | ||||||||||
| import { randomUUID } from 'node:crypto'; | ||||||||||
| import session from 'express-session'; | ||||||||||
| import passport from 'passport'; | ||||||||||
| import { MockMainAuthGuard } from '../support/auth.guard.mock'; | ||||||||||
| import { UserRole } from '@launchline/models'; | ||||||||||
| import { MockAnalyticsModule } from '../support/analytics.module.mock'; | ||||||||||
|
|
||||||||||
| describe('AuthController (integration)', () => { | ||||||||||
| const emailForOtp = 'email-otp@example.com'; | ||||||||||
| let app: INestApplication; | ||||||||||
| let db: NodePgDatabase & { $client: Pool }; | ||||||||||
| let verifiedUser: typeof user.$inferSelect; | ||||||||||
| let unverifiedUser: typeof user.$inferSelect; | ||||||||||
| let otpCode: string; | ||||||||||
|
|
||||||||||
| beforeAll(async () => { | ||||||||||
| const moduleFixture: TestingModule = await Test.createTestingModule({ | ||||||||||
| imports: [ | ||||||||||
| AuthModule, | ||||||||||
| MockDbModule, | ||||||||||
| MockRedisModule, | ||||||||||
| MockConfigModule, | ||||||||||
| MockCommonModule, | ||||||||||
| MockEventBusModule, | ||||||||||
| MockAnalyticsModule, | ||||||||||
| ], | ||||||||||
| }) | ||||||||||
| .overrideProvider(MainAuthGuard) | ||||||||||
| .useValue(MockMainAuthGuard) | ||||||||||
|
dkarasiewicz marked this conversation as resolved.
|
||||||||||
| .compile(); | ||||||||||
|
|
||||||||||
| app = moduleFixture.createNestApplication(); | ||||||||||
|
|
||||||||||
| app.use( | ||||||||||
| session({ | ||||||||||
| secret: 'test-secret', | ||||||||||
| resave: false, | ||||||||||
| saveUninitialized: false, | ||||||||||
| }), | ||||||||||
| ); | ||||||||||
|
dkarasiewicz marked this conversation as resolved.
|
||||||||||
| app.use(passport.session()); | ||||||||||
|
|
||||||||||
| db = app.get(DB_CONNECTION); | ||||||||||
|
|
||||||||||
| await app.init(); | ||||||||||
|
Comment on lines
+29
to
+58
|
||||||||||
| }); | ||||||||||
|
|
||||||||||
| beforeEach(async () => { | ||||||||||
| otpCode = '123456'; | ||||||||||
|
|
||||||||||
| // Create verified user | ||||||||||
| [verifiedUser] = await db | ||||||||||
| .insert(user) | ||||||||||
| .values({ | ||||||||||
| id: randomUUID(), | ||||||||||
| updatedAt: new Date(), | ||||||||||
| email: 'verified@example.com', | ||||||||||
| role: UserRole.WORKSPACE_MEMBER, | ||||||||||
| createdAt: new Date(), | ||||||||||
| isEmailVerified: true, | ||||||||||
| }) | ||||||||||
| .returning(); | ||||||||||
|
|
||||||||||
| // Create unverified user for OTP verification flow | ||||||||||
| [unverifiedUser] = await db | ||||||||||
| .insert(user) | ||||||||||
| .values({ | ||||||||||
| id: randomUUID(), | ||||||||||
| updatedAt: new Date(), | ||||||||||
| email: 'unverified@example.com', | ||||||||||
| role: UserRole.WORKSPACE_MEMBER, | ||||||||||
| createdAt: new Date(), | ||||||||||
| isEmailVerified: false, | ||||||||||
| }) | ||||||||||
| .returning(); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| afterEach(async () => { | ||||||||||
| jest.clearAllMocks(); | ||||||||||
|
|
||||||||||
| await db.$client.query('TRUNCATE TABLE "Otp" CASCADE;'); | ||||||||||
| await db.$client.query('TRUNCATE TABLE "User" CASCADE;'); | ||||||||||
|
dkarasiewicz marked this conversation as resolved.
Comment on lines
+94
to
+95
|
||||||||||
| await db.$client.query('TRUNCATE TABLE "Otp" CASCADE;'); | |
| await db.$client.query('TRUNCATE TABLE "User" CASCADE;'); | |
| await db.delete(otp); | |
| await db.delete(user); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable 'emailForOtp' is declared but never used in the tests. It appears to have been intended for the 'should return 401 when user does not exist' test at line 208, but 'emailForOtp' was defined instead as a test-specific value. Consider removing this unused variable.