diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 71e06e73..71c76ff6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1,5 @@ # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners apps/web @kriptonian1 -apps/workspace @kriptonian1 +apps/platform @kriptonian1 apps/api @rajdip-b diff --git a/apps/api/src/auth/auth.e2e.spec.ts b/apps/api/src/auth/auth.e2e.spec.ts index 26211dad..6f2cde10 100644 --- a/apps/api/src/auth/auth.e2e.spec.ts +++ b/apps/api/src/auth/auth.e2e.spec.ts @@ -8,14 +8,12 @@ import { AuthModule } from './auth.module' import { MAIL_SERVICE } from '../mail/services/interface.service' import { MockMailService } from '../mail/services/mock.service' import { AppModule } from '../app/app.module' -import { Otp } from '@prisma/client' -import cleanUp from '../common/cleanup' +import { AuthService } from './service/auth.service' describe('Auth Controller Tests', () => { let app: NestFastifyApplication let prisma: PrismaService - - let otp: Otp + let authService: AuthService beforeAll(async () => { const moduleRef = await Test.createTestingModule({ @@ -29,11 +27,14 @@ describe('Auth Controller Tests', () => { new FastifyAdapter() ) prisma = moduleRef.get(PrismaService) + authService = moduleRef.get(AuthService) await app.init() await app.getHttpAdapter().getInstance().ready() + }) - await cleanUp(prisma) + afterEach(async () => { + await prisma.user.deleteMany() }) it('should be defined', async () => { @@ -71,7 +72,9 @@ describe('Auth Controller Tests', () => { }) it('should have generated an otp', async () => { - otp = await prisma.otp.findFirst({ + await authService.sendOtp('johndoe@keyshade.xyz') + + const otp = await prisma.otp.findFirst({ where: { user: { email: 'johndoe@keyshade.xyz' @@ -86,6 +89,15 @@ describe('Auth Controller Tests', () => { }) it('should upsert otp if regenerated', async () => { + await authService.sendOtp('johndoe@keyshade.xyz') + const otp = await prisma.otp.findFirst({ + where: { + user: { + email: 'johndoe@keyshade.xyz' + } + } + }) + await app.inject({ method: 'POST', url: '/auth/send-otp/johndoe@keyshade.xyz' @@ -104,8 +116,6 @@ describe('Auth Controller Tests', () => { expect(regenerated.expiresAt).toBeDefined() expect(regenerated.code.length).toBe(6) expect(regenerated.code).not.toBe(otp.code) - - otp = regenerated }) it('should not be able to validate otp with invalid email', async () => { @@ -118,6 +128,8 @@ describe('Auth Controller Tests', () => { }) it('should not be able to validate otp with invalid otp', async () => { + await authService.sendOtp('johndoe@keyshade.xyz') + const response = await app.inject({ method: 'POST', url: '/auth/validate-otp?email=johndoe@keyshade.xyz&otp=123456' @@ -125,8 +137,4 @@ describe('Auth Controller Tests', () => { expect(response.statusCode).toBe(401) }) - - afterAll(async () => { - await cleanUp(prisma) - }) }) diff --git a/apps/api/src/auth/guard/auth/auth.guard.ts b/apps/api/src/auth/guard/auth/auth.guard.ts index 700f7d11..014d36a1 100644 --- a/apps/api/src/auth/guard/auth/auth.guard.ts +++ b/apps/api/src/auth/guard/auth/auth.guard.ts @@ -12,6 +12,7 @@ import { PrismaService } from '../../../prisma/prisma.service' import { ONBOARDING_BYPASSED } from '../../../decorators/bypass-onboarding.decorator' import { AuthenticatedUserContext } from '../../auth.types' import { toSHA256 } from '../../../common/to-sha256' +import { EnvSchema } from '../../../common/env/env.schema' const X_E2E_USER_EMAIL = 'x-e2e-user-email' const X_KEYSHADE_TOKEN = 'x-keyshade-token' @@ -41,17 +42,23 @@ export class AuthGuard implements CanActivate { let user: AuthenticatedUserContext | null = null const request = context.switchToHttp().getRequest() const authType = this.getAuthType(request) + const parsedEnv = EnvSchema.safeParse(process.env) + let nodeEnv - //@ts-expect-error process.env.NODE_ENV parses to 'dev' - if (process.env.NODE_ENV !== 'e2e' && authType === 'NONE') { + if (!parsedEnv.success) { + nodeEnv = 'dev' // Default to a valid value or handle appropriately + } else { + nodeEnv = parsedEnv.data.NODE_ENV + } + + if (nodeEnv !== 'e2e' && authType === 'NONE') { throw new ForbiddenException('No authentication provided') } // In case the environment is e2e, we want to authenticate the user using the email // else we want to authenticate the user using the JWT token. - // @ts-expect-error process.env.NODE_ENV parses to 'dev' - if (authType !== 'API_KEY' && process.env.NODE_ENV === 'e2e') { + if (authType !== 'API_KEY' && nodeEnv === 'e2e') { const email = request.headers[X_E2E_USER_EMAIL] if (!email) { throw new ForbiddenException() diff --git a/apps/api/src/common/env/env.schema.ts b/apps/api/src/common/env/env.schema.ts index d5a3e712..4f92a9c9 100644 --- a/apps/api/src/common/env/env.schema.ts +++ b/apps/api/src/common/env/env.schema.ts @@ -28,7 +28,7 @@ const e2eEnvSchema = z.object({ const generalSchema = z.object({ NODE_ENV: z.literal('dev'), DATABASE_URL: z.string(), - ADMIN_EMAIL: z.string(), + ADMIN_EMAIL: z.string().email(), REDIS_URL: z.string(), REDIS_PASSWORD: z.string().optional(), @@ -56,10 +56,13 @@ const generalSchema = z.object({ SMTP_HOST: z.string(), SMTP_PORT: z.string(), - SMTP_EMAIL_ADDRESS: z.string(), + SMTP_EMAIL_ADDRESS: z.string().email(), SMTP_PASSWORD: z.string(), - // TODO: add regex check for FORM_EMAIL value as represented in .env.example (your-name ) - FROM_EMAIL: z.string(), + FROM_EMAIL: z + .string() + .regex( + /^[a-zA-Z0-9._%+-]+(?: [a-zA-Z0-9._%+-]+)* <[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}>$/ + ), JWT_SECRET: z.string(), @@ -75,7 +78,7 @@ const generalSchema = z.object({ MINIO_BUCKET_NAME: z.string().optional(), MINIO_USE_SSL: z.string().optional(), - FEEDBACK_FORWARD_EMAIL: z.string() + FEEDBACK_FORWARD_EMAIL: z.string().email() }) export type EnvSchemaType = z.infer diff --git a/apps/api/src/environment/environment.e2e.spec.ts b/apps/api/src/environment/environment.e2e.spec.ts index 1939927a..dea45961 100644 --- a/apps/api/src/environment/environment.e2e.spec.ts +++ b/apps/api/src/environment/environment.e2e.spec.ts @@ -8,7 +8,6 @@ import { NestFastifyApplication } from '@nestjs/platform-fastify' import { PrismaService } from '../prisma/prisma.service' -import cleanUp from '../common/cleanup' import { Environment, EventSeverity, @@ -20,20 +19,21 @@ import { User, Workspace } from '@prisma/client' -import { v4 } from 'uuid' import fetchEvents from '../common/fetch-events' import { ProjectModule } from '../project/project.module' -import { WorkspaceService } from '../workspace/service/workspace.service' import { ProjectService } from '../project/service/project.service' import { EventModule } from '../event/event.module' -import { WorkspaceModule } from '../workspace/workspace.module' import { EventService } from '../event/service/event.service' +import { EnvironmentService } from './service/environment.service' +import { UserModule } from '../user/user.module' +import { UserService } from '../user/service/user.service' describe('Environment Controller Tests', () => { let app: NestFastifyApplication let prisma: PrismaService let projectService: ProjectService - let workspaceService: WorkspaceService + let environmentService: EnvironmentService + let userService: UserService let eventService: EventService let user1: User, user2: User @@ -46,9 +46,9 @@ describe('Environment Controller Tests', () => { imports: [ AppModule, EventModule, - WorkspaceModule, ProjectModule, - EnvironmentModule + EnvironmentModule, + UserModule ] }) .overrideProvider(MAIL_SERVICE) @@ -60,53 +60,77 @@ describe('Environment Controller Tests', () => { ) prisma = moduleRef.get(PrismaService) projectService = moduleRef.get(ProjectService) - workspaceService = moduleRef.get(WorkspaceService) eventService = moduleRef.get(EventService) + environmentService = moduleRef.get(EnvironmentService) + userService = moduleRef.get(UserService) await app.init() await app.getHttpAdapter().getInstance().ready() + }) - await cleanUp(prisma) - - const user1Id = v4() - const user2Id = v4() + beforeEach(async () => { + const createUser1 = await userService.createUser({ + email: 'johndoe@keyshade.xyz', + name: 'John Doe', + isOnboardingFinished: true + }) - user1 = await prisma.user.create({ - data: { - id: user1Id, - email: 'johndoe@keyshade.xyz', - name: 'John Doe', - isOnboardingFinished: true - } + const createUser2 = await userService.createUser({ + email: 'janedoe@keyshade.xyz', + name: 'Jane Doe', + isOnboardingFinished: true }) - user2 = await prisma.user.create({ - data: { - id: user2Id, - email: 'janedoe@keyshade.xyz', - name: 'Jane Doe', - isOnboardingFinished: true + workspace1 = createUser1.defaultWorkspace + + delete createUser1.defaultWorkspace + delete createUser2.defaultWorkspace + + user1 = createUser1 + user2 = createUser2 + + project1 = (await projectService.createProject(user1, workspace1.id, { + name: 'Project 1', + description: 'Project 1 description', + storePrivateKey: true, + environments: [ + { + name: 'Environment 1', + description: 'Default environment', + isDefault: true + }, + { + name: 'Environment 2', + description: 'Environment 2 description' + } + ], + accessLevel: ProjectAccessLevel.PRIVATE + })) as Project + + environment1 = await prisma.environment.findUnique({ + where: { + projectId_name: { + projectId: project1.id, + name: 'Environment 1' + } } }) - workspace1 = await workspaceService.createWorkspace(user1, { - name: 'Workspace 1', - description: 'Workspace 1 description', - approvalEnabled: false + environment2 = await prisma.environment.findUnique({ + where: { + projectId_name: { + projectId: project1.id, + name: 'Environment 2' + } + } }) + }) - project1 = (await projectService.createProject( - user1, - workspace1.id, - { - name: 'Project 1', - description: 'Project 1 description', - storePrivateKey: true, - environments: [], - accessLevel: ProjectAccessLevel.PRIVATE - }, - '' - )) as Project + afterEach(async () => { + await prisma.$transaction([ + prisma.user.deleteMany(), + prisma.workspace.deleteMany() + ]) }) it('should be defined', () => { @@ -119,8 +143,8 @@ describe('Environment Controller Tests', () => { method: 'POST', url: `/environment/${project1.id}`, payload: { - name: 'Environment 1', - description: 'Environment 1 description', + name: 'Environment 3', + description: 'Environment 3 description', isDefault: true }, headers: { @@ -129,20 +153,17 @@ describe('Environment Controller Tests', () => { }) expect(response.statusCode).toBe(201) - expect(response.json()).toEqual({ - id: expect.any(String), - name: 'Environment 1', - description: 'Environment 1 description', - isDefault: true, - projectId: project1.id, - lastUpdatedById: user1.id, - createdAt: expect.any(String), - updatedAt: expect.any(String), - pendingCreation: false, - project: expect.any(Object) + expect(response.json().name).toBe('Environment 3') + expect(response.json().description).toBe('Environment 3 description') + expect(response.json().isDefault).toBe(true) + + const environmentFromDb = await prisma.environment.findUnique({ + where: { + id: response.json().id + } }) - environment1 = response.json() + expect(environmentFromDb).toBeDefined() }) it('should ensure there is only one default environment per project', async () => { @@ -152,7 +173,6 @@ describe('Environment Controller Tests', () => { } }) - expect(environments.length).toBe(2) expect(environments.filter((e) => e.isDefault).length).toBe(1) }) @@ -219,8 +239,8 @@ describe('Environment Controller Tests', () => { method: 'POST', url: `/environment/${project1.id}`, payload: { - name: 'Environment 2', - description: 'Environment 2 description', + name: 'Environment 3', + description: 'Environment 3 description', isDefault: false }, headers: { @@ -229,12 +249,10 @@ describe('Environment Controller Tests', () => { }) expect(response.statusCode).toBe(201) - expect(response.json().name).toBe('Environment 2') - expect(response.json().description).toBe('Environment 2 description') + expect(response.json().name).toBe('Environment 3') + expect(response.json().description).toBe('Environment 3 description') expect(response.json().isDefault).toBe(false) - environment2 = response.json() - const environments = await prisma.environment.findMany({ where: { projectId: project1.id @@ -246,6 +264,15 @@ describe('Environment Controller Tests', () => { }) it('should have created a ENVIRONMENT_ADDED event', async () => { + // Create an environment + await environmentService.createEnvironment( + user1, + { + name: 'Environment 4' + }, + project1.id + ) + const response = await fetchEvents( eventService, user1, @@ -351,6 +378,15 @@ describe('Environment Controller Tests', () => { }) it('should create a ENVIRONMENT_UPDATED event', async () => { + // Update an environment + await environmentService.updateEnvironment( + user1, + { + name: 'Environment 1 Updated' + }, + environment1.id + ) + const response = await fetchEvents( eventService, user1, @@ -395,7 +431,7 @@ describe('Environment Controller Tests', () => { } }) - expect(environments.length).toBe(3) + expect(environments.length).toBe(2) expect(environments.filter((e) => e.isDefault).length).toBe(1) environment2 = response.json() @@ -412,11 +448,9 @@ describe('Environment Controller Tests', () => { }) expect(response.statusCode).toBe(200) - expect(response.json().name).toBe('Environment 1 Updated') - expect(response.json().description).toBe( - 'Environment 1 description updated' - ) - expect(response.json().isDefault).toBe(false) + expect(response.json().name).toBe('Environment 1') + expect(response.json().description).toBe('Default environment') + expect(response.json().isDefault).toBe(true) }) it('should not be able to fetch an environment that does not exist', async () => { @@ -490,7 +524,7 @@ describe('Environment Controller Tests', () => { it('should be able to delete an environment', async () => { const response = await app.inject({ method: 'DELETE', - url: `/environment/${environment1.id}`, + url: `/environment/${environment2.id}`, headers: { 'x-e2e-user-email': user1.email } @@ -500,6 +534,9 @@ describe('Environment Controller Tests', () => { }) it('should have created a ENVIRONMENT_DELETED event', async () => { + // Delete an environment + await environmentService.deleteEnvironment(user1, environment2.id) + const response = await fetchEvents( eventService, user1, @@ -548,7 +585,7 @@ describe('Environment Controller Tests', () => { it('should not be able to delete the default environment of a project', async () => { const response = await app.inject({ method: 'DELETE', - url: `/environment/${environment2.id}`, + url: `/environment/${environment1.id}`, headers: { 'x-e2e-user-email': user1.email } @@ -564,13 +601,13 @@ describe('Environment Controller Tests', () => { await prisma.environment.deleteMany({ where: { projectId: project1.id, - name: 'Default' + isDefault: false } }) const response = await app.inject({ method: 'PUT', - url: `/environment/${environment2.id}`, + url: `/environment/${environment1.id}`, payload: { isDefault: false }, @@ -584,8 +621,4 @@ describe('Environment Controller Tests', () => { 'Cannot make the last environment non-default' ) }) - - afterAll(async () => { - await cleanUp(prisma) - }) }) diff --git a/apps/api/src/feedback/feedback.e2e.spec.ts b/apps/api/src/feedback/feedback.e2e.spec.ts index a5cfecff..cd3d0250 100644 --- a/apps/api/src/feedback/feedback.e2e.spec.ts +++ b/apps/api/src/feedback/feedback.e2e.spec.ts @@ -11,7 +11,6 @@ import { FeedbackModule } from './feedback.module' import { MailModule } from '../mail/mail.module' import { PrismaService } from '../prisma/prisma.service' import { User } from '@prisma/client' -import cleanUp from '../common/cleanup' describe('Feedback Controller (E2E)', () => { let app: NestFastifyApplication @@ -38,8 +37,6 @@ describe('Feedback Controller (E2E)', () => { await app.init() await app.getHttpAdapter().getInstance().ready() - - await cleanUp(prisma) }) beforeEach(async () => { @@ -55,11 +52,7 @@ describe('Feedback Controller (E2E)', () => { }) afterEach(async () => { - if (user) { - await prisma.user.delete({ - where: { id: user.id } - }) - } + await prisma.user.deleteMany() }) afterAll(async () => { diff --git a/apps/api/src/integration/integration.e2e.spec.ts b/apps/api/src/integration/integration.e2e.spec.ts index 8ca4b91a..1e5b4dc9 100644 --- a/apps/api/src/integration/integration.e2e.spec.ts +++ b/apps/api/src/integration/integration.e2e.spec.ts @@ -24,7 +24,6 @@ import { ProjectService } from '../project/service/project.service' import { ProjectModule } from '../project/project.module' import { MAIL_SERVICE } from '../mail/services/interface.service' import { MockMailService } from '../mail/services/mock.service' -import cleanUp from '../common/cleanup' import { EnvironmentModule } from '../environment/environment.module' import { EnvironmentService } from '../environment/service/environment.service' @@ -69,8 +68,6 @@ describe('Integration Controller Tests', () => { await app.init() await app.getHttpAdapter().getInstance().ready() - - await cleanUp(prisma) }) beforeEach(async () => { @@ -149,7 +146,6 @@ describe('Integration Controller Tests', () => { }) afterAll(async () => { - await cleanUp(prisma) await prisma.$disconnect() await app.close() }) diff --git a/apps/api/src/prisma/schema.prisma b/apps/api/src/prisma/schema.prisma index 571985aa..c67509b5 100644 --- a/apps/api/src/prisma/schema.prisma +++ b/apps/api/src/prisma/schema.prisma @@ -286,6 +286,9 @@ model Environment { project Project @relation(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) projectId String + + @@unique([projectId, name]) + @@index([name]) } model Project { diff --git a/apps/api/src/project/project.e2e.spec.ts b/apps/api/src/project/project.e2e.spec.ts index 00c2092d..7a98d0e2 100644 --- a/apps/api/src/project/project.e2e.spec.ts +++ b/apps/api/src/project/project.e2e.spec.ts @@ -8,7 +8,6 @@ import { AppModule } from '../app/app.module' import { ProjectModule } from './project.module' import { MAIL_SERVICE } from '../mail/services/interface.service' import { MockMailService } from '../mail/services/mock.service' -import cleanUp from '../common/cleanup' import { Authority, Environment, @@ -89,8 +88,6 @@ describe('Project Controller Tests', () => { await app.init() await app.getHttpAdapter().getInstance().ready() - - await cleanUp(prisma) }) beforeEach(async () => { diff --git a/apps/api/src/secret/secret.e2e.spec.ts b/apps/api/src/secret/secret.e2e.spec.ts index 5cbf49aa..4232eaae 100644 --- a/apps/api/src/secret/secret.e2e.spec.ts +++ b/apps/api/src/secret/secret.e2e.spec.ts @@ -27,15 +27,15 @@ import { EnvironmentModule } from '../environment/environment.module' import { SecretModule } from './secret.module' import { MAIL_SERVICE } from '../mail/services/interface.service' import { MockMailService } from '../mail/services/mock.service' -import cleanUp from '../common/cleanup' import { EnvironmentService } from '../environment/service/environment.service' -import { v4 } from 'uuid' import fetchEvents from '../common/fetch-events' import { SecretService } from './service/secret.service' import { EventService } from '../event/service/event.service' import { REDIS_CLIENT } from '../provider/redis.provider' import { RedisClientType } from 'redis' import { mockDeep } from 'jest-mock-extended' +import { UserService } from '../user/service/user.service' +import { UserModule } from '../user/user.module' describe('Secret Controller Tests', () => { let app: NestFastifyApplication @@ -45,13 +45,14 @@ describe('Secret Controller Tests', () => { let environmentService: EnvironmentService let secretService: SecretService let eventService: EventService + let userService: UserService let user1: User, user2: User let workspace1: Workspace, workspace2: Workspace let project1: Project, project2: Project, workspace2Project: Project - let environment1: Environment, - environment2: Environment, - workspace2Environment: Environment + let environment1: Environment + let environment2: Environment + let workspace2Environment: Environment let secret1: Secret beforeAll(async () => { @@ -62,7 +63,8 @@ describe('Secret Controller Tests', () => { WorkspaceModule, ProjectModule, EnvironmentModule, - SecretModule + SecretModule, + UserModule ] }) .overrideProvider(MAIL_SERVICE) @@ -80,44 +82,33 @@ describe('Secret Controller Tests', () => { environmentService = moduleRef.get(EnvironmentService) secretService = moduleRef.get(SecretService) eventService = moduleRef.get(EventService) + userService = moduleRef.get(UserService) await app.init() await app.getHttpAdapter().getInstance().ready() + }) - await cleanUp(prisma) - - const user1Id = v4() - const user2Id = v4() - - user1 = await prisma.user.create({ - data: { - id: user1Id, - email: 'johndoe@keyshade.xyz', - name: 'John Doe', - isOnboardingFinished: true - } + beforeEach(async () => { + const createUser1 = await userService.createUser({ + email: 'johndoe@keyshade.xyz', + name: 'John Doe', + isOnboardingFinished: true }) - user2 = await prisma.user.create({ - data: { - id: user2Id, - email: 'janedoe@keyshade.xyz', - name: 'Jane Doe', - isOnboardingFinished: true - } + const createUser2 = await userService.createUser({ + email: 'janedoe@keyshade.xyz', + name: 'Jane Doe', + isOnboardingFinished: true }) - workspace1 = await workspaceService.createWorkspace(user1, { - name: 'Workspace 1', - description: 'Workspace 1 description', - approvalEnabled: false - }) + workspace1 = createUser1.defaultWorkspace + workspace2 = createUser2.defaultWorkspace - workspace2 = await workspaceService.createWorkspace(user2, { - name: 'Workspace 2', - description: 'Workspace 2 description', - approvalEnabled: false - }) + delete createUser1.defaultWorkspace + delete createUser2.defaultWorkspace + + user1 = createUser1 + user2 = createUser2 project1 = (await projectService.createProject(user1, workspace1.id, { name: 'Project 1', @@ -190,6 +181,25 @@ describe('Secret Controller Tests', () => { name: 'Environment 2' } }) + + secret1 = (await secretService.createSecret( + user1, + { + environmentId: environment2.id, + name: 'Secret 1', + value: 'Secret 1 value', + rotateAfter: '24', + note: 'Secret 1 note' + }, + project1.id + )) as Secret + }) + + afterEach(async () => { + await prisma.$transaction([ + prisma.user.deleteMany(), + prisma.workspace.deleteMany() + ]) }) it('should be defined', async () => { @@ -206,9 +216,9 @@ describe('Secret Controller Tests', () => { url: `/secret/${project1.id}`, payload: { environmentId: environment2.id, - name: 'Secret 1', - note: 'Secret 1 note', - value: 'Secret 1 value', + name: 'Secret 2', + note: 'Secret 2 note', + value: 'Secret 2 value', rotateAfter: '24' }, headers: { @@ -221,12 +231,10 @@ describe('Secret Controller Tests', () => { const body = response.json() expect(body).toBeDefined() - expect(body.name).toBe('Secret 1') - expect(body.note).toBe('Secret 1 note') + expect(body.name).toBe('Secret 2') + expect(body.note).toBe('Secret 2 note') expect(body.environmentId).toBe(environment2.id) expect(body.projectId).toBe(project1.id) - - secret1 = body }) it('should have created a secret version', async () => { @@ -446,8 +454,6 @@ describe('Secret Controller Tests', () => { }) expect(secretVersion.length).toBe(1) - - secret1 = response.json() }) it('should create a new version if the value is updated', async () => { @@ -474,6 +480,11 @@ describe('Secret Controller Tests', () => { }) it('should have created a SECRET_UPDATED event', async () => { + // Update a secret + await secretService.updateSecret(user1, secret1.id, { + name: 'Updated Secret 1' + }) + const response = await fetchEvents( eventService, user1, @@ -541,7 +552,7 @@ describe('Secret Controller Tests', () => { it('should not be able to move the secret to the same environment', async () => { const response = await app.inject({ method: 'PUT', - url: `/secret/${secret1.id}/environment/${environment1.id}`, + url: `/secret/${secret1.id}/environment/${environment2.id}`, headers: { 'x-e2e-user-email': user1.email } @@ -549,7 +560,7 @@ describe('Secret Controller Tests', () => { expect(response.statusCode).toBe(400) expect(response.json().message).toEqual( - `Can not update the environment of the secret to the same environment: ${environment1.id} in project ${project1.id}` + `Can not update the environment of the secret to the same environment: ${environment2.id} in project ${project1.id}` ) }) @@ -569,17 +580,19 @@ describe('Secret Controller Tests', () => { }) it('should not be able to move a secret of the same name to an environment', async () => { - const newSecret = await prisma.secret.create({ - data: { - projectId: project1.id, - environmentId: environment2.id, - name: 'Updated Secret 1' - } - }) + const newSecret = (await secretService.createSecret( + user1, + { + environmentId: environment1.id, + name: 'Secret 1', + value: 'Some value' + }, + project1.id + )) as Secret const response = await app.inject({ method: 'PUT', - url: `/secret/${newSecret.id}/environment/${environment1.id}`, + url: `/secret/${newSecret.id}/environment/${environment2.id}`, headers: { 'x-e2e-user-email': user1.email } @@ -587,7 +600,7 @@ describe('Secret Controller Tests', () => { expect(response.statusCode).toBe(409) expect(response.json().message).toEqual( - `Secret already exists: Updated Secret 1 in environment ${environment1.id} in project ${project1.id}` + `Secret already exists: Secret 1 in environment ${environment2.id} in project ${project1.id}` ) }) @@ -654,7 +667,7 @@ describe('Secret Controller Tests', () => { } }) - expect(versions.length).toBe(4) + expect(versions.length).toBe(3) const response = await app.inject({ method: 'PUT', @@ -665,7 +678,7 @@ describe('Secret Controller Tests', () => { }) expect(response.statusCode).toBe(200) - expect(response.json().count).toEqual(3) + expect(response.json().count).toEqual(2) versions = await prisma.secretVersion.findMany({ where: { @@ -813,7 +826,7 @@ describe('Secret Controller Tests', () => { }) expect(response.statusCode).toBe(200) - expect(response.json().length).toBe(3) + expect(response.json().length).toBe(1) }) it('should be able to fetch all secrets decrypted', async () => { @@ -826,11 +839,11 @@ describe('Secret Controller Tests', () => { }) expect(response.statusCode).toBe(200) - expect(response.json().length).toBe(3) + expect(response.json().length).toBe(1) const secret = response.json()[0] - expect(secret.versions[0].value).toEqual('Secret 2 value') + expect(secret.versions[0].value).toEqual('Secret 1 value') }) it('should not be able to fetch all secrets decrypted if the project does not store the private key', async () => { @@ -955,6 +968,9 @@ describe('Secret Controller Tests', () => { }) it('should have created a SECRET_DELETED event', async () => { + // Delete a secret + await secretService.deleteSecret(user1, secret1.id) + const response = await fetchEvents( eventService, user1, @@ -971,8 +987,4 @@ describe('Secret Controller Tests', () => { expect(event.workspaceId).toBe(workspace1.id) expect(event.itemId).toBe(secret1.id) }) - - afterAll(async () => { - await app.close() - }) }) diff --git a/apps/api/src/user/service/user.service.ts b/apps/api/src/user/service/user.service.ts index c026a437..ac25b6bb 100644 --- a/apps/api/src/user/service/user.service.ts +++ b/apps/api/src/user/service/user.service.ts @@ -15,6 +15,7 @@ import { } from '../../mail/services/interface.service' import createUser from '../../common/create-user' import generateOtp from '../../common/generate-otp' +import { EnvSchema } from '../../common/env/env.schema' @Injectable() export class UserService { @@ -294,9 +295,16 @@ export class UserService { } private async checkIfAdminExistsOrCreate() { - // @ts-expect-error process.env.NODE_ENV parses to 'dev' - // FIXME - if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'e2e') { + const parsedEnv = EnvSchema.safeParse(process.env) + let nodeEnv + + if (!parsedEnv.success) { + nodeEnv = 'dev' // Default to a valid value or handle appropriately + } else { + nodeEnv = parsedEnv.data.NODE_ENV + } + + if (nodeEnv === 'test' || nodeEnv === 'e2e') { return } diff --git a/apps/api/src/user/user.e2e.spec.ts b/apps/api/src/user/user.e2e.spec.ts index 1b872de1..2550153c 100644 --- a/apps/api/src/user/user.e2e.spec.ts +++ b/apps/api/src/user/user.e2e.spec.ts @@ -10,7 +10,6 @@ import { AuthProvider, User } from '@prisma/client' import { MAIL_SERVICE } from '../mail/services/interface.service' import { MockMailService } from '../mail/services/mock.service' import { UserService } from './service/user.service' -import cleanUp from '../common/cleanup' describe('User Controller Tests', () => { let app: NestFastifyApplication @@ -35,8 +34,6 @@ describe('User Controller Tests', () => { await app.init() await app.getHttpAdapter().getInstance().ready() - - await cleanUp(prisma) }) beforeEach(async () => { @@ -575,7 +572,6 @@ describe('User Controller Tests', () => { // }) afterAll(async () => { - await cleanUp(prisma) await prisma.$disconnect() await app.close() }) diff --git a/apps/api/src/variable/variable.e2e.spec.ts b/apps/api/src/variable/variable.e2e.spec.ts index aadead4b..1257fdae 100644 --- a/apps/api/src/variable/variable.e2e.spec.ts +++ b/apps/api/src/variable/variable.e2e.spec.ts @@ -27,15 +27,15 @@ import { EnvironmentModule } from '../environment/environment.module' import { VariableModule } from './variable.module' import { MAIL_SERVICE } from '../mail/services/interface.service' import { MockMailService } from '../mail/services/mock.service' -import cleanUp from '../common/cleanup' import { EnvironmentService } from '../environment/service/environment.service' -import { v4 } from 'uuid' import fetchEvents from '../common/fetch-events' import { VariableService } from './service/variable.service' import { EventService } from '../event/service/event.service' import { REDIS_CLIENT } from '../provider/redis.provider' import { mockDeep } from 'jest-mock-extended' import { RedisClientType } from 'redis' +import { UserService } from '../user/service/user.service' +import { UserModule } from '../user/user.module' describe('Variable Controller Tests', () => { let app: NestFastifyApplication @@ -45,13 +45,14 @@ describe('Variable Controller Tests', () => { let environmentService: EnvironmentService let variableService: VariableService let eventService: EventService + let userService: UserService let user1: User, user2: User let workspace1: Workspace, workspace2: Workspace let project1: Project, project2: Project, workspace2Project: Project - let environment1: Environment, - environment2: Environment, - workspace2Environment: Environment + let environment1: Environment + let environment2: Environment + let workspace2Environment: Environment let variable1: Variable beforeAll(async () => { @@ -62,7 +63,8 @@ describe('Variable Controller Tests', () => { WorkspaceModule, ProjectModule, EnvironmentModule, - VariableModule + VariableModule, + UserModule ] }) .overrideProvider(MAIL_SERVICE) @@ -80,44 +82,33 @@ describe('Variable Controller Tests', () => { environmentService = moduleRef.get(EnvironmentService) variableService = moduleRef.get(VariableService) eventService = moduleRef.get(EventService) + userService = moduleRef.get(UserService) await app.init() await app.getHttpAdapter().getInstance().ready() + }) - await cleanUp(prisma) - - const user1Id = v4() - const user2Id = v4() - - user1 = await prisma.user.create({ - data: { - id: user1Id, - email: 'johndoe@keyshade.xyz', - name: 'John Doe', - isOnboardingFinished: true - } + beforeEach(async () => { + const createUser1 = await userService.createUser({ + email: 'johndoe@keyshade.xyz', + name: 'John Doe', + isOnboardingFinished: true }) - user2 = await prisma.user.create({ - data: { - id: user2Id, - email: 'janedoe@keyshade.xyz', - name: 'Jane Doe', - isOnboardingFinished: true - } + const createUser2 = await userService.createUser({ + email: 'janedoe@keyshade.xyz', + name: 'Jane Doe', + isOnboardingFinished: true }) - workspace1 = await workspaceService.createWorkspace(user1, { - name: 'Workspace 1', - description: 'Workspace 1 description', - approvalEnabled: false - }) + workspace1 = createUser1.defaultWorkspace + workspace2 = createUser2.defaultWorkspace - workspace2 = await workspaceService.createWorkspace(user2, { - name: 'Workspace 2', - description: 'Workspace 2 description', - approvalEnabled: false - }) + delete createUser1.defaultWorkspace + delete createUser2.defaultWorkspace + + user1 = createUser1 + user2 = createUser2 project1 = (await projectService.createProject(user1, workspace1.id, { name: 'Project 1', @@ -190,6 +181,23 @@ describe('Variable Controller Tests', () => { name: 'Environment 2' } }) + + variable1 = (await variableService.createVariable( + user1, + { + name: 'Variable 1', + value: 'Variable 1 value', + environmentId: environment2.id + }, + project1.id + )) as Variable + }) + + afterEach(async () => { + await prisma.$transaction([ + prisma.user.deleteMany(), + prisma.workspace.deleteMany() + ]) }) it('should be defined', async () => { @@ -206,9 +214,9 @@ describe('Variable Controller Tests', () => { url: `/variable/${project1.id}`, payload: { environmentId: environment2.id, - name: 'Variable 1', - value: 'Variable 1 value', - note: 'Variable 1 note', + name: 'Variable 3', + value: 'Variable 3 value', + note: 'Variable 3 note', rotateAfter: '24' }, headers: { @@ -221,12 +229,18 @@ describe('Variable Controller Tests', () => { const body = response.json() expect(body).toBeDefined() - expect(body.name).toBe('Variable 1') - expect(body.note).toBe('Variable 1 note') + expect(body.name).toBe('Variable 3') + expect(body.note).toBe('Variable 3 note') expect(body.environmentId).toBe(environment2.id) expect(body.projectId).toBe(project1.id) - variable1 = body + const variable = await prisma.variable.findUnique({ + where: { + id: body.id + } + }) + + expect(variable).toBeDefined() }) it('should have created a variable version', async () => { @@ -448,8 +462,6 @@ describe('Variable Controller Tests', () => { }) expect(variableVersion.length).toBe(1) - - variable1 = response.json() }) it('should create a new version if the value is updated', async () => { @@ -476,6 +488,11 @@ describe('Variable Controller Tests', () => { }) it('should have created a VARIABLE_UPDATED event', async () => { + // Update a variable + await variableService.updateVariable(user1, variable1.id, { + value: 'Updated Variable 1 value' + }) + const response = await fetchEvents( eventService, user1, @@ -543,7 +560,7 @@ describe('Variable Controller Tests', () => { it('should not be able to move the variable to the same environment', async () => { const response = await app.inject({ method: 'PUT', - url: `/variable/${variable1.id}/environment/${environment1.id}`, + url: `/variable/${variable1.id}/environment/${environment2.id}`, headers: { 'x-e2e-user-email': user1.email } @@ -551,7 +568,7 @@ describe('Variable Controller Tests', () => { expect(response.statusCode).toBe(400) expect(response.json().message).toEqual( - `Can not update the environment of the variable to the same environment: ${environment1.id}` + `Can not update the environment of the variable to the same environment: ${environment2.id}` ) }) @@ -571,17 +588,19 @@ describe('Variable Controller Tests', () => { }) it('should not be able to move a variable of the same name to an environment', async () => { - const newVariable = await prisma.variable.create({ - data: { - projectId: project1.id, - environmentId: environment2.id, - name: 'Updated Variable 1' - } - }) + const newVariable = (await variableService.createVariable( + user1, + { + environmentId: environment1.id, + name: 'Variable 1', + value: 'Variable 1 value' + }, + project1.id + )) as Variable const response = await app.inject({ method: 'PUT', - url: `/variable/${newVariable.id}/environment/${environment1.id}`, + url: `/variable/${newVariable.id}/environment/${environment2.id}`, headers: { 'x-e2e-user-email': user1.email } @@ -589,7 +608,7 @@ describe('Variable Controller Tests', () => { expect(response.statusCode).toBe(409) expect(response.json().message).toEqual( - `Variable already exists: Updated Variable 1 in environment ${environment1.id} in project ${project1.id}` + `Variable already exists: Variable 1 in environment ${environment2.id} in project ${project1.id}` ) }) @@ -656,7 +675,7 @@ describe('Variable Controller Tests', () => { } }) - expect(versions.length).toBe(4) + expect(versions.length).toBe(3) const response = await app.inject({ method: 'PUT', @@ -667,7 +686,7 @@ describe('Variable Controller Tests', () => { }) expect(response.statusCode).toBe(200) - expect(response.json().count).toEqual(3) + expect(response.json().count).toEqual(2) versions = await prisma.variableVersion.findMany({ where: { @@ -754,7 +773,7 @@ describe('Variable Controller Tests', () => { }) expect(response.statusCode).toBe(200) - expect(response.json().length).toBe(3) + expect(response.json().length).toBe(1) }) it('should not be able to fetch all variables if the user has no access to the project', async () => { @@ -830,6 +849,9 @@ describe('Variable Controller Tests', () => { }) it('should have created a VARIABLE_DELETED event', async () => { + // Delete a variable + await variableService.deleteVariable(user1, variable1.id) + const response = await fetchEvents( eventService, user1, @@ -846,8 +868,4 @@ describe('Variable Controller Tests', () => { expect(event.workspaceId).toBe(workspace1.id) expect(event.itemId).toBeDefined() }) - - afterAll(async () => { - await app.close() - }) }) diff --git a/apps/api/src/workspace-role/workspace-role.e2e.spec.ts b/apps/api/src/workspace-role/workspace-role.e2e.spec.ts index 8932ac77..95eefeca 100644 --- a/apps/api/src/workspace-role/workspace-role.e2e.spec.ts +++ b/apps/api/src/workspace-role/workspace-role.e2e.spec.ts @@ -20,15 +20,19 @@ import { MAIL_SERVICE } from '../mail/services/interface.service' import { MockMailService } from '../mail/services/mock.service' import { Test } from '@nestjs/testing' import { v4 } from 'uuid' -import cleanUp from '../common/cleanup' import fetchEvents from '../common/fetch-events' import { EventService } from '../event/service/event.service' import { EventModule } from '../event/event.module' +import { WorkspaceRoleService } from './service/workspace-role.service' +import { UserService } from '../user/service/user.service' +import { UserModule } from '../user/user.module' describe('Workspace Role Controller Tests', () => { let app: NestFastifyApplication let prisma: PrismaService let eventService: EventService + let workspaceRoleService: WorkspaceRoleService + let userService: UserService let alice: User let bob: User @@ -41,7 +45,7 @@ describe('Workspace Role Controller Tests', () => { beforeAll(async () => { const moduleRef = await Test.createTestingModule({ - imports: [AppModule, WorkspaceRoleModule, EventModule] + imports: [AppModule, WorkspaceRoleModule, EventModule, UserModule] }) .overrideProvider(MAIL_SERVICE) .useClass(MockMailService) @@ -51,168 +55,81 @@ describe('Workspace Role Controller Tests', () => { ) prisma = moduleRef.get(PrismaService) eventService = moduleRef.get(EventService) + workspaceRoleService = moduleRef.get(WorkspaceRoleService) + userService = moduleRef.get(UserService) await app.init() await app.getHttpAdapter().getInstance().ready() + }) - await cleanUp(prisma) - - const aliceId = v4() - const bobId = v4() - const charlieId = v4() - const workspaceAliceId = v4() - const workspaceBobId = v4() - + beforeEach(async () => { // Create the users - const createAlice = prisma.user.create({ - data: { - id: aliceId, - email: 'alice@keyshade.xyz', - name: 'Alice', - isActive: true, - isAdmin: false, - isOnboardingFinished: true - } + const createAlice = await userService.createUser({ + email: 'alice@keyshade.xyz', + name: 'Alice', + isActive: true, + isAdmin: false, + isOnboardingFinished: true }) - const createBob = prisma.user.create({ - data: { - id: bobId, - email: 'bob@keyshade.xyz', - name: 'Bob', - isActive: true, - isAdmin: false, - isOnboardingFinished: true - } + const createBob = await userService.createUser({ + email: 'bob@keyshade.xyz', + name: 'Bob', + isActive: true, + isAdmin: false, + isOnboardingFinished: true }) - const createCharlie = prisma.user.create({ - data: { - id: charlieId, - email: 'charlie@keyshade.xyz', - name: 'Charlie', - isActive: true, - isAdmin: false, - isOnboardingFinished: true - } + const createCharlie = await userService.createUser({ + email: 'charlie@keyshade.xyz', + name: 'Charlie', + isActive: true, + isAdmin: false, + isOnboardingFinished: true }) - // Create the workspaces - const createWorkspaceAlice = prisma.workspace.create({ - data: { - id: workspaceAliceId, - name: 'Test Workspace for Alice', - description: 'Test Workspace Description', - isFreeTier: true, - ownerId: workspaceBobId, - roles: { - createMany: { - data: [ - { - name: 'Admin', - authorities: [Authority.WORKSPACE_ADMIN], - hasAdminAuthority: true, - colorCode: '#FF0000' - }, - { - name: 'Viewer', - authorities: [Authority.READ_WORKSPACE_ROLE] - } - ] - } - } - } - }) + workspaceAlice = createAlice.defaultWorkspace + workspaceBob = createBob.defaultWorkspace - const createWorkspaceBob = prisma.workspace.create({ - data: { - id: workspaceBobId, - name: 'Test Workspace for Bob', - description: 'Test Workspace Description', - isFreeTier: true, - ownerId: bobId, - roles: { - createMany: { - data: [ - { - name: 'Admin', - authorities: [Authority.WORKSPACE_ADMIN], - hasAdminAuthority: true, - colorCode: '#FF0000' - } - ] - } - } + delete createAlice.defaultWorkspace + delete createBob.defaultWorkspace + delete createCharlie.defaultWorkspace + + alice = createAlice + bob = createBob + charlie = createCharlie + + adminRole1 = await prisma.workspaceRole.findFirst({ + where: { + workspaceId: workspaceAlice.id, + hasAdminAuthority: true } }) - // Add the owners to the workspaces - const assignOwnershipForAlice = prisma.workspaceMember.create({ - data: { - workspace: { - connect: { - id: workspaceAliceId - } - }, - user: { - connect: { - id: aliceId - } - }, - invitationAccepted: true, - roles: { - create: { - role: { - connect: { - workspaceId_name: { - workspaceId: workspaceAliceId, - name: 'Admin' - } - } - } - } - } + adminRole2 = await prisma.workspaceRole.findFirst({ + where: { + workspaceId: workspaceBob.id, + hasAdminAuthority: true } }) - const assignOwnershipForBob = prisma.workspaceMember.create({ - data: { - workspace: { - connect: { - id: workspaceBobId - } - }, - user: { - connect: { - id: bobId - } - }, - invitationAccepted: true, - roles: { - create: { - role: { - connect: { - workspaceId_name: { - workspaceId: workspaceBobId, - name: 'Admin' - } - } - } - } - } - } + await workspaceRoleService.createWorkspaceRole(alice, workspaceAlice.id, { + name: 'Member', + description: 'Member Role', + colorCode: '#0000FF', + authorities: [Authority.READ_WORKSPACE_ROLE, Authority.READ_WORKSPACE] }) - const assignRoleForCharlie = prisma.workspaceMember.create({ + await prisma.workspaceMember.create({ data: { workspace: { connect: { - id: workspaceAliceId + id: workspaceAlice.id } }, user: { connect: { - id: charlieId + id: charlie.id } }, invitationAccepted: true, @@ -221,8 +138,8 @@ describe('Workspace Role Controller Tests', () => { role: { connect: { workspaceId_name: { - workspaceId: workspaceAliceId, - name: 'Viewer' + workspaceId: workspaceAlice.id, + name: 'Member' } } } @@ -231,37 +148,6 @@ describe('Workspace Role Controller Tests', () => { } }) - const result = await prisma.$transaction([ - createAlice, - createBob, - createCharlie, - createWorkspaceAlice, - createWorkspaceBob, - assignOwnershipForAlice, - assignOwnershipForBob, - assignRoleForCharlie - ]) - - alice = result[0] - bob = result[1] - charlie = result[2] - workspaceAlice = result[3] - workspaceBob = result[4] - - adminRole1 = await prisma.workspaceRole.findFirst({ - where: { - workspaceId: workspaceAlice.id, - hasAdminAuthority: true - } - }) - - adminRole2 = await prisma.workspaceRole.findFirst({ - where: { - workspaceId: workspaceBob.id, - hasAdminAuthority: true - } - }) - projects = await prisma.$transaction([ prisma.project.create({ data: { @@ -282,9 +168,19 @@ describe('Workspace Role Controller Tests', () => { ]) }) + afterEach(async () => { + await prisma.$transaction([ + prisma.user.deleteMany(), + prisma.workspace.deleteMany() + ]) + }) + it('should be defined', async () => { expect(app).toBeDefined() expect(prisma).toBeDefined() + expect(eventService).toBeDefined() + expect(workspaceRoleService).toBeDefined() + expect(userService).toBeDefined() }) it('should be able to get the auto generated admin role', async () => { @@ -401,6 +297,14 @@ describe('Workspace Role Controller Tests', () => { }) it('should not be able to create a workspace role with the same name', async () => { + // Create a role with the same name + await workspaceRoleService.createWorkspaceRole(alice, workspaceAlice.id, { + name: 'Test Role', + description: 'Test Role Description', + colorCode: '#0000FF', + authorities: [Authority.CREATE_SECRET, Authority.CREATE_WORKSPACE_ROLE] + }) + const response = await app.inject({ method: 'POST', url: `/workspace-role/${workspaceAlice.id}`, @@ -486,6 +390,13 @@ describe('Workspace Role Controller Tests', () => { }) it('should have created a WORKSPACE_ROLE_UPDATED event', async () => { + // Update the workspace role + await workspaceRoleService.updateWorkspaceRole(alice, adminRole1.id, { + name: 'Updated Admin', + description: 'Updated Description', + colorCode: '#00FF00' + }) + const response = await fetchEvents( eventService, alice, @@ -541,8 +452,8 @@ describe('Workspace Role Controller Tests', () => { method: 'PUT', url: `/workspace-role/${adminRole1.id}`, payload: { - name: 'Updated Admin', - description: 'Updated Description', + name: 'Admin', + description: 'Description', colorCode: '#00FF00', authorities: [Authority.CREATE_SECRET, Authority.CREATE_WORKSPACE_ROLE] }, @@ -577,7 +488,7 @@ describe('Workspace Role Controller Tests', () => { where: { workspaceId_name: { workspaceId: workspaceAlice.id, - name: 'Viewer' + name: 'Member' } }, data: { @@ -646,7 +557,7 @@ describe('Workspace Role Controller Tests', () => { where: { workspaceId_name: { workspaceId: workspaceAlice.id, - name: 'Viewer' + name: 'Member' } }, data: { @@ -696,6 +607,17 @@ describe('Workspace Role Controller Tests', () => { }) it('should have created a WORKSPACE_ROLE_DELETED event', async () => { + // Fetch the member role + const memberRole = await prisma.workspaceRole.findFirst({ + where: { + workspaceId: workspaceAlice.id, + name: 'Member' + } + }) + + // Delete the workspace role + await workspaceRoleService.deleteWorkspaceRole(alice, memberRole.id) + const response = await fetchEvents( eventService, alice, @@ -740,7 +662,7 @@ describe('Workspace Role Controller Tests', () => { it('should be able to check if the workspace role exists', async () => { const response = await app.inject({ method: 'GET', - url: `/workspace-role/${workspaceAlice.id}/exists/Viewer`, + url: `/workspace-role/${workspaceAlice.id}/exists/Member`, headers: { 'x-e2e-user-email': charlie.email } @@ -811,7 +733,7 @@ describe('Workspace Role Controller Tests', () => { where: { workspaceId_name: { workspaceId: workspaceAlice.id, - name: 'Viewer' + name: 'Member' } }, data: { @@ -852,7 +774,7 @@ describe('Workspace Role Controller Tests', () => { where: { workspaceId_name: { workspaceId: workspaceAlice.id, - name: 'Viewer' + name: 'Member' } }, data: { @@ -906,7 +828,7 @@ describe('Workspace Role Controller Tests', () => { where: { workspaceId_name: { workspaceId: workspaceAlice.id, - name: 'Viewer' + name: 'Member' } }, data: { @@ -955,7 +877,7 @@ describe('Workspace Role Controller Tests', () => { where: { workspaceId_name: { workspaceId: workspaceAlice.id, - name: 'Viewer' + name: 'Member' } }, data: { @@ -978,8 +900,4 @@ describe('Workspace Role Controller Tests', () => { expect(response.statusCode).toBe(401) }) - - afterAll(async () => { - await cleanUp(prisma) - }) }) diff --git a/apps/api/src/workspace/workspace.e2e.spec.ts b/apps/api/src/workspace/workspace.e2e.spec.ts index 3671cd45..a802dfb1 100644 --- a/apps/api/src/workspace/workspace.e2e.spec.ts +++ b/apps/api/src/workspace/workspace.e2e.spec.ts @@ -18,7 +18,6 @@ import { Workspace, WorkspaceRole } from '@prisma/client' -import cleanUp from '../common/cleanup' import fetchEvents from '../common/fetch-events' import { EventService } from '../event/service/event.service' import { EventModule } from '../event/event.module' @@ -1342,8 +1341,4 @@ describe('Workspace Controller Tests', () => { message: `You cannot transfer ownership of default workspace ${workspace1.name} (${workspace1.id})` }) }) - - afterAll(async () => { - await cleanUp(prisma) - }) })