From 8d800fc7da3b06caadb2db1277be9a0c52a77581 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 13 Jan 2022 09:55:09 +0100 Subject: [PATCH] test some error cases --- .../src/graphql/resolver/UserResolver.test.ts | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index fb4e42bf6..1a535ae72 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -261,10 +261,10 @@ describe('UserResolver', () => { setPassword(code: $code, password: $password) } ` + let result: any + let emailOptIn: string describe('valid optin code and valid password', () => { - let emailOptIn: string - let result: any let loginUser: any let newLoginUser: any let newUser: any @@ -288,6 +288,10 @@ describe('UserResolver', () => { await resetDB() }) + it('sets email checked to true', () => { + expect(newLoginUser[0].emailChecked).toBeTruthy() + }) + it('updates the password', () => { expect(newLoginUser[0].password).toEqual('3917921995996627700') }) @@ -322,6 +326,58 @@ describe('UserResolver', () => { expect(result).toBeTruthy() }) }) + + describe('no valid password', () => { + beforeAll(async () => { + await mutate({ mutation: createUserMutation, variables: createUserVariables }) + const loginEmailOptIn = await getRepository(LoginEmailOptIn) + .createQueryBuilder('login_email_optin') + .getMany() + emailOptIn = loginEmailOptIn[0].verificationCode.toString() + result = await mutate({ + mutation: setPasswordMutation, + variables: { code: emailOptIn, password: 'not-valid' }, + }) + }) + + afterAll(async () => { + await resetDB() + }) + + it('throws an error', () => { + expect(result).toEqual( + expect.objectContaining({ + errors: [ + new GraphQLError( + 'Please enter a valid password with at least 8 characters, upper and lower case letters, at least one number and one special character!', + ), + ], + }), + ) + }) + }) + + describe('no valid optin code', () => { + beforeAll(async () => { + await mutate({ mutation: createUserMutation, variables: createUserVariables }) + result = await mutate({ + mutation: setPasswordMutation, + variables: { code: 'not valid', password: 'Aa12345_' }, + }) + }) + + afterAll(async () => { + await resetDB() + }) + + it('throws an error', () => { + expect(result).toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Could not login with emailVerificationCode')], + }), + ) + }) + }) }) })