From cbd8895acfd5569e8d57b4174a529ae2b3ab9c06 Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 30 Jan 2023 16:40:43 +0100 Subject: [PATCH 1/4] refactor error message in user resolver --- backend/src/graphql/resolver/UserResolver.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index c630c240a..94b9265b3 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -392,16 +392,11 @@ export class UserResolver { } if (!canEmailResend(user.emailContact.updatedAt || user.emailContact.createdAt)) { - logger.error( - `email already sent less than ${printTimeDuration( - CONFIG.EMAIL_CODE_REQUEST_TIME, - )} minutes ago`, - ) - throw new Error( - `email already sent less than ${printTimeDuration( - CONFIG.EMAIL_CODE_REQUEST_TIME, - )} minutes ago`, - ) + const errorMessage = `email already sent less than ${printTimeDuration( + CONFIG.EMAIL_CODE_REQUEST_TIME, + )} ago` + logger.error(errorMessage) + throw new Error(errorMessage) } user.emailContact.updatedAt = new Date() From fab594663131ad5f70335c6d5fa8782bba9261ba Mon Sep 17 00:00:00 2001 From: mahula Date: Mon, 30 Jan 2023 16:41:44 +0100 Subject: [PATCH 2/4] adapt unit tests to changes in user resolver's error message --- backend/src/graphql/resolver/EmailOptinCodes.test.ts | 2 +- backend/src/graphql/resolver/UserResolver.test.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/EmailOptinCodes.test.ts b/backend/src/graphql/resolver/EmailOptinCodes.test.ts index d7c0b9bd6..b1bef0618 100644 --- a/backend/src/graphql/resolver/EmailOptinCodes.test.ts +++ b/backend/src/graphql/resolver/EmailOptinCodes.test.ts @@ -96,7 +96,7 @@ describe('EmailOptinCodes', () => { mutate({ mutation: forgotPassword, variables: { email: 'peter@lustig.de' } }), ).resolves.toMatchObject({ data: null, - errors: [new GraphQLError('email already sent less than 10 minutes minutes ago')], + errors: [new GraphQLError('email already sent less than 10 minutes ago')], }) }) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 073bad04d..9060f2696 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -830,7 +830,7 @@ describe('UserResolver', () => { new GraphQLError( `email already sent less than ${printTimeDuration( CONFIG.EMAIL_CODE_REQUEST_TIME, - )} minutes ago`, + )} ago`, ), ], }), @@ -870,13 +870,13 @@ describe('UserResolver', () => { CONFIG.EMAIL_CODE_REQUEST_TIME = emailCodeRequestTime await expect(mutate({ mutation: forgotPassword, variables })).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('email already sent less than 10 minutes minutes ago')], + errors: [new GraphQLError('email already sent less than 10 minutes ago')], }), ) }) it('logs the error found', () => { - expect(logger.error).toBeCalledWith(`email already sent less than 10 minutes minutes ago`) + expect(logger.error).toBeCalledWith(`email already sent less than 10 minutes ago`) }) }) }) From 84a1cfcf773c5d7163f969c56b9cbbb996a3989d Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 31 Jan 2023 13:53:40 +0100 Subject: [PATCH 3/4] fix(backend): unit tests creations for day 31 --- .../graphql/resolver/util/creations.test.ts | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/backend/src/graphql/resolver/util/creations.test.ts b/backend/src/graphql/resolver/util/creations.test.ts index d9ccf6936..d367d7be8 100644 --- a/backend/src/graphql/resolver/util/creations.test.ts +++ b/backend/src/graphql/resolver/util/creations.test.ts @@ -21,7 +21,7 @@ beforeAll(async () => { }) afterAll(async () => { - await cleanDB() + // await cleanDB() await con.close() }) @@ -62,7 +62,7 @@ describe('util/creation', () => { amount: 160.0, memo: 'Admin contribution for the last month', creationDate: contributionDateFormatter( - new Date(now.getFullYear(), now.getMonth() - 1, now.getDate()), + new Date(now.getFullYear(), now.getMonth() - 1, 1), ), }, }) @@ -73,7 +73,7 @@ describe('util/creation', () => { amount: 450.0, memo: 'Admin contribution for two months ago', creationDate: contributionDateFormatter( - new Date(now.getFullYear(), now.getMonth() - 2, now.getDate()), + new Date(now.getFullYear(), now.getMonth() - 2, 1), ), }, }) @@ -95,7 +95,7 @@ describe('util/creation', () => { amount: 500.0, memo: 'Contribution for the last month', creationDate: contributionDateFormatter( - new Date(now.getFullYear(), now.getMonth() - 1, now.getDate()), + new Date(now.getFullYear(), now.getMonth() - 1, 1), ), }, }) @@ -114,9 +114,7 @@ describe('util/creation', () => { }), expect.objectContaining({ userId: user.id, - contributionDate: setZeroHours( - new Date(now.getFullYear(), now.getMonth() - 1, now.getDate()), - ), + contributionDate: setZeroHours(new Date(now.getFullYear(), now.getMonth() - 1, 1)), amount: expect.decimalEqual(160), memo: 'Admin contribution for the last month', moderatorId: admin.id, @@ -125,9 +123,7 @@ describe('util/creation', () => { }), expect.objectContaining({ userId: user.id, - contributionDate: setZeroHours( - new Date(now.getFullYear(), now.getMonth() - 2, now.getDate()), - ), + contributionDate: setZeroHours(new Date(now.getFullYear(), now.getMonth() - 2, 1)), amount: expect.decimalEqual(450), memo: 'Admin contribution for two months ago', moderatorId: admin.id, @@ -145,9 +141,7 @@ describe('util/creation', () => { }), expect.objectContaining({ userId: user.id, - contributionDate: setZeroHours( - new Date(now.getFullYear(), now.getMonth() - 1, now.getDate()), - ), + contributionDate: setZeroHours(new Date(now.getFullYear(), now.getMonth() - 1, 1)), amount: expect.decimalEqual(500), memo: 'Contribution for the last month', moderatorId: null, From d7fca05bc8fa8568a743cf6b32895d7b740ff28f Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 31 Jan 2023 14:04:19 +0100 Subject: [PATCH 4/4] clean db after tests again --- backend/src/graphql/resolver/util/creations.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/util/creations.test.ts b/backend/src/graphql/resolver/util/creations.test.ts index d367d7be8..4d8132333 100644 --- a/backend/src/graphql/resolver/util/creations.test.ts +++ b/backend/src/graphql/resolver/util/creations.test.ts @@ -21,7 +21,7 @@ beforeAll(async () => { }) afterAll(async () => { - // await cleanDB() + await cleanDB() await con.close() })