diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index 6842f09ca..ca6bf0fe7 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -1053,6 +1053,53 @@ describe('AdminResolver', () => { expect(transaction[0].typeId).toEqual(1) }) }) + + describe('confirm two creations one after the other quickly', () => { + let c1: AdminPendingCreation | void + let c2: AdminPendingCreation | void + + beforeAll(async () => { + const now = new Date() + c1 = await creationFactory(testEnv, { + email: 'bibi@bloxberg.de', + amount: 50, + memo: 'Herzlich Willkommen bei Gradido liebe Bibi!', + creationDate: new Date(now.getFullYear(), now.getMonth() - 2, 1).toISOString(), + }) + c2 = await creationFactory(testEnv, { + email: 'bibi@bloxberg.de', + amount: 50, + memo: 'Herzlich Willkommen bei Gradido liebe Bibi!', + creationDate: new Date(now.getFullYear(), now.getMonth() - 2, 1).toISOString(), + }) + }) + + // In the futrue this should not throw anymore + it('throws an error for the second confirmation', async () => { + const r1 = mutate({ + mutation: confirmPendingCreation, + variables: { + id: c1 ? c1.id : -1, + }, + }) + const r2 = mutate({ + mutation: confirmPendingCreation, + variables: { + id: c2 ? c2.id : -1, + }, + }) + await expect(r1).resolves.toEqual( + expect.objectContaining({ + data: { confirmPendingCreation: true }, + }), + ) + await expect(r2).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Unable to confirm creation.')], + }), + ) + }) + }) }) }) }) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index ad89767bc..8da92a61c 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -362,8 +362,7 @@ export class AdminResolver { transaction.decay = decay ? decay.decay : new Decimal(0) transaction.decayStart = decay ? decay.start : null await transaction.save().catch(() => { - // eslint-disable-next-line no-console - console.log('Unable to save transaction.') + throw new Error('Unable to confirm creation.') }) await AdminPendingCreation.delete(pendingCreation)