diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index 49bca2c42..62f273829 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -257,17 +257,13 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [ - new GraphQLError('Start-Date is not initialized. A Start-Date must be set!'), - ], + errors: [new GraphQLError('A Start-Date must be set')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith( - 'Start-Date is not initialized. A Start-Date must be set!', - ) + expect(logger.error).toBeCalledWith('A Start-Date must be set') }) it('returns an error if missing endDate', async () => { @@ -282,15 +278,13 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('End-Date is not initialized. An End-Date must be set!')], + errors: [new GraphQLError('An End-Date must be set')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith( - 'End-Date is not initialized. An End-Date must be set!', - ) + expect(logger.error).toBeCalledWith('An End-Date must be set') }) it('returns an error if endDate is before startDate', async () => { @@ -307,7 +301,7 @@ describe('Contribution Links', () => { ).resolves.toEqual( expect.objectContaining({ errors: [ - new GraphQLError(`The value of validFrom must before or equals the validTo!`), + new GraphQLError(`The value of validFrom must before or equals the validTo`), ], }), ) @@ -315,7 +309,7 @@ describe('Contribution Links', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - `The value of validFrom must before or equals the validTo!`, + `The value of validFrom must before or equals the validTo`, ) }) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 670eaac2d..b56180c45 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -245,8 +245,8 @@ describe('ContributionResolver', () => { it('logs the error found', () => { expect(logger.error).toBeCalledWith( - 'No information for available creations with the given creationDate=', - 'Invalid Date', + 'No information for available creations for the given date', + expect.any(Date), ) }) @@ -268,8 +268,8 @@ describe('ContributionResolver', () => { it('logs the error found', () => { expect(logger.error).toBeCalledWith( - 'No information for available creations with the given creationDate=', - 'Invalid Date', + 'No information for available creations for the given date', + expect.any(Date), ) }) }) @@ -526,14 +526,16 @@ describe('ContributionResolver', () => { }) expect(errorObjects).toEqual([ new GraphQLError( - 'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', ), ]) }) it('logs the error found', () => { expect(logger.error).toBeCalledWith( - 'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', + new Decimal(1019), + new Decimal(600), ) }) }) @@ -2008,8 +2010,8 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'No information for available creations with the given creationDate=', - new Date(variables.creationDate).toString(), + 'No information for available creations for the given date', + new Date(variables.creationDate), ) }) }) @@ -2033,8 +2035,8 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'No information for available creations with the given creationDate=', - new Date(variables.creationDate).toString(), + 'No information for available creations for the given date', + new Date(variables.creationDate), ) }) }) @@ -2049,7 +2051,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (2000 GDD) to be created exceeds the amount (790 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', ), ], }), @@ -2058,7 +2060,9 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'The amount (2000 GDD) to be created exceeds the amount (790 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', + new Decimal(2000), + new Decimal(790), ) }) }) @@ -2098,7 +2102,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (1000 GDD) to be created exceeds the amount (590 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', ), ], }), @@ -2107,7 +2111,9 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'The amount (1000 GDD) to be created exceeds the amount (590 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', + new Decimal(1000), + new Decimal(590), ) }) }) @@ -2300,7 +2306,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (1900 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', ), ], }), @@ -2309,7 +2315,9 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'The amount (1900 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', + new Decimal(1900), + new Decimal(1000), ) }) }) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts index f60ab45d0..2b0950a33 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts @@ -362,7 +362,7 @@ describe('TransactionLinkResolver', () => { expect(logger.error).toBeCalledWith( 'Creation from contribution link was not successful', new Error( - 'The amount (5 GDD) to be created exceeds the amount (0 GDD) still available for this month.', + 'The amount to be created exceeds the amount still available for this month', ), ) }) diff --git a/backend/src/graphql/resolver/util/creations.ts b/backend/src/graphql/resolver/util/creations.ts index 00137eaa1..6a47915b1 100644 --- a/backend/src/graphql/resolver/util/creations.ts +++ b/backend/src/graphql/resolver/util/creations.ts @@ -1,3 +1,4 @@ +import LogError from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' import { getConnection } from '@dbTools/typeorm' import { Contribution } from '@entity/Contribution' @@ -19,19 +20,14 @@ export const validateContribution = ( const index = getCreationIndex(creationDate.getMonth(), timezoneOffset) if (index < 0) { - logger.error( - 'No information for available creations with the given creationDate=', - creationDate.toString(), - ) - throw new Error('No information for available creations for the given date') + throw new LogError('No information for available creations for the given date', creationDate) } if (amount.greaterThan(creations[index].toString())) { - logger.error( - `The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`, - ) - throw new Error( - `The amount (${amount} GDD) to be created exceeds the amount (${creations[index]} GDD) still available for this month.`, + throw new LogError( + 'The amount to be created exceeds the amount still available for this month', + amount, + creations[index], ) } } @@ -126,19 +122,16 @@ export const isStartEndDateValid = ( endDate: string | null | undefined, ): void => { if (!startDate) { - logger.error('Start-Date is not initialized. A Start-Date must be set!') - throw new Error('Start-Date is not initialized. A Start-Date must be set!') + throw new LogError('A Start-Date must be set') } if (!endDate) { - logger.error('End-Date is not initialized. An End-Date must be set!') - throw new Error('End-Date is not initialized. An End-Date must be set!') + throw new LogError('An End-Date must be set') } // check if endDate is before startDate if (new Date(endDate).getTime() - new Date(startDate).getTime() < 0) { - logger.error(`The value of validFrom must before or equals the validTo!`) - throw new Error(`The value of validFrom must before or equals the validTo!`) + throw new LogError(`The value of validFrom must before or equals the validTo`) } }