test contribution link redeem

This commit is contained in:
Ulf Gebhardt 2023-03-09 12:40:29 +01:00
parent 9493ed58d9
commit 09c5aff33e
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9

View File

@ -26,6 +26,9 @@ import Decimal from 'decimal.js-light'
import { GraphQLError } from 'graphql'
import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK'
import { logger } from '@test/testSetup'
import { EventType } from '@/event/Event'
import { Event as DbEvent } from '@entity/Event'
import { UserContact } from '@entity/UserContact'
// mock semaphore to allow use fake timers
jest.mock('@/util/TRANSACTIONS_LOCK')
@ -432,6 +435,24 @@ describe('TransactionLinkResolver', () => {
})
})
it('stores the CONTRIBUTION_LINK_REDEEM event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.CONTRIBUTION_LINK_REDEEM,
affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
involvedTransactionId: expect.any(Number),
involvedContributionId: expect.any(Number),
involvedContributionLinkId: contributionLink?.id,
amount: contributionLink?.amount,
}),
)
})
it('does not allow the user to redeem the contribution link a second time on the same day', async () => {
jest.clearAllMocks()
await expect(