From ccb69b2631ce955286bd1068cb43cee28308f89b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 14 Jun 2022 00:37:11 +0200 Subject: [PATCH] Tests for createContributionLink --- .dbeaver/credentials-config.json | 3 +- .dbeaver/data-sources.json | 21 +- backend/src/config/index.ts | 2 +- .../graphql/resolver/AdminResolver.test.ts | 220 +++++------------- backend/src/graphql/resolver/AdminResolver.ts | 6 +- 5 files changed, 77 insertions(+), 175 deletions(-) diff --git a/.dbeaver/credentials-config.json b/.dbeaver/credentials-config.json index f56152022..492e05f38 100644 --- a/.dbeaver/credentials-config.json +++ b/.dbeaver/credentials-config.json @@ -1,2 +1 @@ -;5'm?v7y " ,8EY>'S:ƂR֒el#2 -+s7!`!X8|Zu(ӴAMx \ No newline at end of file +&tfGNK=xnO$WZ;β-ZĊS̿d&ͺ1gt2 k-IrYC}#.؛?g(B \ No newline at end of file diff --git a/.dbeaver/data-sources.json b/.dbeaver/data-sources.json index fe96e923d..7e9676d89 100644 --- a/.dbeaver/data-sources.json +++ b/.dbeaver/data-sources.json @@ -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" + } + } + } + } } } }, diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index e325c6690..b4351599d 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -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', diff --git a/backend/src/graphql/resolver/AdminResolver.test.ts b/backend/src/graphql/resolver/AdminResolver.test.ts index a2c4c3b82..fbfbfb65f 100644 --- a/backend/src/graphql/resolver/AdminResolver.test.ts +++ b/backend/src/graphql/resolver/AdminResolver.test.ts @@ -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, + }, + }, + }), + ) }) }) - - }) }) }) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 829b9a705..1f9ecbaa6 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -487,7 +487,7 @@ export class AdminResolver { }: CreateContributionLinkArgs, @Ctx() context: Context, ): Promise { - 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