diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index b1b1b015f..8f8c5757e 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -675,9 +675,82 @@ describe('UserResolver', () => { describe('user is in database but deleted', () => { beforeAll(async () => { jest.clearAllMocks() + await userFactory(testEnv, stephenHawking) + const variables = { + email: stephenHawking.email, + password: 'Aa12345_', + publisherId: 1234, + } + result = await mutate({ mutation: login, variables }) + }) + + afterAll(async () => { + await cleanDB() + }) + + it('returns an error', () => { + expect(result).toEqual( + expect.objectContaining({ + errors: [ + new GraphQLError('This user was permanently deleted. Contact support for questions'), + ], + }), + ) + }) + + it('logs the error thrown', () => { + expect(logger.error).toBeCalledWith( + 'This user was permanently deleted. Contact support for questions', + expect.objectContaining({ + firstName: stephenHawking.firstName, + lastName: stephenHawking.lastName, + }), + ) + }) + }) + + describe('user is in database but email not confirmed', () => { + beforeAll(async () => { + jest.clearAllMocks() + await userFactory(testEnv, garrickOllivander) + const variables = { + email: garrickOllivander.email, + password: 'Aa12345_', + publisherId: 1234, + } + result = await mutate({ mutation: login, variables }) + }) + + afterAll(async () => { + await cleanDB() + }) + + it('returns an error', () => { + expect(result).toEqual( + expect.objectContaining({ + errors: [new GraphQLError('The Users email is not validate yet')], + }), + ) + }) + + it('logs the error thrown', () => { + expect(logger.error).toBeCalledWith( + 'The Users email is not validate yet', + expect.objectContaining({ + firstName: garrickOllivander.firstName, + lastName: garrickOllivander.lastName, + }), + ) + }) + }) + + describe.skip('user is in database but password is not set', () => { + beforeAll(async () => { + jest.clearAllMocks() + // TODO: we need an user without password set const user = await userFactory(testEnv, bibiBloxberg) - // Hint: softRemove does not soft-delete the email contact of this user - await user.softRemove() + user.password = BigInt(0) + await user.save() result = await mutate({ mutation: login, variables }) }) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index fe33d9287..b50cf3af5 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -140,6 +140,7 @@ export class UserResolver { if (!dbUser.emailContact.emailChecked) { throw new LogError('The Users email is not validate yet', dbUser) } + // TODO: at least in test this does not work since `dbUser.password = 0` and `BigInto(0) = 0n` if (dbUser.password === BigInt(0)) { // TODO we want to catch this on the frontend and ask the user to check his emails or resend code throw new LogError('The User has not set a password yet', dbUser)