mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into contribution-resolver-logs-and-events
This commit is contained in:
commit
49ea82783d
@ -73,8 +73,8 @@ describe('TransactionLinkResolver', () => {
|
|||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
code: expect.stringMatching(/^[0-9a-f]{24,24}$/),
|
code: expect.stringMatching(/^[0-9a-f]{24,24}$/),
|
||||||
linkEnabled: true,
|
linkEnabled: true,
|
||||||
// amount: '200',
|
amount: expect.decimalEqual(5),
|
||||||
// maxAmountPerMonth: '200',
|
maxAmountPerMonth: expect.decimalEqual(200),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -111,6 +111,56 @@ describe('TransactionLinkResolver', () => {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('after one day', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
jest.useFakeTimers()
|
||||||
|
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
|
||||||
|
setTimeout(() => {}, 1000 * 60 * 60 * 24)
|
||||||
|
jest.runAllTimers()
|
||||||
|
await mutate({
|
||||||
|
mutation: login,
|
||||||
|
variables: { email: 'peter@lustig.de', password: 'Aa12345_' },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
jest.useRealTimers()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('allows the user to redeem the contribution link again', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({
|
||||||
|
mutation: redeemTransactionLink,
|
||||||
|
variables: {
|
||||||
|
code: 'CL-' + (contributionLink ? contributionLink.code : ''),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
redeemTransactionLink: true,
|
||||||
|
},
|
||||||
|
errors: undefined,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not allow the user to redeem the contribution link a second time on the same day', async () => {
|
||||||
|
await expect(
|
||||||
|
mutate({
|
||||||
|
mutation: redeemTransactionLink,
|
||||||
|
variables: {
|
||||||
|
code: 'CL-' + (contributionLink ? contributionLink.code : ''),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
errors: [
|
||||||
|
new GraphQLError(
|
||||||
|
'Creation from contribution link was not successful. Error: Contribution link already redeemed today',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { backendLogger as logger } from '@/server/logger'
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
import { Context, getUser } from '@/server/context'
|
import { Context, getUser } from '@/server/context'
|
||||||
import { getConnection, Between } from '@dbTools/typeorm'
|
import { getConnection } from '@dbTools/typeorm'
|
||||||
import {
|
import {
|
||||||
Resolver,
|
Resolver,
|
||||||
Args,
|
Args,
|
||||||
@ -235,11 +235,16 @@ export class TransactionLinkResolver {
|
|||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.select('contribution')
|
.select('contribution')
|
||||||
.from(DbContribution, 'contribution')
|
.from(DbContribution, 'contribution')
|
||||||
.where('contribution.contributionLinkId = :linkId AND contribution.userId = :id', {
|
.where(
|
||||||
linkId: contributionLink.id,
|
`contribution.contributionLinkId = :linkId AND contribution.userId = :id
|
||||||
id: user.id,
|
AND Date(contribution.confirmedAt) BETWEEN :start AND :end`,
|
||||||
contributionDate: Between(start, end),
|
{
|
||||||
})
|
linkId: contributionLink.id,
|
||||||
|
id: user.id,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
)
|
||||||
.getOne()
|
.getOne()
|
||||||
if (alreadyRedeemed) {
|
if (alreadyRedeemed) {
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user