From 48826feaa64fa2c35d5bdc9bd49b0bf3a965253f Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 28 Apr 2022 11:53:24 +0200 Subject: [PATCH] improve error messages --- .../graphql/resolver/AdminResolver.test.ts | 20 +++++++++---------- backend/src/graphql/resolver/AdminResolver.ts | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 5872a5092..c2a9256fd 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -236,7 +236,7 @@ describe('AdminResolver', () => { mutate({ mutation: unDeleteUser, variables: { userId: user.id } }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('User already deleted')], + errors: [new GraphQLError('User is not deleted')], }), ) }) @@ -265,7 +265,7 @@ describe('AdminResolver', () => { const variables = { email: 'bibi@bloxberg.de', amount: new Decimal(2000), - memo: 'Vielen Dank für den Zaubertrank!', + memo: 'Aktives Grundeinkommen', creationDate: 'not-valid', } @@ -552,7 +552,7 @@ describe('AdminResolver', () => { mutate({ mutation: createPendingCreation, variables }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('No Creation found!')], + errors: [new GraphQLError('No information for available creations for the given date')], }), ) }) @@ -570,7 +570,7 @@ describe('AdminResolver', () => { mutate({ mutation: createPendingCreation, variables }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('No Creation found!')], + errors: [new GraphQLError('No information for available creations for the given date')], }), ) }) @@ -588,7 +588,7 @@ describe('AdminResolver', () => { mutate({ mutation: createPendingCreation, variables }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('No Creation found!')], + errors: [new GraphQLError('No information for available creations for the given date')], }), ) }) @@ -603,7 +603,7 @@ describe('AdminResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (2000 GDD) to be created exceeds the available amount (1000 GDD) for this month.', + 'The amount (2000 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', ), ], }), @@ -635,7 +635,7 @@ describe('AdminResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (1000 GDD) to be created exceeds the available amount (800 GDD) for this month.', + 'The amount (1000 GDD) to be created exceeds the amount (800 GDD) still available for this month.', ), ], }), @@ -803,7 +803,7 @@ describe('AdminResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (1900 GDD) to be created exceeds the available amount (500 GDD) for this month.', + 'The amount (1900 GDD) to be created exceeds the amount (500 GDD) still available for this month.', ), ], }), @@ -917,7 +917,7 @@ describe('AdminResolver', () => { lastName: 'Bloxberg', email: 'bibi@bloxberg.de', date: expect.any(String), - memo: 'Vielen Dank für den Zaubertrank!', + memo: 'Aktives Grundeinkommen', amount: '200', moderator: admin.id, creation: ['1000', '1000', '300'], @@ -941,7 +941,7 @@ describe('AdminResolver', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('Creation not found to given id.')], + errors: [new GraphQLError('Creation not found for given id.')], }), ) }) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index ba703a554..94734d239 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -161,7 +161,7 @@ export class AdminResolver { throw new Error(`Could not find user with userId: ${userId}`) } if (!user.deletedAt) { - throw new Error('User already deleted') + throw new Error('User is not deleted') } await user.recover() return null @@ -309,7 +309,7 @@ export class AdminResolver { async deletePendingCreation(@Arg('id', () => Int) id: number): Promise { const pendingCreation = await AdminPendingCreation.findOne(id) if (!pendingCreation) { - throw new Error('Creation not found to given id.') + throw new Error('Creation not found for given id.') } const res = await AdminPendingCreation.delete(pendingCreation) return !!res @@ -526,12 +526,12 @@ function isCreationValid(creations: Decimal[], amount: Decimal, creationDate: Da const index = getCreationIndex(creationDate.getMonth()) if (index < 0) { - throw new Error(`No Creation found!`) + throw new Error('No information for available creations for the given date') } if (amount.greaterThan(creations[index].toString())) { throw new Error( - `The amount (${amount} GDD) to be created exceeds the available amount (${creations[index]} GDD) for this month.`, + `The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`, ) }