From fe5fb607e52e0bbcfa57dbf059773a735d9ea351 Mon Sep 17 00:00:00 2001 From: Florian Rossiaud Date: Thu, 15 Jun 2023 08:51:11 +0200 Subject: [PATCH] fix: remove the default JwtAuthGuard from /me (#628) * fix: remove the default JwtAuthGuard from /me * fix: update-method spec in nestjs-authorized-service * test: update the tests --------- Co-authored-by: Mickael Martos --- .../service/methods/count-method.generator.spec.ts | 6 ++++-- .../service/methods/create-method.generator.spec.ts | 6 ++++-- .../service/methods/delete-method.generator.spec.ts | 6 ++++-- .../methods/find-many-method.generator.spec.ts | 6 ++++-- .../methods/find-unique-method.generator.spec.ts | 11 +++++++++-- .../service/methods/update-method.generator.spec.ts | 8 +++++++- .../service/aggregate-method.generator.spec.ts | 4 +++- .../service/count-method.generator.spec.ts | 4 +++- .../service/create-many-method.generator.spec.ts | 4 +++- .../service/create-method.generator.spec.ts | 4 +++- .../service/delete-many-method.generator.spec.ts | 4 +++- .../service/delete-method.generator.spec.ts | 4 +++- .../service/find-first-method.generator.spec.ts | 8 +++++--- .../service/find-many-method.generator.spec.ts | 4 +++- .../service/find-unique-method.generator.spec.ts | 11 +++++++++-- .../service/update-many-method.generator.spec.ts | 9 ++++++--- .../service/update-method.generator.spec.ts | 5 +++++ .../service/upsert-method.generator.spec.ts | 4 +++- .../src/authentication.module.spec.ts | 13 ++++--------- .../src/controllers/login.controller.spec.ts | 2 +- .../src/controllers/login.controller.ts | 1 - 21 files changed, 86 insertions(+), 38 deletions(-) diff --git a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/count-method.generator.spec.ts b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/count-method.generator.spec.ts index 482b0d705..827948b8a 100644 --- a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/count-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/count-method.generator.spec.ts @@ -61,14 +61,16 @@ describe('generateCountMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { expect( compressWhitespace((methodDeclaration.statements as string[]).join('\n')), ).toEqual( - `const where = { AND: [abilities ? accessibleBy(abilities).User : {}, args?.where ?? {}], }; return this.userService.count({ ...args, where });`, + `const where = { AND: [abilities ? accessibleBy(abilities).User : {}, args?.where ?? {}], }; return this.userService.count({ ...args, where });`, ); }); }); diff --git a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/create-method.generator.spec.ts b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/create-method.generator.spec.ts index 08e01478f..f0352a186 100644 --- a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/create-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/create-method.generator.spec.ts @@ -58,7 +58,9 @@ describe('generateCreateMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); expect(abilitiesParameters?.name).toEqual('abilities'); expect(abilitiesParameters?.kind).toEqual(30); @@ -69,7 +71,7 @@ describe('generateCreateMethod', () => { }); it('generates a method declaration with the correct statements', () => { - const expectedStatements = `const create = async(client: Prisma.UserDelegate) => { const user = await this.userService.create(args, client); if (abilities?.cannot(Action.Create, subject('User', user))) throw new ForbiddenException('cannot create User'); return user; } if (prisma) return create(prisma); return this.prisma.$transaction((client) => create(client.user));`; + const expectedStatements = `const create = async(client: Prisma.UserDelegate) => { const user = await this.userService.create(args, client); if (abilities?.cannot(Action.Create, subject('User', user))) throw new ForbiddenException('cannot create User'); return user; } if (prisma) return create(prisma); return this.prisma.$transaction((client) => create(client.user));`; expect( compressWhitespace((methodDeclaration.statements as string[]).join('\n')), diff --git a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/delete-method.generator.spec.ts b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/delete-method.generator.spec.ts index 4febe82cf..ec2a8bac1 100644 --- a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/delete-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/delete-method.generator.spec.ts @@ -60,14 +60,16 @@ describe('generateDeleteMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { expect( compressWhitespace((method.statements as string[]).join('\n')), ).toEqual( - `const deleteCb = async(client: Prisma.UserDelegate) => { const user = await this.userService.delete(args, client); if (abilities?.cannot(Action.Delete, subject('User', user))) throw new ForbiddenException('cannot delete User'); return user; } if (prisma) return deleteCb(prisma); return this.prisma.$transaction((client) => deleteCb(client.user));`, + `const deleteCb = async(client: Prisma.UserDelegate) => { const user = await this.userService.delete(args, client); if (abilities?.cannot(Action.Delete, subject('User', user))) throw new ForbiddenException('cannot delete User'); return user; } if (prisma) return deleteCb(prisma); return this.prisma.$transaction((client) => deleteCb(client.user));`, ); }); }); diff --git a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/find-many-method.generator.spec.ts b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/find-many-method.generator.spec.ts index 90fed2571..677041d38 100644 --- a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/find-many-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/find-many-method.generator.spec.ts @@ -59,12 +59,14 @@ describe('generateFindManyMethod', () => { expect(parameters?.[1].kind).toEqual(30); // corresponds to `StructureKind.Parameter` expect(parameters?.[2].name).toEqual('prisma'); - expect(parameters?.[2].type).toEqual(`Prisma.UserDelegate`); + expect(parameters?.[2].type).toEqual( + `Prisma.UserDelegate`, + ); expect(parameters?.[2].kind).toEqual(30); // corresponds to `StructureKind.Parameter` }); it('generates a method declaration with the correct statements', () => { - const expectedStatements = `const where = { AND: [abilities ? accessibleBy(abilities).User : {}, args?.where ?? {}], }; return this.userService.findMany({ ...args, where }, prisma);`; + const expectedStatements = `const where = { AND: [abilities ? accessibleBy(abilities).User : {}, args?.where ?? {}], }; return this.userService.findMany({ ...args, where }, prisma);`; expect( compressWhitespace((generatedMethod.statements as string[]).join('\n')), ).toEqual(expectedStatements); diff --git a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/find-unique-method.generator.spec.ts b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/find-unique-method.generator.spec.ts index 12d06e18f..2122b7076 100644 --- a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/find-unique-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/find-unique-method.generator.spec.ts @@ -46,6 +46,11 @@ describe('generateFindUniqueMethod', () => { kind: StructureKind.TypeParameter, constraint: `Prisma.UserFindUniqueArgs`, }, + { + name: 'GlobalRejectSettings', + kind: StructureKind.TypeParameter, + constraint: `Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined`, + }, ]; expect(methodDeclaration.typeParameters).toEqual(expectedTypeParameters); @@ -64,7 +69,9 @@ describe('generateFindUniqueMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); // StructureKind.Parameter is equal to 30 - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); expect(abilitiesParameters?.name).toEqual('abilities'); expect(abilitiesParameters?.kind).toEqual(30); // StructureKind.Parameter is equal to 30 @@ -77,7 +84,7 @@ describe('generateFindUniqueMethod', () => { expect( compressWhitespace((methodDeclaration.statements as string[]).join('\n')), ).toBe( - `const user = await this.userService.findUnique(args, prisma); if (user && abilities?.cannot(Action.Read, subject('User', user))) throw new ForbiddenException('cannot read this user'); return user`, + `const user = await this.userService.findUnique(args, prisma); if (user && abilities?.cannot(Action.Read, subject('User', user))) throw new ForbiddenException('cannot read this user'); return user`, ); }); }); diff --git a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/update-method.generator.spec.ts b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/update-method.generator.spec.ts index ba79c0079..a9beccac8 100644 --- a/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/update-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-authorized-services/src/generators/service/methods/update-method.generator.spec.ts @@ -45,13 +45,19 @@ describe('generateUpdateMethod', () => { kind: StructureKind.TypeParameter, constraint: `Prisma.UserUpdateArgs`, }, + { + name: 'GlobalRejectSettings', + kind: StructureKind.TypeParameter, + constraint: + 'Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined', + }, ]); // Check return type expect( compressWhitespace((methodDeclaration.statements as string[]).join('\n')), ).toBe( - `const update = async(client: Prisma.UserDelegate) => { const user = await this.userService.update(args, client); if (abilities?.cannot(Action.Update, subject('User', user))) throw new ForbiddenException('cannot update User'); return user; } if (prisma) return update(prisma); return this.prisma.$transaction((client) => update(client.user));`, + `const update = async(client: Prisma.UserDelegate) => { const user = await this.userService.update(args, client); if (abilities?.cannot(Action.Update, subject('User', user))) throw new ForbiddenException('cannot update User'); return user; } if (prisma) return update(prisma); return this.prisma.$transaction((client) => update(client.user));`, ); // TODO : a check for description ? see with Max diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/aggregate-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/aggregate-method.generator.spec.ts index 591f0eda4..a7ff81637 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/aggregate-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/aggregate-method.generator.spec.ts @@ -51,7 +51,9 @@ describe('generateAggregateMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/count-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/count-method.generator.spec.ts index 37898e5cf..5684aa26b 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/count-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/count-method.generator.spec.ts @@ -52,7 +52,9 @@ describe('generateCountMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/create-many-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/create-many-method.generator.spec.ts index 3cdb317ac..beae6cbd3 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/create-many-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/create-many-method.generator.spec.ts @@ -58,7 +58,9 @@ describe('generateCreateMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/create-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/create-method.generator.spec.ts index 28fc1c6bf..5343959a1 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/create-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/create-method.generator.spec.ts @@ -57,7 +57,9 @@ describe('generateCreateMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/delete-many-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/delete-many-method.generator.spec.ts index e2ed8fb8e..c9dc7a1c7 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/delete-many-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/delete-many-method.generator.spec.ts @@ -51,7 +51,9 @@ describe('generateDeleteMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/delete-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/delete-method.generator.spec.ts index 335d9e884..cc63506a7 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/delete-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/delete-method.generator.spec.ts @@ -52,7 +52,9 @@ describe('generateDeleteMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); expect(prismaParameters?.kind).toEqual(StructureKind.Parameter); - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/find-first-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/find-first-method.generator.spec.ts index bce0cf7c1..375111f66 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/find-first-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/find-first-method.generator.spec.ts @@ -39,7 +39,7 @@ describe('generateFindFirstMethod', () => { const typeParameters: TypeParameterDeclarationStructure[] = method.typeParameters as TypeParameterDeclarationStructure[]; - expect(typeParameters.length).toEqual(1); + expect(typeParameters.length).toEqual(2); expect(typeParameters[0].name).toEqual('T'); expect(typeParameters[0].constraint).toEqual( `Prisma.${pascal(model.name)}FindFirstArgs`, @@ -58,13 +58,15 @@ describe('generateFindFirstMethod', () => { ); expect(parameters[1].name).toEqual('prisma'); - expect(parameters[1].type).toEqual(`Prisma.UserDelegate`); + expect(parameters[1].type).toEqual( + `Prisma.UserDelegate`, + ); expect(parameters[1].initializer).toEqual(`this.prismaClient.user`); }); it('generates a method declaration with the correct statements', () => { expect(compressWhitespace(method.statements as string)).toEqual( - `const user = await prisma.findFirst(args); return user;`, + `const user = await prisma.findFirst(args); return user;`, ); }); diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/find-many-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/find-many-method.generator.spec.ts index 7b546ac8f..b68a868c3 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/find-many-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/find-many-method.generator.spec.ts @@ -53,7 +53,9 @@ describe('generateFindManyMethod', () => { expect(parameters?.[0].kind).toEqual(30); // corresponds to `StructureKind.Parameter` expect(parameters?.[1].name).toEqual('prisma'); - expect(parameters?.[1].type).toEqual(`Prisma.UserDelegate`); + expect(parameters?.[1].type).toEqual( + `Prisma.UserDelegate`, + ); expect(parameters?.[1].kind).toEqual(30); // corresponds to `StructureKind.Parameter` expect(parameters?.[1].initializer).toEqual(`this.prismaClient.user`); }); diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/find-unique-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/find-unique-method.generator.spec.ts index 08cb7fa44..2ee7af31e 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/find-unique-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/find-unique-method.generator.spec.ts @@ -47,6 +47,11 @@ describe('generateFindUniqueMethod', () => { kind: StructureKind.TypeParameter, constraint: `Prisma.UserFindUniqueArgs`, }, + { + name: 'GlobalRejectSettings', + kind: StructureKind.TypeParameter, + constraint: `Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined`, + }, ]; expect(methodDeclaration.typeParameters).toEqual(expectedTypeParameters); @@ -64,12 +69,14 @@ describe('generateFindUniqueMethod', () => { expect(prismaParameters?.name).toEqual('prisma'); expect(prismaParameters?.kind).toEqual(30); // StructureKind.Parameter is equal to 30 - expect(prismaParameters?.type).toEqual(`Prisma.UserDelegate`); + expect(prismaParameters?.type).toEqual( + `Prisma.UserDelegate`, + ); }); it('generates a method declaration with the correct statements', () => { expect(compressWhitespace(methodDeclaration.statements as string)).toBe( - 'const user = await prisma.findUnique(args); return user;', + 'const user = await prisma.findUnique(args); return user;', ); }); diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/update-many-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/update-many-method.generator.spec.ts index 5b06bc5a1..414628223 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/update-many-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/update-many-method.generator.spec.ts @@ -38,7 +38,7 @@ describe('generateUpdateManyMethod', () => { ); expect(methodDeclaration.parameters?.[1].name).toBe('prisma'); expect(methodDeclaration.parameters?.[1].type).toBe( - `Prisma.UserDelegate`, + `Prisma.UserDelegate`, ); expect(methodDeclaration.parameters?.[1].initializer).toBe( `this.prismaClient.user`, @@ -51,13 +51,16 @@ describe('generateUpdateManyMethod', () => { kind: StructureKind.TypeParameter, constraint: `Prisma.UserUpdateManyArgs`, }, + { + name: 'GlobalRejectSettings', + kind: StructureKind.TypeParameter, + constraint: `Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined`, + }, ]); // Check return type expect(methodDeclaration.statements).toBe( `return prisma.updateMany(args);`, ); - - // TODO : a check for description ? see with Max }); }); diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/update-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/update-method.generator.spec.ts index 0324f7b64..17dc19b0f 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/update-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/update-method.generator.spec.ts @@ -48,6 +48,11 @@ describe('generateUpdateMethod', () => { kind: StructureKind.TypeParameter, constraint: `Prisma.UserUpdateArgs`, }, + { + name: 'GlobalRejectSettings', + kind: StructureKind.TypeParameter, + constraint: `Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined`, + }, ]); // Check return type diff --git a/libs/hapify/generators/nestjs-services/src/generators/service/upsert-method.generator.spec.ts b/libs/hapify/generators/nestjs-services/src/generators/service/upsert-method.generator.spec.ts index d8161a06a..ee58ef407 100644 --- a/libs/hapify/generators/nestjs-services/src/generators/service/upsert-method.generator.spec.ts +++ b/libs/hapify/generators/nestjs-services/src/generators/service/upsert-method.generator.spec.ts @@ -42,7 +42,9 @@ describe('generateUpsertMethod', () => { const prismaParameter = methodDeclaration.parameters?.[1]; expect(prismaParameter?.name).toBe('prisma'); - expect(prismaParameter?.type).toBe(`Prisma.UserDelegate`); + expect(prismaParameter?.type).toBe( + `Prisma.UserDelegate`, + ); expect(prismaParameter?.initializer).toBe(`this.prismaClient.user`); expect(compressWhitespace(methodDeclaration.statements as string)).toBe( diff --git a/libs/nestjs/authentication/src/authentication.module.spec.ts b/libs/nestjs/authentication/src/authentication.module.spec.ts index af39e86a4..53f203e5d 100644 --- a/libs/nestjs/authentication/src/authentication.module.spec.ts +++ b/libs/nestjs/authentication/src/authentication.module.spec.ts @@ -137,10 +137,6 @@ describe('Authentication Module', () => { app = moduleFixture.createNestApplication(); await app.init(); - - app = moduleFixture.createNestApplication(); - - await app.init(); }); afterEach(async () => { @@ -163,15 +159,14 @@ describe('Authentication Module', () => { await request(app.getHttpServer()).post('/logout').expect(200); }); - it('/me should fail with 401 and reset cookie', async () => { + it('/me should fail with 400 and not reset cookie', async () => { const response = await request(app.getHttpServer()) .get('/me') - .expect(401); + .expect(400); - const cookie = response.headers['set-cookie'][0]; + const cookie = response.headers['set-cookie']; - expect(cookie).toMatch(/authCookie=/); - expect(cookie).toMatch(/Path=\//); + expect(cookie).toBeUndefined(); }); }); }); diff --git a/libs/nestjs/authentication/src/controllers/login.controller.spec.ts b/libs/nestjs/authentication/src/controllers/login.controller.spec.ts index cdf470b66..1826c7cfc 100644 --- a/libs/nestjs/authentication/src/controllers/login.controller.spec.ts +++ b/libs/nestjs/authentication/src/controllers/login.controller.spec.ts @@ -114,7 +114,7 @@ describe('Login Controller', () => { expect(response.body).toEqual(mockUser); // eslint-disable-next-line @typescript-eslint/unbound-method - expect(mockUserService.findUserById).toHaveBeenCalledTimes(2); + expect(mockUserService.findUserById).toHaveBeenCalledTimes(1); }); }); diff --git a/libs/nestjs/authentication/src/controllers/login.controller.ts b/libs/nestjs/authentication/src/controllers/login.controller.ts index 4e4b508d9..0309cde45 100644 --- a/libs/nestjs/authentication/src/controllers/login.controller.ts +++ b/libs/nestjs/authentication/src/controllers/login.controller.ts @@ -57,7 +57,6 @@ export class LoginController { } @Get('me') - @UseGuards(JwtAuthGuard) async me( @CurrentUser() currentUser: U, ): Promise {