From afd5703c807442f2c2a834045a538b1aadb1cff0 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 29 Mar 2023 11:06:47 +0200 Subject: [PATCH] missing event tests --- .../resolver/TransactionLinkResolver.test.ts | 109 +++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts index d86f260fe..cdb832963 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts @@ -22,6 +22,7 @@ import { createContribution, updateContribution, createTransactionLink, + deleteTransactionLink, confirmContribution, } from '@/seeds/graphql/mutations' import { listTransactionLinksAdmin } from '@/seeds/graphql/queries' @@ -573,6 +574,7 @@ describe('TransactionLinkResolver', () => { describe('link exists', () => { let myCode: string + let myId: number beforeAll(async () => { await mutate({ @@ -589,7 +591,7 @@ describe('TransactionLinkResolver', () => { }) const { data: { - createTransactionLink: { code }, + createTransactionLink: { id, code }, }, } = await mutate({ mutation: createTransactionLink, @@ -599,6 +601,23 @@ describe('TransactionLinkResolver', () => { }, }) myCode = code + myId = id + }) + + it('stores the TRANSACTION_LINK_CREATE event in the database', async () => { + const userConatct = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'] }, + ) + await expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.TRANSACTION_LINK_CREATE, + affectedUserId: userConatct.user.id, + actingUserId: userConatct.user.id, + involvedTransactionLinkId: myId, + amount: expect.decimalEqual(200), + }), + ) }) describe('own link', () => { @@ -625,6 +644,94 @@ describe('TransactionLinkResolver', () => { expect.any(Number), ) }) + it('delete own link', async () => { + await expect( + mutate({ + mutation: deleteTransactionLink, + variables: { + id: myId, + }, + }), + ).resolves.toMatchObject({ + data: { deleteTransactionLink: true }, + }) + }) + + it('stores the TRANSACTION_LINK_DELETE event in the database', async () => { + const userConatct = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'] }, + ) + await expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.TRANSACTION_LINK_DELETE, + affectedUserId: userConatct.user.id, + actingUserId: userConatct.user.id, + involvedTransactionLinkId: myId, + }), + ) + }) + }) + + describe('other link', () => { + beforeAll(async () => { + await mutate({ + mutation: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + const { + data: { + createTransactionLink: { id, code }, + }, + } = await mutate({ + mutation: createTransactionLink, + variables: { + amount: 200, + memo: 'This is a transaction link from bibi', + }, + }) + myCode = code + myId = id + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + }) + + it('successfully redeems link', async () => { + await expect( + mutate({ + mutation: redeemTransactionLink, + variables: { + code: myCode, + }, + }), + ).resolves.toMatchObject({ + data: { redeemTransactionLink: true }, + errors: undefined, + }) + }) + + it('stores the TRANSACTION_LINK_REDEEM event in the database', async () => { + const creator = await UserContact.findOneOrFail( + { email: 'bibi@bloxberg.de' }, + { relations: ['user'] }, + ) + const redeemer = await UserContact.findOneOrFail( + { email: 'peter@lustig.de' }, + { relations: ['user'] }, + ) + await expect(DbEvent.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventType.TRANSACTION_LINK_REDEEM, + affectedUserId: redeemer.user.id, + actingUserId: redeemer.user.id, + involvedUserId: creator.user.id, + involvedTransactionLinkId: myId, + amount: expect.decimalEqual(200), + }), + ) + }) }) }) })