mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
Tests for createContributionLink
This commit is contained in:
parent
66a526e69c
commit
ccb69b2631
@ -1,2 +1 @@
|
||||
;5'mÄë?š<EFBFBD>Övª©7y"Õ <EFBFBD>,8<EFBFBD>ÌE•Y>Ñ'SèÒ:”Æ‚“ØR‰²øêÖ’¥eÇÚl#2
|
||||
+s7ø!`!™ËX8|Z¦uÉ(ÐÓ´ªïAßM“™xÀà
|
||||
° &tƒfGN¼K=xnOç$WZ;β-ZÄŠ¾ıS¶Ì¿£d&×ͺ1œg³tÍıÏ2»k•‰Üç-IrY<EFBFBD>C}¸#.啯؛Òÿï»Í?g¼îŞíƒ(ˆÙB
|
||||
@ -13,8 +13,25 @@
|
||||
"url": "jdbc:mariadb://localhost:3306/",
|
||||
"home": "mysql_client",
|
||||
"type": "dev",
|
||||
"auth-model": "native",
|
||||
"handlers": {}
|
||||
"auth-model": "native"
|
||||
},
|
||||
"custom-properties": {
|
||||
"resultset.binary.representation": "base64"
|
||||
}
|
||||
}
|
||||
},
|
||||
"virtual-models": {
|
||||
"mariaDB-1815e3cb8a7-3b4d7a27c954779d": {
|
||||
"gradido_community": {
|
||||
":users": {
|
||||
"attributes": {
|
||||
"public_key": {
|
||||
"transforms": {
|
||||
"custom": "resultset.binary.representation"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -14,7 +14,7 @@ const constants = {
|
||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
|
||||
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
|
||||
CONFIG_VERSION: {
|
||||
DEFAULT: 'DEFAULT',
|
||||
EXPECTED: 'v6.2022-04-21',
|
||||
|
||||
@ -20,6 +20,7 @@ import {
|
||||
updatePendingCreation,
|
||||
deletePendingCreation,
|
||||
confirmPendingCreation,
|
||||
createContributionLink,
|
||||
} from '@/seeds/graphql/mutations'
|
||||
import {
|
||||
getPendingCreations,
|
||||
@ -34,6 +35,8 @@ import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { AdminPendingCreation } from '@entity/AdminPendingCreation'
|
||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||
// import { contributionFactory } from '@/seeds/factory/contribution'
|
||||
// import CONFIG from '@/config'
|
||||
|
||||
// mock account activation email to avoid console spam
|
||||
jest.mock('@/mailer/sendAccountActivationEmail', () => {
|
||||
@ -496,6 +499,17 @@ describe('AdminResolver', () => {
|
||||
creationDate: 'not-valid',
|
||||
}
|
||||
|
||||
const contributionLinkVariables = {
|
||||
startDate: '18.06.2022',
|
||||
endDate: '30.09.2022',
|
||||
name: 'Dokumenta 2022',
|
||||
amount: '100,00',
|
||||
memo: 'Startguthaben Dokumenta',
|
||||
cycle: 'ONCE',
|
||||
repetition: '1',
|
||||
maxAmount: '500,00',
|
||||
}
|
||||
|
||||
describe('unauthenticated', () => {
|
||||
describe('createPendingCreation', () => {
|
||||
it('returns an error', async () => {
|
||||
@ -1330,179 +1344,51 @@ describe('AdminResolver', () => {
|
||||
})
|
||||
// Tests for creating ContributionLinks
|
||||
describe('createContributionLink', () => {
|
||||
/*
|
||||
beforeAll(async () => {
|
||||
const now = new Date()
|
||||
creation = await creationFactory(testEnv, {
|
||||
startDate: new Date(2022, 6, 18).toISOString(),
|
||||
endDate,
|
||||
name,
|
||||
amount,
|
||||
memo,
|
||||
cycle,
|
||||
repetition,
|
||||
maxAmount,
|
||||
|
||||
email: 'peter@lustig.de',
|
||||
amount: 400,
|
||||
memo: 'Herzlich Willkommen bei Gradido!',
|
||||
creationDate: new Date(now.getFullYear(), now.getMonth() - 1, 1).toISOString(),
|
||||
const contributionLink = await contributionFactory(testEnv, {
|
||||
startDate: '18.06.2022',
|
||||
endDate: '30.09.2022',
|
||||
name: 'Dokumenta 2022',
|
||||
amount: '100.00',
|
||||
memo: 'Startguthaben Dokumenta',
|
||||
cycle: 'once',
|
||||
repetition: '1',
|
||||
maxAmount: '500.00',
|
||||
})
|
||||
})
|
||||
|
||||
describe('user to create for does not exist', () => {
|
||||
it('throws an error', async () => {
|
||||
await expect(
|
||||
mutate({ mutation: createContributionLink, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [new GraphQLError('Could not find user with email: bibi@bloxberg.de')],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('user to create for is deleted', () => {
|
||||
beforeAll(async () => {
|
||||
user = await userFactory(testEnv, stephenHawking)
|
||||
variables.email = 'stephen@hawking.uk'
|
||||
})
|
||||
|
||||
it('throws an error', async () => {
|
||||
await expect(mutate({ mutation: createPendingCreation, variables })).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [new GraphQLError('This user was deleted. Cannot make a creation.')],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('user to create for has email not confirmed', () => {
|
||||
beforeAll(async () => {
|
||||
user = await userFactory(testEnv, garrickOllivander)
|
||||
variables.email = 'garrick@ollivander.com'
|
||||
})
|
||||
|
||||
it('throws an error', async () => {
|
||||
await expect(mutate({ mutation: createPendingCreation, variables })).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [new GraphQLError('Creation could not be saved, Email is not activated')],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('valid user to create for', () => {
|
||||
beforeAll(async () => {
|
||||
user = await userFactory(testEnv, bibiBloxberg)
|
||||
variables.email = 'bibi@bloxberg.de'
|
||||
})
|
||||
|
||||
describe('date of creation is not a date string', () => {
|
||||
it('throws an error', async () => {
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
new GraphQLError('No information for available creations for the given date'),
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('date of creation is four months ago', () => {
|
||||
it('throws an error', async () => {
|
||||
const now = new Date()
|
||||
variables.creationDate = new Date(
|
||||
now.getFullYear(),
|
||||
now.getMonth() - 4,
|
||||
1,
|
||||
).toString()
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
new GraphQLError('No information for available creations for the given date'),
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('date of creation is in the future', () => {
|
||||
it('throws an error', async () => {
|
||||
const now = new Date()
|
||||
variables.creationDate = new Date(
|
||||
now.getFullYear(),
|
||||
now.getMonth() + 4,
|
||||
1,
|
||||
).toString()
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
new GraphQLError('No information for available creations for the given date'),
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('amount of creation is too high', () => {
|
||||
it('throws an error', async () => {
|
||||
variables.creationDate = new Date().toString()
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
new GraphQLError(
|
||||
'The amount (2000 GDD) to be created exceeds the amount (1000 GDD) still available for this month.',
|
||||
),
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('creation is valid', () => {
|
||||
it('returns an array of the open creations for the last three months', async () => {
|
||||
variables.amount = new Decimal(200)
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
createPendingCreation: [1000, 1000, 800],
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('second creation surpasses the available amount ', () => {
|
||||
it('returns an array of the open creations for the last three months', async () => {
|
||||
variables.amount = new Decimal(1000)
|
||||
await expect(
|
||||
mutate({ mutation: createPendingCreation, variables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
errors: [
|
||||
new GraphQLError(
|
||||
'The amount (1000 GDD) to be created exceeds the amount (800 GDD) still available for this month.',
|
||||
),
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
*/
|
||||
it('throws an error', async () => {
|
||||
await expect(
|
||||
mutate({ mutation: createContributionLink, contributionLinkVariables }),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
ContributionLink: {
|
||||
amount: '100.00',
|
||||
code: expect.any(String),
|
||||
createdAt: expect.any(Date),
|
||||
cycle: 'once',
|
||||
deletedAt: null,
|
||||
endDate: expect.any(Date),
|
||||
id: expect.any(Number),
|
||||
linkEnabled: true,
|
||||
link: expect.stringMatching('http://localhost/redeem/CL-'),
|
||||
maxAccountBalance: null,
|
||||
maxAmountPerMonth: null,
|
||||
memo: 'Startguthaben Dokumenta',
|
||||
minGapHours: null,
|
||||
name: 'Dokumenta 2022',
|
||||
repetition: 1,
|
||||
startDate: expect.any(Date),
|
||||
totalMaxCountOfContribution: null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -487,7 +487,7 @@ export class AdminResolver {
|
||||
}: CreateContributionLinkArgs,
|
||||
@Ctx() context: Context,
|
||||
): Promise<ContributionLink> {
|
||||
logger.trace(
|
||||
logger.debug(
|
||||
`createContributionLink(startDate=${startDate}, endDate=${endDate}, name=${name}, amount=${amount}, memo=${memo}, cycle=${cycle}, repetition=${repetition}, maxAmount=${maxAmount})`,
|
||||
)
|
||||
if (!isStartEndDateValid(startDate, endDate)) {
|
||||
@ -523,12 +523,12 @@ export class AdminResolver {
|
||||
contributionLink.code = contributionLinkCode(startDateObj)
|
||||
contributionLink.createdAt = new Date()
|
||||
contributionLink.cycle = cycle // ? cycle : ContributionCycleType.NONE
|
||||
contributionLink.deletedAt = null
|
||||
// contributionLink.deletedAt = null
|
||||
contributionLink.linkEnabled = true
|
||||
/* not supported in the 1st expansion stage
|
||||
contributionLink.maxAccountBalance = null
|
||||
*/
|
||||
contributionLink.maxAmountPerMonth = null // maxAmount
|
||||
// contributionLink.maxAmountPerMonth = null // maxAmount
|
||||
contributionLink.maxPerCycle = Number(repetition)
|
||||
contributionLink.memo = memo
|
||||
/* not supported in the 1st expansion stage
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user