Merge branch 'master' into import-no-cycle-refactor-events

This commit is contained in:
Ulf Gebhardt 2023-03-30 14:20:49 +02:00 committed by GitHub
commit d3290646bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,6 +29,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),
}),
)
})
})
})
})