mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2900 from gradido/event-tests-for-transactionLinks
refactor(backend): missing event tests
This commit is contained in:
commit
fee1a49295
@ -22,6 +22,7 @@ import {
|
|||||||
createContribution,
|
createContribution,
|
||||||
updateContribution,
|
updateContribution,
|
||||||
createTransactionLink,
|
createTransactionLink,
|
||||||
|
deleteTransactionLink,
|
||||||
confirmContribution,
|
confirmContribution,
|
||||||
} from '@/seeds/graphql/mutations'
|
} from '@/seeds/graphql/mutations'
|
||||||
import { listTransactionLinksAdmin } from '@/seeds/graphql/queries'
|
import { listTransactionLinksAdmin } from '@/seeds/graphql/queries'
|
||||||
@ -573,6 +574,7 @@ describe('TransactionLinkResolver', () => {
|
|||||||
|
|
||||||
describe('link exists', () => {
|
describe('link exists', () => {
|
||||||
let myCode: string
|
let myCode: string
|
||||||
|
let myId: number
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await mutate({
|
await mutate({
|
||||||
@ -589,7 +591,7 @@ describe('TransactionLinkResolver', () => {
|
|||||||
})
|
})
|
||||||
const {
|
const {
|
||||||
data: {
|
data: {
|
||||||
createTransactionLink: { code },
|
createTransactionLink: { id, code },
|
||||||
},
|
},
|
||||||
} = await mutate({
|
} = await mutate({
|
||||||
mutation: createTransactionLink,
|
mutation: createTransactionLink,
|
||||||
@ -599,6 +601,23 @@ describe('TransactionLinkResolver', () => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
myCode = code
|
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', () => {
|
describe('own link', () => {
|
||||||
@ -625,6 +644,94 @@ describe('TransactionLinkResolver', () => {
|
|||||||
expect.any(Number),
|
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),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user