From 08d8c008f6bd66c3c726785ba13e8125b9973638 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 31 Jan 2023 13:07:41 +0100 Subject: [PATCH 01/22] Add denyContribution mutation to the seeds. --- backend/src/seeds/graphql/mutations.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index 2b4ed6656..8c3f97f17 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -266,6 +266,12 @@ export const deleteContribution = gql` } ` +export const denyContribution = gql` + mutation ($id: Int!) { + denyContribution(id: $id) + } +` + export const createContributionMessage = gql` mutation ($contributionId: Float!, $message: String!) { createContributionMessage(contributionId: $contributionId, message: $message) { From f3f749889f08aa148b4105f465b83e417c199e3e Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 31 Jan 2023 13:24:59 +0100 Subject: [PATCH 02/22] Add Test for denyContribution. --- .../resolver/ContributionResolver.test.ts | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index abae8e446..f17851fd8 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -10,6 +10,7 @@ import { createContribution, updateContribution, deleteContribution, + denyContribution, confirmContribution, adminCreateContribution, adminCreateContributions, @@ -671,6 +672,123 @@ describe('ContributionResolver', () => { }) }) + describe('denyContribution', () => { + describe('unauthenticated', () => { + it('returns an error', async () => { + await expect( + mutate({ + mutation: denyContribution, + variables: { + id: 1, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + + describe('authenticated', () => { + beforeAll(async () => { + await userFactory(testEnv, peterLustig) + await userFactory(testEnv, bibiBloxberg) + await mutate({ + mutation: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + result = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test env contribution', + creationDate: new Date().toString(), + }, + }) + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + }) + + afterAll(async () => { + await cleanDB() + resetToken() + }) + + describe('wrong contribution id', () => { + it('throws an error', async () => { + jest.clearAllMocks() + await expect( + mutate({ + mutation: denyContribution, + variables: { + id: -1, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Contribution not found for given id.')], + }), + ) + }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('Contribution not found for given id: -1') + }) + }) + + describe('wrong user tries to deny the contribution', () => { + beforeAll(async () => { + await mutate({ + mutation: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + }) + + it('throws an error', async () => { + jest.clearAllMocks() + await expect( + mutate({ + mutation: denyContribution, + variables: { + id: result.data.createContribution.id, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + + describe('valid input', () => { + it('deny contribution', async () => { + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + await expect( + mutate({ + mutation: denyContribution, + variables: { + id: result.data.createContribution.id, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + denyContribution: true, + }, + }), + ) + }) + }) + }) + }) + describe('listAllContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { From 4f0cfb9363a908ffba815639f4ad4d4f5b11c4a9 Mon Sep 17 00:00:00 2001 From: elweyn Date: Fri, 3 Feb 2023 13:55:08 +0100 Subject: [PATCH 03/22] Change structure of tests so that we create every data needed beforeAll unit tests. --- .../resolver/ContributionResolver.test.ts | 1166 ++++++++++------- 1 file changed, 688 insertions(+), 478 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 9c917368b..226ab63cd 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -17,6 +17,8 @@ import { adminUpdateContribution, adminDeleteContribution, login, + logout, + adminCreateContributionMessage, } from '@/seeds/graphql/mutations' import { listAllContributions, @@ -69,7 +71,13 @@ let mutate: any, query: any, con: any let testEnv: any let creation: Contribution | void let admin: User -let result: any +// let result: any +// let contribution: any +let pendingContribution: any +let inProgressContribution: any +let contributionToConfirm: any +let contributionToDeny: any +let contributionToDelete: any beforeAll(async () => { testEnv = await testEnvironment(logger, localization) @@ -86,6 +94,75 @@ afterAll(async () => { describe('ContributionResolver', () => { let bibi: any + let peter: any + + beforeAll(async () => { + bibi = await userFactory(testEnv, bibiBloxberg) + admin = peter = await userFactory(testEnv, peterLustig) + const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + await creationFactory(testEnv, bibisCreation!) + await mutate({ + mutation: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + pendingContribution = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test PENDING contribution', + creationDate: new Date().toString(), + }, + }) + inProgressContribution = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test IN_PROGESS contribution', + creationDate: new Date().toString(), + }, + }) + await mutate({ + mutation: adminCreateContributionMessage, + variables: { + contributionId: inProgressContribution.data.createContribution.id, + message: 'Test message to IN_PROGESS contribution', + }, + }) + contributionToConfirm = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test contribution to confirm', + creationDate: new Date().toString(), + }, + }) + contributionToDeny = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test contribution to deny', + creationDate: new Date().toString(), + }, + }) + contributionToDelete = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test contribution to delete', + creationDate: new Date().toString(), + }, + }) + await mutate({ + mutation: logout, + }) + resetToken() + }) + + afterAll(async () => { + await cleanDB() + resetToken() + }) describe('createContribution', () => { describe('unauthenticated', () => { @@ -105,8 +182,6 @@ describe('ContributionResolver', () => { describe('authenticated with valid user', () => { beforeAll(async () => { - await userFactory(testEnv, bibiBloxberg) - bibi = await mutate({ mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, @@ -114,7 +189,6 @@ describe('ContributionResolver', () => { }) afterAll(async () => { - await cleanDB() resetToken() }) @@ -222,27 +296,14 @@ describe('ContributionResolver', () => { }) describe('valid input', () => { - let contribution: any - - beforeAll(async () => { - contribution = await mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }) - }) - it('creates contribution', async () => { - expect(contribution).toEqual( + expect(pendingContribution).toEqual( expect.objectContaining({ data: { createContribution: { id: expect.any(Number), amount: '100', - memo: 'Test env contribution', + memo: 'Test PENDING contribution', }, }, }), @@ -254,7 +315,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_CREATE, amount: expect.decimalEqual(100), - contributionId: contribution.data.createContribution.id, + contributionId: pendingContribution.data.createContribution.id, userId: bibi.data.login.id, }), ) @@ -263,122 +324,6 @@ describe('ContributionResolver', () => { }) }) - describe('listContributions', () => { - describe('unauthenticated', () => { - it('returns an error', async () => { - await expect( - query({ - query: listContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - filterConfirmed: false, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) - }) - }) - - describe('authenticated', () => { - beforeAll(async () => { - await userFactory(testEnv, bibiBloxberg) - await userFactory(testEnv, peterLustig) - const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - await creationFactory(testEnv, bibisCreation!) - await mutate({ - mutation: login, - variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, - }) - await mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }) - }) - - afterAll(async () => { - await cleanDB() - resetToken() - }) - - describe('filter confirmed is false', () => { - it('returns creations', async () => { - await expect( - query({ - query: listContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - filterConfirmed: false, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listContributions: { - contributionCount: 2, - contributionList: expect.arrayContaining([ - expect.objectContaining({ - id: expect.any(Number), - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test env contribution', - amount: '100', - }), - ]), - }, - }, - }), - ) - }) - }) - - describe('filter confirmed is true', () => { - it('returns only unconfirmed creations', async () => { - await expect( - query({ - query: listContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - filterConfirmed: true, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listContributions: { - contributionCount: 1, - contributionList: expect.arrayContaining([ - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test env contribution', - amount: '100', - }), - ]), - }, - }, - }), - ) - }) - }) - }) - }) - describe('updateContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { @@ -402,24 +347,13 @@ describe('ContributionResolver', () => { describe('authenticated', () => { beforeAll(async () => { - await userFactory(testEnv, peterLustig) - await userFactory(testEnv, bibiBloxberg) await mutate({ mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) - result = await mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }) }) afterAll(async () => { - await cleanDB() resetToken() }) @@ -456,7 +390,7 @@ describe('ContributionResolver', () => { mutate({ mutation: updateContribution, variables: { - contributionId: result.data.createContribution.id, + contributionId: pendingContribution.data.createContribution.id, amount: 100.0, memo: 'Test', creationDate: date.toString(), @@ -482,7 +416,7 @@ describe('ContributionResolver', () => { mutate({ mutation: updateContribution, variables: { - contributionId: result.data.createContribution.id, + contributionId: pendingContribution.data.createContribution.id, amount: 100.0, memo: 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test', creationDate: date.toString(), @@ -514,7 +448,7 @@ describe('ContributionResolver', () => { mutate({ mutation: updateContribution, variables: { - contributionId: result.data.createContribution.id, + contributionId: pendingContribution.data.createContribution.id, amount: 10.0, memo: 'Test env contribution', creationDate: new Date().toString(), @@ -539,13 +473,20 @@ describe('ContributionResolver', () => { }) describe('admin tries to update a user contribution', () => { + beforeAll(async () => { + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + }) + it('throws an error', async () => { jest.clearAllMocks() await expect( mutate({ mutation: adminUpdateContribution, variables: { - id: result.data.createContribution.id, + id: pendingContribution.data.createContribution.id, email: 'bibi@bloxberg.de', amount: 10.0, memo: 'Test env contribution', @@ -562,7 +503,7 @@ describe('ContributionResolver', () => { // TODO check that the error is logged (need to modify AdminResolver, avoid conflicts) }) - describe('update too much so that the limit is exceeded', () => { + describe('update to much so that the limit is exceeded', () => { beforeAll(async () => { await mutate({ mutation: login, @@ -576,7 +517,7 @@ describe('ContributionResolver', () => { mutate({ mutation: updateContribution, variables: { - contributionId: result.data.createContribution.id, + contributionId: pendingContribution.data.createContribution.id, amount: 1019.0, memo: 'Test env contribution', creationDate: new Date().toString(), @@ -586,7 +527,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (1019 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', + 'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.', ), ], }), @@ -595,7 +536,7 @@ describe('ContributionResolver', () => { it('logs the error found', () => { expect(logger.error).toBeCalledWith( - 'The amount (1019 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', + 'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.', ) }) }) @@ -608,7 +549,7 @@ describe('ContributionResolver', () => { mutate({ mutation: updateContribution, variables: { - contributionId: result.data.createContribution.id, + contributionId: pendingContribution.data.createContribution.id, amount: 10.0, memo: 'Test env contribution', creationDate: date.setMonth(date.getMonth() - 3).toString(), @@ -635,9 +576,9 @@ describe('ContributionResolver', () => { mutate({ mutation: updateContribution, variables: { - contributionId: result.data.createContribution.id, + contributionId: pendingContribution.data.createContribution.id, amount: 10.0, - memo: 'Test contribution', + memo: 'Test PENDING contribution update', creationDate: new Date().toString(), }, }), @@ -645,9 +586,9 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { updateContribution: { - id: result.data.createContribution.id, + id: pendingContribution.data.createContribution.id, amount: '10', - memo: 'Test contribution', + memo: 'Test PENDING contribution update', }, }, }), @@ -664,7 +605,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_UPDATE, amount: expect.decimalEqual(10), - contributionId: result.data.createContribution.id, + contributionId: pendingContribution.data.createContribution.id, userId: bibi.data.login.id, }), ) @@ -691,22 +632,36 @@ describe('ContributionResolver', () => { }) }) - describe('authenticated', () => { + describe('authenticated without admin rights', () => { beforeAll(async () => { - await userFactory(testEnv, peterLustig) - await userFactory(testEnv, bibiBloxberg) await mutate({ mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) - result = await mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }) + }) + + afterAll(() => { + resetToken() + }) + + it('returns an error', async () => { + await expect( + mutate({ + mutation: denyContribution, + variables: { + id: 1, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + + describe('authenticated with admin rights', () => { + beforeAll(async () => { await mutate({ mutation: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, @@ -714,13 +669,11 @@ describe('ContributionResolver', () => { }) afterAll(async () => { - await cleanDB() resetToken() }) describe('wrong contribution id', () => { it('throws an error', async () => { - jest.clearAllMocks() await expect( mutate({ mutation: denyContribution, @@ -740,31 +693,6 @@ describe('ContributionResolver', () => { }) }) - describe('wrong user tries to deny the contribution', () => { - beforeAll(async () => { - await mutate({ - mutation: login, - variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, - }) - }) - - it('throws an error', async () => { - jest.clearAllMocks() - await expect( - mutate({ - mutation: denyContribution, - variables: { - id: result.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) - }) - }) - describe('valid input', () => { it('deny contribution', async () => { await mutate({ @@ -775,7 +703,7 @@ describe('ContributionResolver', () => { mutate({ mutation: denyContribution, variables: { - id: result.data.createContribution.id, + id: contributionToDeny.data.createContribution.id, }, }), ).resolves.toEqual( @@ -790,6 +718,282 @@ describe('ContributionResolver', () => { }) }) + describe('deleteContribution', () => { + describe('unauthenticated', () => { + it('returns an error', async () => { + await expect( + query({ + query: deleteContribution, + variables: { + id: -1, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + + describe('authenticated', () => { + beforeAll(async () => { + bibi = await mutate({ + mutation: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + }) + + afterAll(async () => { + resetToken() + }) + + describe('wrong contribution id', () => { + it('returns an error', async () => { + await expect( + mutate({ + mutation: deleteContribution, + variables: { + id: -1, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Contribution not found for given id.')], + }), + ) + }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('Contribution not found for given id') + }) + }) + + describe('other user sends a deleteContribution', () => { + it('returns an error', async () => { + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + await expect( + mutate({ + mutation: deleteContribution, + variables: { + id: contributionToDelete.data.createContribution.id, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Can not delete contribution of another user')], + }), + ) + }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('Can not delete contribution of another user') + }) + }) + + describe('User deletes own contribution', () => { + it('deletes successfully', async () => { + await expect( + mutate({ + mutation: deleteContribution, + variables: { + id: contributionToDelete.data.createContribution.id, + }, + }), + ).resolves.toBeTruthy() + }) + + it('stores the delete contribution event in the database', async () => { + const contribution = await mutate({ + mutation: createContribution, + variables: { + amount: 166.0, + memo: 'Whatever contribution', + creationDate: new Date().toString(), + }, + }) + + await mutate({ + mutation: deleteContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.CONTRIBUTION_DELETE, + contributionId: contribution.data.createContribution.id, + amount: expect.decimalEqual(166), + userId: peter.id, + }), + ) + }) + }) + + describe('User deletes already confirmed contribution', () => { + it('throws an error', async () => { + jest.clearAllMocks() + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + await mutate({ + mutation: confirmContribution, + variables: { + id: contributionToConfirm.data.createContribution.id, + }, + }) + await mutate({ + mutation: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + await expect( + mutate({ + mutation: deleteContribution, + variables: { + id: contributionToConfirm.data.createContribution.id, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('A confirmed contribution can not be deleted')], + }), + ) + }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith('A confirmed contribution can not be deleted') + }) + }) + }) + }) + + describe('listContributions', () => { + describe('unauthenticated', () => { + it('returns an error', async () => { + await expect( + query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: false, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('401 Unauthorized')], + }), + ) + }) + }) + + describe('authenticated', () => { + beforeAll(async () => { + await mutate({ + mutation: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + }) + + afterAll(async () => { + resetToken() + }) + + describe('filter confirmed is false', () => { + it('returns creations', async () => { + await expect( + query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: false, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + listContributions: { + contributionCount: 6, + contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test contribution to deny', + amount: '100', + }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + ]), + }, + }, + }), + ) + }) + }) + + describe('filter confirmed is true', () => { + it('returns only unconfirmed creations', async () => { + await expect( + query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: true, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + data: { + listContributions: { + contributionCount: 4, + contributionList: expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test contribution to delete', + amount: '100', + }), + ]), + }, + }, + }), + ) + }) + }) + }) + }) + describe('listAllContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { @@ -813,27 +1017,13 @@ describe('ContributionResolver', () => { describe('authenticated', () => { beforeAll(async () => { - await userFactory(testEnv, bibiBloxberg) - await userFactory(testEnv, peterLustig) - const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - await creationFactory(testEnv, bibisCreation!) await mutate({ mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) - await mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }) }) afterAll(async () => { - await cleanDB() resetToken() }) @@ -920,20 +1110,44 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 2, + contributionCount: 6, contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'IN_PROGRESS', + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), expect.objectContaining({ id: expect.any(Number), state: 'CONFIRMED', memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test env contribution', - amount: '100', - }), ]), }, }, @@ -956,20 +1170,44 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 2, + contributionCount: 6, contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'IN_PROGRESS', + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), expect.objectContaining({ id: expect.any(Number), state: 'CONFIRMED', memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test env contribution', - amount: '100', - }), ]), }, }, @@ -992,20 +1230,44 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 2, + contributionCount: 6, contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'IN_PROGRESS', + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), expect.objectContaining({ id: expect.any(Number), state: 'CONFIRMED', memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test env contribution', - amount: '100', - }), ]), }, }, @@ -1028,20 +1290,44 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 1, + contributionCount: 2, contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'IN_PROGRESS', + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), expect.objectContaining({ id: expect.any(Number), state: 'CONFIRMED', memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test env contribution', - amount: '100', - }), ]), }, }, @@ -1067,17 +1353,41 @@ describe('ContributionResolver', () => { contributionCount: 1, contributionList: expect.arrayContaining([ expect.not.objectContaining({ - id: expect.any(Number), + amount: '100', state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', + id: expect.any(Number), + memo: 'Test contribution to confirm', }), expect.objectContaining({ id: expect.any(Number), state: 'PENDING', - memo: 'Test env contribution', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Test contribution to deny', amount: '100', }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'IN_PROGRESS', + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), ]), }, }, @@ -1100,20 +1410,44 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 0, - contributionList: expect.not.arrayContaining([ + contributionCount: 1, + contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), expect.objectContaining({ + id: expect.any(Number), + state: 'IN_PROGRESS', + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), + expect.not.objectContaining({ id: expect.any(Number), state: 'CONFIRMED', memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test env contribution', - amount: '100', - }), ]), }, }, @@ -1136,20 +1470,44 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 0, - contributionList: expect.not.arrayContaining([ + contributionCount: 1, + contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'IN_PROGRESS', + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), + expect.not.objectContaining({ id: expect.any(Number), state: 'CONFIRMED', memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test env contribution', - amount: '100', - }), ]), }, }, @@ -1173,20 +1531,7 @@ describe('ContributionResolver', () => { data: { listAllContributions: { contributionCount: 0, - contributionList: expect.not.arrayContaining([ - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test env contribution', - amount: '100', - }), - ]), + contributionList: [], }, }, }), @@ -1208,20 +1553,44 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 2, + contributionCount: 3, contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'IN_PROGRESS', + memo: 'Test IN_PROGESS contribution', + amount: '100', + }), expect.objectContaining({ id: expect.any(Number), state: 'CONFIRMED', memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test env contribution', - amount: '100', - }), ]), }, }, @@ -1231,173 +1600,6 @@ describe('ContributionResolver', () => { }) }) - describe('deleteContribution', () => { - describe('unauthenticated', () => { - it('returns an error', async () => { - await expect( - query({ - query: deleteContribution, - variables: { - id: -1, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) - }) - }) - - describe('authenticated', () => { - let peter: any - beforeAll(async () => { - await userFactory(testEnv, bibiBloxberg) - peter = await userFactory(testEnv, peterLustig) - - await mutate({ - mutation: login, - variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, - }) - result = await mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }) - }) - - afterAll(async () => { - await cleanDB() - resetToken() - }) - - describe('wrong contribution id', () => { - it('returns an error', async () => { - await expect( - mutate({ - mutation: deleteContribution, - variables: { - id: -1, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Contribution not found for given id.')], - }), - ) - }) - - it('logs the error found', () => { - expect(logger.error).toBeCalledWith('Contribution not found for given id') - }) - }) - - describe('other user sends a deleteContribution', () => { - it('returns an error', async () => { - await mutate({ - mutation: login, - variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, - }) - await expect( - mutate({ - mutation: deleteContribution, - variables: { - id: result.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Can not delete contribution of another user')], - }), - ) - }) - - it('logs the error found', () => { - expect(logger.error).toBeCalledWith('Can not delete contribution of another user') - }) - }) - - describe('User deletes own contribution', () => { - it('deletes successfully', async () => { - await expect( - mutate({ - mutation: deleteContribution, - variables: { - id: result.data.createContribution.id, - }, - }), - ).resolves.toBeTruthy() - }) - - it('stores the delete contribution event in the database', async () => { - const contribution = await mutate({ - mutation: createContribution, - variables: { - amount: 166.0, - memo: 'Whatever contribution', - creationDate: new Date().toString(), - }, - }) - - await mutate({ - mutation: deleteContribution, - variables: { - id: contribution.data.createContribution.id, - }, - }) - - await expect(EventProtocol.find()).resolves.toContainEqual( - expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_DELETE, - contributionId: contribution.data.createContribution.id, - amount: expect.decimalEqual(166), - userId: peter.id, - }), - ) - }) - }) - - describe('User deletes already confirmed contribution', () => { - it('throws an error', async () => { - jest.clearAllMocks() - await mutate({ - mutation: login, - variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, - }) - await mutate({ - mutation: confirmContribution, - variables: { - id: result.data.createContribution.id, - }, - }) - await mutate({ - mutation: login, - variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, - }) - await expect( - mutate({ - mutation: deleteContribution, - variables: { - id: result.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('A confirmed contribution can not be deleted')], - }), - ) - }) - - it('logs the error found', () => { - expect(logger.error).toBeCalledWith('A confirmed contribution can not be deleted') - }) - }) - }) - }) - describe('contributions', () => { const variables = { email: 'bibi@bloxberg.de', @@ -1505,7 +1707,6 @@ describe('ContributionResolver', () => { describe('authenticated', () => { describe('without admin rights', () => { beforeAll(async () => { - await userFactory(testEnv, bibiBloxberg) await mutate({ mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, @@ -1513,7 +1714,6 @@ describe('ContributionResolver', () => { }) afterAll(async () => { - await cleanDB() resetToken() }) @@ -1614,7 +1814,6 @@ describe('ContributionResolver', () => { describe('with admin rights', () => { beforeAll(async () => { - admin = await userFactory(testEnv, peterLustig) await mutate({ mutation: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, @@ -1622,7 +1821,6 @@ describe('ContributionResolver', () => { }) afterAll(async () => { - await cleanDB() resetToken() }) @@ -1644,6 +1842,7 @@ describe('ContributionResolver', () => { creation = await Contribution.findOneOrFail({ where: { memo: 'Herzlich Willkommen bei Gradido!', + amount: 400, }, }) }) @@ -1651,6 +1850,7 @@ describe('ContributionResolver', () => { describe('user to create for does not exist', () => { it('throws an error', async () => { jest.clearAllMocks() + variables.email = 'some@fake.email' variables.creationDate = contributionDateFormatter( new Date(now.getFullYear(), now.getMonth() - 1, 1), ) @@ -1658,15 +1858,13 @@ describe('ContributionResolver', () => { mutate({ mutation: adminCreateContribution, variables }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('Could not find user with email: bibi@bloxberg.de')], + errors: [new GraphQLError('Could not find user with email: some@fake.email')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith( - 'Could not find user with email: bibi@bloxberg.de', - ) + expect(logger.error).toBeCalledWith('Could not find user with email: some@fake.email') }) }) @@ -1730,7 +1928,6 @@ describe('ContributionResolver', () => { describe('valid user to create for', () => { beforeAll(async () => { - await userFactory(testEnv, bibiBloxberg) variables.email = 'bibi@bloxberg.de' variables.creationDate = 'invalid-date' }) @@ -1812,7 +2009,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (2000 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', + 'The amount (2000 GDD) to be created exceeds the amount (900 GDD) still available for this month.', ), ], }), @@ -1821,7 +2018,7 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'The amount (2000 GDD) to be created exceeds the amount (1000 GDD) still available for this month.', + 'The amount (2000 GDD) to be created exceeds the amount (900 GDD) still available for this month.', ) }) }) @@ -1834,7 +2031,7 @@ describe('ContributionResolver', () => { ).resolves.toEqual( expect.objectContaining({ data: { - adminCreateContribution: [1000, 1000, 800], + adminCreateContribution: [1000, 1000, 700], }, }), ) @@ -1859,7 +2056,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (1000 GDD) to be created exceeds the amount (800 GDD) still available for this month.', + 'The amount (1000 GDD) to be created exceeds the amount (700 GDD) still available for this month.', ), ], }), @@ -1868,7 +2065,7 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'The amount (1000 GDD) to be created exceeds the amount (800 GDD) still available for this month.', + 'The amount (1000 GDD) to be created exceeds the amount (700 GDD) still available for this month.', ) }) }) @@ -2013,6 +2210,7 @@ describe('ContributionResolver', () => { describe('user email does not match creation user', () => { it('throws an error', async () => { jest.clearAllMocks() + console.log('creation', creation) await expect( mutate({ mutation: adminUpdateContribution, @@ -2170,7 +2368,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listUnconfirmedContributions: expect.arrayContaining([ - { + expect.objectContaining({ id: expect.any(Number), firstName: 'Peter', lastName: 'Lustig', @@ -2179,9 +2377,9 @@ describe('ContributionResolver', () => { memo: 'Das war leider zu Viel!', amount: '200', moderator: admin.id, - creation: ['1000', '800', '500'], - }, - { + creation: ['1000', '600', '500'], + }), + expect.objectContaining({ id: expect.any(Number), firstName: 'Peter', lastName: 'Lustig', @@ -2190,9 +2388,20 @@ describe('ContributionResolver', () => { memo: 'Grundeinkommen', amount: '500', moderator: admin.id, - creation: ['1000', '800', '500'], - }, - { + creation: ['1000', '600', '500'], + }), + expect.objectContaining({ + id: expect.any(Number), + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + date: expect.any(String), + memo: 'Test contribution to delete', + amount: '100', + moderator: null, + creation: ['1000', '1000', '200'], + }), + expect.objectContaining({ id: expect.any(Number), firstName: 'Bibi', lastName: 'Bloxberg', @@ -2201,9 +2410,9 @@ describe('ContributionResolver', () => { memo: 'Grundeinkommen', amount: '500', moderator: admin.id, - creation: ['1000', '1000', '300'], - }, - { + creation: ['1000', '1000', '200'], + }), + expect.objectContaining({ id: expect.any(Number), firstName: 'Bibi', lastName: 'Bloxberg', @@ -2212,8 +2421,8 @@ describe('ContributionResolver', () => { memo: 'Aktives Grundeinkommen', amount: '200', moderator: admin.id, - creation: ['1000', '1000', '300'], - }, + creation: ['1000', '1000', '200'], + }), ]), }, }), @@ -2245,12 +2454,13 @@ describe('ContributionResolver', () => { }) describe('admin deletes own user contribution', () => { + let ownContribution: any beforeAll(async () => { await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, }) - result = await mutate({ + ownContribution = await mutate({ mutation: createContribution, variables: { amount: 100.0, @@ -2266,7 +2476,7 @@ describe('ContributionResolver', () => { mutate({ mutation: adminDeleteContribution, variables: { - id: result.data.createContribution.id, + id: ownContribution.data.createContribution.id, }, }), ).resolves.toEqual( From 0575c513c4f91d0bd200bac620b32edc8d514796 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 6 Feb 2023 08:01:29 +0100 Subject: [PATCH 04/22] End refactoring of ContributionResolver.test. --- .../resolver/ContributionResolver.test.ts | 147 ++++++++++++++---- 1 file changed, 113 insertions(+), 34 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 226ab63cd..a7b6716db 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -118,17 +118,10 @@ describe('ContributionResolver', () => { mutation: createContribution, variables: { amount: 100.0, - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', creationDate: new Date().toString(), }, }) - await mutate({ - mutation: adminCreateContributionMessage, - variables: { - contributionId: inProgressContribution.data.createContribution.id, - message: 'Test message to IN_PROGESS contribution', - }, - }) contributionToConfirm = await mutate({ mutation: createContribution, variables: { @@ -153,6 +146,17 @@ describe('ContributionResolver', () => { creationDate: new Date().toString(), }, }) + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + await mutate({ + mutation: adminCreateContributionMessage, + variables: { + contributionId: inProgressContribution.data.createContribution.id, + message: 'Test message to IN_PROGRESS contribution', + }, + }) await mutate({ mutation: logout, }) @@ -770,11 +774,18 @@ describe('ContributionResolver', () => { }) describe('other user sends a deleteContribution', () => { - it('returns an error', async () => { + beforeAll(async () => { await mutate({ mutation: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, }) + }) + + afterAll(() => { + resetToken() + }) + + it('returns an error', async () => { await expect( mutate({ mutation: deleteContribution, @@ -795,6 +806,17 @@ describe('ContributionResolver', () => { }) describe('User deletes own contribution', () => { + beforeAll(async () => { + await mutate({ + mutation: login, + variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, + }) + }) + + afterAll(() => { + resetToken() + }) + it('deletes successfully', async () => { await expect( mutate({ @@ -803,10 +825,21 @@ describe('ContributionResolver', () => { id: contributionToDelete.data.createContribution.id, }, }), - ).resolves.toBeTruthy() + ).resolves.toEqual( + expect.objectContaining({ + data: { + deleteContribution: true, + }, + }), + ) }) it('stores the delete contribution event in the database', async () => { + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + const contribution = await mutate({ mutation: createContribution, variables: { @@ -945,7 +978,7 @@ describe('ContributionResolver', () => { }), expect.objectContaining({ id: expect.any(Number), - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.objectContaining({ @@ -979,11 +1012,36 @@ describe('ContributionResolver', () => { listContributions: { contributionCount: 4, contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + amount: '100', + id: expect.any(Number), + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test contribution to deny', + amount: '100', + }), expect.objectContaining({ id: expect.any(Number), memo: 'Test contribution to delete', amount: '100', }), + expect.objectContaining({ + id: expect.any(Number), + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.not.objectContaining({ + id: expect.any(Number), + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), ]), }, }, @@ -1110,7 +1168,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 6, + contributionCount: 5, contributionList: expect.arrayContaining([ expect.objectContaining({ amount: '100', @@ -1139,7 +1197,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ id: expect.any(Number), state: 'IN_PROGRESS', - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.objectContaining({ @@ -1170,7 +1228,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 6, + contributionCount: 5, contributionList: expect.arrayContaining([ expect.objectContaining({ amount: '100', @@ -1199,7 +1257,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ id: expect.any(Number), state: 'IN_PROGRESS', - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.objectContaining({ @@ -1230,7 +1288,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 6, + contributionCount: 5, contributionList: expect.arrayContaining([ expect.objectContaining({ amount: '100', @@ -1259,7 +1317,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ id: expect.any(Number), state: 'IN_PROGRESS', - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.objectContaining({ @@ -1319,7 +1377,7 @@ describe('ContributionResolver', () => { expect.not.objectContaining({ id: expect.any(Number), state: 'IN_PROGRESS', - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.objectContaining({ @@ -1379,7 +1437,7 @@ describe('ContributionResolver', () => { expect.not.objectContaining({ id: expect.any(Number), state: 'IN_PROGRESS', - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.not.objectContaining({ @@ -1439,7 +1497,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ id: expect.any(Number), state: 'IN_PROGRESS', - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.not.objectContaining({ @@ -1499,7 +1557,7 @@ describe('ContributionResolver', () => { expect.not.objectContaining({ id: expect.any(Number), state: 'IN_PROGRESS', - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.not.objectContaining({ @@ -1582,7 +1640,7 @@ describe('ContributionResolver', () => { expect.not.objectContaining({ id: expect.any(Number), state: 'IN_PROGRESS', - memo: 'Test IN_PROGESS contribution', + memo: 'Test IN_PROGRESS contribution', amount: '100', }), expect.objectContaining({ @@ -2009,7 +2067,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (2000 GDD) to be created exceeds the amount (900 GDD) still available for this month.', + 'The amount (2000 GDD) to be created exceeds the amount (790 GDD) still available for this month.', ), ], }), @@ -2018,7 +2076,7 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'The amount (2000 GDD) to be created exceeds the amount (900 GDD) still available for this month.', + 'The amount (2000 GDD) to be created exceeds the amount (790 GDD) still available for this month.', ) }) }) @@ -2031,7 +2089,7 @@ describe('ContributionResolver', () => { ).resolves.toEqual( expect.objectContaining({ data: { - adminCreateContribution: [1000, 1000, 700], + adminCreateContribution: [1000, 1000, 590], }, }), ) @@ -2056,7 +2114,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ errors: [ new GraphQLError( - 'The amount (1000 GDD) to be created exceeds the amount (700 GDD) still available for this month.', + 'The amount (1000 GDD) to be created exceeds the amount (590 GDD) still available for this month.', ), ], }), @@ -2065,7 +2123,7 @@ describe('ContributionResolver', () => { it('logs the error thrown', () => { expect(logger.error).toBeCalledWith( - 'The amount (1000 GDD) to be created exceeds the amount (700 GDD) still available for this month.', + 'The amount (1000 GDD) to be created exceeds the amount (590 GDD) still available for this month.', ) }) }) @@ -2210,7 +2268,6 @@ describe('ContributionResolver', () => { describe('user email does not match creation user', () => { it('throws an error', async () => { jest.clearAllMocks() - console.log('creation', creation) await expect( mutate({ mutation: adminUpdateContribution, @@ -2377,7 +2434,7 @@ describe('ContributionResolver', () => { memo: 'Das war leider zu Viel!', amount: '200', moderator: admin.id, - creation: ['1000', '600', '500'], + creation: ['1000', '800', '500'], }), expect.objectContaining({ id: expect.any(Number), @@ -2388,9 +2445,9 @@ describe('ContributionResolver', () => { memo: 'Grundeinkommen', amount: '500', moderator: admin.id, - creation: ['1000', '600', '500'], + creation: ['1000', '800', '500'], }), - expect.objectContaining({ + expect.not.objectContaining({ id: expect.any(Number), firstName: 'Bibi', lastName: 'Bloxberg', @@ -2399,7 +2456,29 @@ describe('ContributionResolver', () => { memo: 'Test contribution to delete', amount: '100', moderator: null, - creation: ['1000', '1000', '200'], + creation: ['1000', '1000', '90'], + }), + expect.objectContaining({ + id: expect.any(Number), + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + date: expect.any(String), + memo: 'Test PENDING contribution update', + amount: '10', + moderator: null, + creation: ['1000', '1000', '90'], + }), + expect.objectContaining({ + id: expect.any(Number), + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + date: expect.any(String), + memo: 'Test IN_PROGRESS contribution', + amount: '100', + moderator: null, + creation: ['1000', '1000', '90'], }), expect.objectContaining({ id: expect.any(Number), @@ -2410,7 +2489,7 @@ describe('ContributionResolver', () => { memo: 'Grundeinkommen', amount: '500', moderator: admin.id, - creation: ['1000', '1000', '200'], + creation: ['1000', '1000', '90'], }), expect.objectContaining({ id: expect.any(Number), @@ -2421,7 +2500,7 @@ describe('ContributionResolver', () => { memo: 'Aktives Grundeinkommen', amount: '200', moderator: admin.id, - creation: ['1000', '1000', '200'], + creation: ['1000', '1000', '90'], }), ]), }, From b7343fdc3e950d1b5988dd4d2ac2c97f1f45a7c3 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 6 Feb 2023 09:25:44 +0100 Subject: [PATCH 05/22] Add test user raeuber hotzenplotz and deny already confirmed, deleted or denied contributions. --- .../resolver/ContributionResolver.test.ts | 263 +++++++++++++++++- 1 file changed, 257 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index a7b6716db..eaf157edc 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -49,6 +49,7 @@ import { User } from '@entity/User' import { EventProtocolType } from '@/event/EventProtocolType' import { logger, i18n as localization } from '@test/testSetup' import { UserInputError } from 'apollo-server-express' +import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz' // mock account activation email to avoid console spam // mock account activation email to avoid console spam @@ -94,11 +95,13 @@ afterAll(async () => { describe('ContributionResolver', () => { let bibi: any + let raueber: any let peter: any beforeAll(async () => { bibi = await userFactory(testEnv, bibiBloxberg) admin = peter = await userFactory(testEnv, peterLustig) + raueber = await userFactory(testEnv, raeuberHotzenplotz) const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await creationFactory(testEnv, bibisCreation!) @@ -697,6 +700,158 @@ describe('ContributionResolver', () => { }) }) + describe('deny contribution that is already confirmed', () => { + let contribution: any + it('throws an error', async () => { + await mutate({ + mutation: login, + variables: { email: 'raeuber@hotzenplotz.de', password: 'Aa12345_' }, + }) + + contribution = await mutate({ + mutation: createContribution, + variables: { + amount: 166.0, + memo: 'Whatever contribution', + creationDate: new Date().toString(), + }, + }) + + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + + await mutate({ + mutation: confirmContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + + await expect( + mutate({ + mutation: denyContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Contribution not found for given id.')], + }), + ) + }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + `Contribution not found for given id: ${contribution.data.createContribution.id}`, + ) + }) + }) + + describe('deny contribution that is already deleted', () => { + let contribution: any + + it('throws an error', async () => { + await mutate({ + mutation: login, + variables: { email: 'raeuber@hotzenplotz.de', password: 'Aa12345_' }, + }) + + contribution = await mutate({ + mutation: createContribution, + variables: { + amount: 166.0, + memo: 'Whatever contribution', + creationDate: new Date().toString(), + }, + }) + + await mutate({ + mutation: deleteContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + + await expect( + mutate({ + mutation: denyContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Contribution not found for given id.')], + }), + ) + }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + `Contribution not found for given id: ${contribution.data.createContribution.id}`, + ) + }) + }) + + describe('deny contribution that is already denied', () => { + let contribution: any + + it('throws an error', async () => { + await mutate({ + mutation: login, + variables: { email: 'raeuber@hotzenplotz.de', password: 'Aa12345_' }, + }) + + contribution = await mutate({ + mutation: createContribution, + variables: { + amount: 166.0, + memo: 'Whatever contribution', + creationDate: new Date().toString(), + }, + }) + + await mutate({ + mutation: login, + variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, + }) + + await mutate({ + mutation: denyContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + + await expect( + mutate({ + mutation: denyContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }), + ).resolves.toEqual( + expect.objectContaining({ + errors: [new GraphQLError('Contribution not found for given id.')], + }), + ) + }) + + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + `Contribution not found for given id: ${contribution.data.createContribution.id}`, + ) + }) + }) + describe('valid input', () => { it('deny contribution', async () => { await mutate({ @@ -1168,7 +1323,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 5, + contributionCount: 7, contributionList: expect.arrayContaining([ expect.objectContaining({ amount: '100', @@ -1206,6 +1361,18 @@ describe('ContributionResolver', () => { memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), ]), }, }, @@ -1228,7 +1395,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 5, + contributionCount: 7, contributionList: expect.arrayContaining([ expect.objectContaining({ amount: '100', @@ -1266,6 +1433,18 @@ describe('ContributionResolver', () => { memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), ]), }, }, @@ -1288,7 +1467,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 5, + contributionCount: 7, contributionList: expect.arrayContaining([ expect.objectContaining({ amount: '100', @@ -1326,6 +1505,18 @@ describe('ContributionResolver', () => { memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), ]), }, }, @@ -1348,7 +1539,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 2, + contributionCount: 3, contributionList: expect.arrayContaining([ expect.objectContaining({ amount: '100', @@ -1386,6 +1577,18 @@ describe('ContributionResolver', () => { memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), ]), }, }, @@ -1446,6 +1649,18 @@ describe('ContributionResolver', () => { memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), ]), }, }, @@ -1506,6 +1721,18 @@ describe('ContributionResolver', () => { memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), ]), }, }, @@ -1528,7 +1755,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 1, + contributionCount: 2, contributionList: expect.arrayContaining([ expect.not.objectContaining({ amount: '100', @@ -1566,6 +1793,18 @@ describe('ContributionResolver', () => { memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), ]), }, }, @@ -1611,7 +1850,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ data: { listAllContributions: { - contributionCount: 3, + contributionCount: 4, contributionList: expect.arrayContaining([ expect.objectContaining({ amount: '100', @@ -1649,6 +1888,18 @@ describe('ContributionResolver', () => { memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), ]), }, }, From 46e8a55d2e69cec40c2ff1e6257506b60b26dcd7 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 6 Feb 2023 09:48:20 +0100 Subject: [PATCH 06/22] remove unused variable raeuber. --- backend/src/graphql/resolver/ContributionResolver.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index eaf157edc..7c239e699 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -95,13 +95,12 @@ afterAll(async () => { describe('ContributionResolver', () => { let bibi: any - let raueber: any let peter: any beforeAll(async () => { bibi = await userFactory(testEnv, bibiBloxberg) admin = peter = await userFactory(testEnv, peterLustig) - raueber = await userFactory(testEnv, raeuberHotzenplotz) + await userFactory(testEnv, raeuberHotzenplotz) const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await creationFactory(testEnv, bibisCreation!) From 65488b5c5c9705144b5689dd10dfa7aa2ae2fed0 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 8 Feb 2023 11:29:38 +0100 Subject: [PATCH 07/22] Test of createContribution are now centered on the final object. --- .../resolver/ContributionResolver.test.ts | 139 +++++++----------- 1 file changed, 56 insertions(+), 83 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 7c239e699..ebf40b292 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -72,8 +72,6 @@ let mutate: any, query: any, con: any let testEnv: any let creation: Contribution | void let admin: User -// let result: any -// let contribution: any let pendingContribution: any let inProgressContribution: any let contributionToConfirm: any @@ -173,16 +171,12 @@ describe('ContributionResolver', () => { describe('createContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - await expect( - mutate({ - mutation: createContribution, - variables: { amount: 100.0, memo: 'Test Contribution', creationDate: 'not-valid' }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: createContribution, + variables: { amount: 100.0, memo: 'Test Contribution', creationDate: 'not-valid' }, + }) + + expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) }) }) @@ -202,20 +196,18 @@ describe('ContributionResolver', () => { it('throws error when memo length smaller than 5 chars', async () => { jest.clearAllMocks() const date = new Date() - await expect( - mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test', - creationDate: date.toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('memo text is too short (5 characters minimum)')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test', + creationDate: date.toString(), + }, + }) + + expect(errorObjects).toMatchObject([ + new GraphQLError('memo text is too short (5 characters minimum)'), + ]) }) it('logs the error found', () => { @@ -225,20 +217,17 @@ describe('ContributionResolver', () => { it('throws error when memo length greater than 255 chars', async () => { jest.clearAllMocks() const date = new Date() - await expect( - mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test', - creationDate: date.toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('memo text is too long (255 characters maximum)')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test', + creationDate: date.toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('memo text is too long (255 characters maximum)'), + ]) }) it('logs the error found', () => { @@ -247,22 +236,17 @@ describe('ContributionResolver', () => { it('throws error when creationDate not-valid', async () => { jest.clearAllMocks() - await expect( - mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: 'not-valid', - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [ - new GraphQLError('No information for available creations for the given date'), - ], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test env contribution', + creationDate: 'not-valid', + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('No information for available creations for the given date'), + ]) }) it('logs the error found', () => { @@ -275,22 +259,17 @@ describe('ContributionResolver', () => { it('throws error when creationDate 3 month behind', async () => { jest.clearAllMocks() const date = new Date() - await expect( - mutate({ - mutation: createContribution, - variables: { - amount: 100.0, - memo: 'Test env contribution', - creationDate: date.setMonth(date.getMonth() - 3).toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [ - new GraphQLError('No information for available creations for the given date'), - ], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: createContribution, + variables: { + amount: 100.0, + memo: 'Test env contribution', + creationDate: date.setMonth(date.getMonth() - 3).toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('No information for available creations for the given date'), + ]) }) it('logs the error found', () => { @@ -303,17 +282,11 @@ describe('ContributionResolver', () => { describe('valid input', () => { it('creates contribution', async () => { - expect(pendingContribution).toEqual( - expect.objectContaining({ - data: { - createContribution: { - id: expect.any(Number), - amount: '100', - memo: 'Test PENDING contribution', - }, - }, - }), - ) + expect(pendingContribution.data.createContribution).toMatchObject({ + id: expect.any(Number), + amount: '100', + memo: 'Test PENDING contribution', + }) }) it('stores the create contribution event in the database', async () => { From 4cbfd83d5ec7e7dd7aff6f5aa8e99471827d8ed8 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 8 Feb 2023 11:51:09 +0100 Subject: [PATCH 08/22] Add deconstructing variables for updateContribution. --- .../resolver/ContributionResolver.test.ts | 270 ++++++++---------- 1 file changed, 119 insertions(+), 151 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index ebf40b292..1e463dd4b 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -50,6 +50,7 @@ import { EventProtocolType } from '@/event/EventProtocolType' import { logger, i18n as localization } from '@test/testSetup' import { UserInputError } from 'apollo-server-express' import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz' +import { UnconfirmedContribution } from '../model/UnconfirmedContribution' // mock account activation email to avoid console spam // mock account activation email to avoid console spam @@ -306,21 +307,16 @@ describe('ContributionResolver', () => { describe('updateContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - await expect( - mutate({ - mutation: updateContribution, - variables: { - contributionId: 1, - amount: 100.0, - memo: 'Test Contribution', - creationDate: 'not-valid', - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: updateContribution, + variables: { + contributionId: 1, + amount: 100.0, + memo: 'Test Contribution', + creationDate: 'not-valid', + }, + }) + expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) }) }) @@ -339,21 +335,18 @@ describe('ContributionResolver', () => { describe('wrong contribution id', () => { it('throws an error', async () => { jest.clearAllMocks() - await expect( - mutate({ - mutation: updateContribution, - variables: { - contributionId: -1, - amount: 100.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('No contribution found to given id.')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: updateContribution, + variables: { + contributionId: -1, + amount: 100.0, + memo: 'Test env contribution', + creationDate: new Date().toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('No contribution found to given id.'), + ]) }) it('logs the error found', () => { @@ -365,21 +358,18 @@ describe('ContributionResolver', () => { it('throws error', async () => { jest.clearAllMocks() const date = new Date() - await expect( - mutate({ - mutation: updateContribution, - variables: { - contributionId: pendingContribution.data.createContribution.id, - amount: 100.0, - memo: 'Test', - creationDate: date.toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('memo text is too short (5 characters minimum)')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: updateContribution, + variables: { + contributionId: pendingContribution.data.createContribution.id, + amount: 100.0, + memo: 'Test', + creationDate: date.toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('memo text is too short (5 characters minimum)'), + ]) }) it('logs the error found', () => { @@ -391,21 +381,18 @@ describe('ContributionResolver', () => { it('throws error', async () => { jest.clearAllMocks() const date = new Date() - await expect( - mutate({ - mutation: updateContribution, - variables: { - contributionId: pendingContribution.data.createContribution.id, - amount: 100.0, - memo: 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test', - creationDate: date.toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('memo text is too long (255 characters maximum)')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: updateContribution, + variables: { + contributionId: pendingContribution.data.createContribution.id, + amount: 100.0, + memo: 'Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test', + creationDate: date.toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('memo text is too long (255 characters maximum)'), + ]) }) it('logs the error found', () => { @@ -423,25 +410,18 @@ describe('ContributionResolver', () => { it('throws an error', async () => { jest.clearAllMocks() - await expect( - mutate({ - mutation: updateContribution, - variables: { - contributionId: pendingContribution.data.createContribution.id, - amount: 10.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [ - new GraphQLError( - 'user of the pending contribution and send user does not correspond', - ), - ], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: updateContribution, + variables: { + contributionId: pendingContribution.data.createContribution.id, + amount: 10.0, + memo: 'Test env contribution', + creationDate: new Date().toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('user of the pending contribution and send user does not correspond'), + ]) }) it('logs the error found', () => { @@ -461,25 +441,26 @@ describe('ContributionResolver', () => { it('throws an error', async () => { jest.clearAllMocks() - await expect( - mutate({ - mutation: adminUpdateContribution, - variables: { - id: pendingContribution.data.createContribution.id, - email: 'bibi@bloxberg.de', - amount: 10.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('An admin is not allowed to update a user contribution.')], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: adminUpdateContribution, + variables: { + id: pendingContribution.data.createContribution.id, + email: 'bibi@bloxberg.de', + amount: 10.0, + memo: 'Test env contribution', + creationDate: new Date().toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('An admin is not allowed to update a user contribution.'), + ]) }) - // TODO check that the error is logged (need to modify AdminResolver, avoid conflicts) + it('logs the error found', () => { + expect(logger.error).toBeCalledWith( + 'An admin is not allowed to update a user contribution.', + ) + }) }) describe('update to much so that the limit is exceeded', () => { @@ -492,25 +473,20 @@ describe('ContributionResolver', () => { it('throws an error', async () => { jest.clearAllMocks() - await expect( - mutate({ - mutation: updateContribution, - variables: { - contributionId: pendingContribution.data.createContribution.id, - amount: 1019.0, - memo: 'Test env contribution', - creationDate: new Date().toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [ - new GraphQLError( - 'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.', - ), - ], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: updateContribution, + variables: { + contributionId: pendingContribution.data.createContribution.id, + amount: 1019.0, + memo: 'Test env contribution', + creationDate: new Date().toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError( + 'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.', + ), + ]) }) it('logs the error found', () => { @@ -524,21 +500,18 @@ describe('ContributionResolver', () => { it('throws an error', async () => { jest.clearAllMocks() const date = new Date() - await expect( - mutate({ - mutation: updateContribution, - variables: { - contributionId: pendingContribution.data.createContribution.id, - amount: 10.0, - memo: 'Test env contribution', - creationDate: date.setMonth(date.getMonth() - 3).toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Currently the month of the contribution cannot change.')], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: updateContribution, + variables: { + contributionId: pendingContribution.data.createContribution.id, + amount: 10.0, + memo: 'Test env contribution', + creationDate: date.setMonth(date.getMonth() - 3).toString(), + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('Currently the month of the contribution cannot change.'), + ]) }) it.skip('logs the error found', () => { @@ -551,27 +524,22 @@ describe('ContributionResolver', () => { describe('valid input', () => { it('updates contribution', async () => { - await expect( - mutate({ - mutation: updateContribution, - variables: { - contributionId: pendingContribution.data.createContribution.id, - amount: 10.0, - memo: 'Test PENDING contribution update', - creationDate: new Date().toString(), - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - updateContribution: { - id: pendingContribution.data.createContribution.id, - amount: '10', - memo: 'Test PENDING contribution update', - }, - }, - }), - ) + const { + data: { updateContribution: contribution }, + }: { data: { updateContribution: UnconfirmedContribution } } = await mutate({ + mutation: updateContribution, + variables: { + contributionId: pendingContribution.data.createContribution.id, + amount: 10.0, + memo: 'Test PENDING contribution update', + creationDate: new Date().toString(), + }, + }) + expect(contribution).toMatchObject({ + id: pendingContribution.data.createContribution.id, + amount: '10', + memo: 'Test PENDING contribution update', + }) }) it('stores the update contribution event in the database', async () => { From 712b64fd068c854d8cb83da3832d0c11c8fa9795 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 8 Feb 2023 14:25:48 +0100 Subject: [PATCH 09/22] Add destructure for denyContribution tests. --- .../resolver/ContributionResolver.test.ts | 191 +++++++----------- 1 file changed, 70 insertions(+), 121 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 1e463dd4b..11ecbcd47 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -564,18 +564,13 @@ describe('ContributionResolver', () => { describe('denyContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - await expect( - mutate({ - mutation: denyContribution, - variables: { - id: 1, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: denyContribution, + variables: { + id: 1, + }, + }) + expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) }) }) @@ -592,18 +587,13 @@ describe('ContributionResolver', () => { }) it('returns an error', async () => { - await expect( - mutate({ - mutation: denyContribution, - variables: { - id: 1, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: denyContribution, + variables: { + id: 1, + }, + }) + expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) }) }) @@ -621,18 +611,15 @@ describe('ContributionResolver', () => { describe('wrong contribution id', () => { it('throws an error', async () => { - await expect( - mutate({ - mutation: denyContribution, - variables: { - id: -1, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Contribution not found for given id.')], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: denyContribution, + variables: { + id: -1, + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('Contribution not found for given id.'), + ]) }) it('logs the error found', () => { @@ -669,18 +656,15 @@ describe('ContributionResolver', () => { }, }) - await expect( - mutate({ - mutation: denyContribution, - variables: { - id: contribution.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Contribution not found for given id.')], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: denyContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('Contribution not found for given id.'), + ]) }) it('logs the error found', () => { @@ -720,18 +704,15 @@ describe('ContributionResolver', () => { variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, }) - await expect( - mutate({ - mutation: denyContribution, - variables: { - id: contribution.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Contribution not found for given id.')], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: denyContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('Contribution not found for given id.'), + ]) }) it('logs the error found', () => { @@ -771,18 +752,15 @@ describe('ContributionResolver', () => { }, }) - await expect( - mutate({ - mutation: denyContribution, - variables: { - id: contribution.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Contribution not found for given id.')], - }), - ) + const { errors: errorObjects }: { errors: GraphQLError[] } = await mutate({ + mutation: denyContribution, + variables: { + id: contribution.data.createContribution.id, + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('Contribution not found for given id.'), + ]) }) it('logs the error found', () => { @@ -798,20 +776,15 @@ describe('ContributionResolver', () => { mutation: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, }) - await expect( - mutate({ - mutation: denyContribution, - variables: { - id: contributionToDeny.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - denyContribution: true, - }, - }), - ) + const { + data: { denyContribution: isDenied }, + }: { data: { denyContribution: boolean } } = await mutate({ + mutation: denyContribution, + variables: { + id: contributionToDeny.data.createContribution.id, + }, + }) + expect(isDenied).toBeTruthy() }) }) }) @@ -930,32 +903,11 @@ describe('ContributionResolver', () => { }) it('stores the delete contribution event in the database', async () => { - await mutate({ - mutation: login, - variables: { email: 'peter@lustig.de', password: 'Aa12345_' }, - }) - - const contribution = await mutate({ - mutation: createContribution, - variables: { - amount: 166.0, - memo: 'Whatever contribution', - creationDate: new Date().toString(), - }, - }) - - await mutate({ - mutation: deleteContribution, - variables: { - id: contribution.data.createContribution.id, - }, - }) - await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.CONTRIBUTION_DELETE, - contributionId: contribution.data.createContribution.id, - amount: expect.decimalEqual(166), + contributionId: contributionToDelete.data.createContribution.id, + amount: expect.decimalEqual(100), userId: peter.id, }), ) @@ -979,18 +931,15 @@ describe('ContributionResolver', () => { mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) - await expect( - mutate({ - mutation: deleteContribution, - variables: { - id: contributionToConfirm.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('A confirmed contribution can not be deleted')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: deleteContribution, + variables: { + id: contributionToConfirm.data.createContribution.id, + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('A confirmed contribution can not be deleted'), + ]) }) it('logs the error found', () => { From bcf63ec334d6386d546fa4b9fe29550e0c2be573 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 9 Feb 2023 15:02:53 +0100 Subject: [PATCH 10/22] Deconstruct test for listContributions. --- .../resolver/ContributionResolver.test.ts | 290 ++++++++---------- backend/src/seeds/factory/creation.ts | 3 +- 2 files changed, 135 insertions(+), 158 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 11ecbcd47..a56e89ab0 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -51,6 +51,7 @@ import { logger, i18n as localization } from '@test/testSetup' import { UserInputError } from 'apollo-server-express' import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz' import { UnconfirmedContribution } from '../model/UnconfirmedContribution' +import { ContributionListResult } from '../model/Contribution' // mock account activation email to avoid console spam // mock account activation email to avoid console spam @@ -78,6 +79,7 @@ let inProgressContribution: any let contributionToConfirm: any let contributionToDeny: any let contributionToDelete: any +let bibiCreatedContribution: Contribution beforeAll(async () => { testEnv = await testEnvironment(logger, localization) @@ -102,7 +104,7 @@ describe('ContributionResolver', () => { await userFactory(testEnv, raeuberHotzenplotz) const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - await creationFactory(testEnv, bibisCreation!) + bibiCreatedContribution = await creationFactory(testEnv, bibisCreation!) await mutate({ mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, @@ -183,7 +185,7 @@ describe('ContributionResolver', () => { describe('authenticated with valid user', () => { beforeAll(async () => { - bibi = await mutate({ + await mutate({ mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) @@ -296,7 +298,7 @@ describe('ContributionResolver', () => { type: EventProtocolType.CONTRIBUTION_CREATE, amount: expect.decimalEqual(100), contributionId: pendingContribution.data.createContribution.id, - userId: bibi.data.login.id, + userId: bibi.id, }), ) }) @@ -543,7 +545,7 @@ describe('ContributionResolver', () => { }) it('stores the update contribution event in the database', async () => { - bibi = await query({ + await query({ query: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) @@ -553,7 +555,7 @@ describe('ContributionResolver', () => { type: EventProtocolType.CONTRIBUTION_UPDATE, amount: expect.decimalEqual(10), contributionId: pendingContribution.data.createContribution.id, - userId: bibi.data.login.id, + userId: bibi.id, }), ) }) @@ -793,24 +795,19 @@ describe('ContributionResolver', () => { describe('deleteContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - await expect( - query({ - query: deleteContribution, - variables: { - id: -1, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + query: deleteContribution, + variables: { + id: -1, + }, + }) + expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) }) }) describe('authenticated', () => { beforeAll(async () => { - bibi = await mutate({ + await mutate({ mutation: login, variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' }, }) @@ -822,18 +819,15 @@ describe('ContributionResolver', () => { describe('wrong contribution id', () => { it('returns an error', async () => { - await expect( - mutate({ - mutation: deleteContribution, - variables: { - id: -1, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Contribution not found for given id.')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: deleteContribution, + variables: { + id: -1, + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('Contribution not found for given id.'), + ]) }) it('logs the error found', () => { @@ -854,18 +848,15 @@ describe('ContributionResolver', () => { }) it('returns an error', async () => { - await expect( - mutate({ - mutation: deleteContribution, - variables: { - id: contributionToDelete.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('Can not delete contribution of another user')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await mutate({ + mutation: deleteContribution, + variables: { + id: contributionToDelete.data.createContribution.id, + }, + }) + expect(errorObjects).toMatchObject([ + new GraphQLError('Can not delete contribution of another user'), + ]) }) it('logs the error found', () => { @@ -886,20 +877,15 @@ describe('ContributionResolver', () => { }) it('deletes successfully', async () => { - await expect( - mutate({ - mutation: deleteContribution, - variables: { - id: contributionToDelete.data.createContribution.id, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - deleteContribution: true, - }, - }), - ) + const { + data: { deleteContribution: isDenied }, + }: { data: { deleteContribution: boolean } } = await mutate({ + mutation: deleteContribution, + variables: { + id: contributionToDelete.data.createContribution.id, + }, + }) + expect(isDenied).toBeTruthy() }) it('stores the delete contribution event in the database', async () => { @@ -908,7 +894,7 @@ describe('ContributionResolver', () => { type: EventProtocolType.CONTRIBUTION_DELETE, contributionId: contributionToDelete.data.createContribution.id, amount: expect.decimalEqual(100), - userId: peter.id, + userId: bibi.id, }), ) }) @@ -984,113 +970,103 @@ describe('ContributionResolver', () => { describe('filter confirmed is false', () => { it('returns creations', async () => { - await expect( - query({ - query: listContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - filterConfirmed: false, + const { + data: { listContributions: contributionListResult }, + }: { data: { listContributions: ContributionListResult } } = await query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: false, + }, + }) + expect(contributionListResult).toMatchObject({ + contributionCount: 6, + contributionList: expect.arrayContaining([ + { + amount: '100', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listContributions: { - contributionCount: 6, - contributionList: expect.arrayContaining([ - expect.objectContaining({ - amount: '100', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test contribution to deny', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test contribution to delete', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - ]), - }, + { + id: pendingContribution.data.createContribution.id, + memo: 'Test PENDING contribution update', + amount: '10', }, - }), - ) + { + id: contributionToDeny.data.createContribution.id, + memo: 'Test contribution to deny', + amount: '100', + }, + { + id: contributionToDelete.data.createContribution.id, + memo: 'Test contribution to delete', + amount: '100', + }, + { + id: inProgressContribution.data.createContribution.id, + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }, + { + id: bibiCreatedContribution.id, + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }, + ]), + }) }) }) describe('filter confirmed is true', () => { it('returns only unconfirmed creations', async () => { - await expect( - query({ - query: listContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - filterConfirmed: true, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listContributions: { - contributionCount: 4, - contributionList: expect.arrayContaining([ - expect.not.objectContaining({ - amount: '100', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test contribution to deny', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test contribution to delete', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - ]), - }, - }, - }), - ) + const { + data: { listContributions: contributionListResult }, + }: { data: { listContributions: ContributionListResult } } = await query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: true, + }, + }) + expect(contributionListResult).toMatchObject({ + contributionCount: 4, + contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + amount: '100', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: pendingContribution.data.createContribution.id, + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: contributionToDeny.data.createContribution.id, + memo: 'Test contribution to deny', + amount: '100', + }), + expect.objectContaining({ + id: contributionToDelete.data.createContribution.id, + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: inProgressContribution.data.createContribution.id, + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.not.objectContaining({ + id: bibiCreatedContribution.id, + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + ]), + }) }) }) }) diff --git a/backend/src/seeds/factory/creation.ts b/backend/src/seeds/factory/creation.ts index 09bf981bb..69d77aa03 100644 --- a/backend/src/seeds/factory/creation.ts +++ b/backend/src/seeds/factory/creation.ts @@ -16,7 +16,7 @@ export const nMonthsBefore = (date: Date, months = 1): string => { export const creationFactory = async ( client: ApolloServerTestClient, creation: CreationInterface, -): Promise => { +): Promise => { const { mutate } = client await mutate({ mutation: login, variables: { email: creation.email, password: 'Aa12345_' } }) @@ -51,6 +51,7 @@ export const creationFactory = async ( await confirmedContribution.save() } } + return confirmedContribution } else { return contribution } From 96feb30476b515d67d42a8bc5c3d3811c7583a22 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 9 Feb 2023 16:08:57 +0100 Subject: [PATCH 11/22] Deconstruct the listAllContributions test. --- .../resolver/ContributionResolver.test.ts | 1229 ++++++++--------- 1 file changed, 582 insertions(+), 647 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index a56e89ab0..eff7925b1 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -1075,21 +1075,16 @@ describe('ContributionResolver', () => { describe('listAllContribution', () => { describe('unauthenticated', () => { it('returns an error', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: null, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: null, + }, + }) + expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) }) }) @@ -1106,670 +1101,610 @@ describe('ContributionResolver', () => { }) it('throws an error with "NOT_VALID" in statusFilter', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: ['NOT_VALID'], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [ - new UserInputError( - 'Variable "$statusFilter" got invalid value "NOT_VALID" at "statusFilter[0]"; Value "NOT_VALID" does not exist in "ContributionStatus" enum.', - ), - ], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError | UserInputError] } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: ['NOT_VALID'], + }, + }) + expect(errorObjects).toMatchObject([ + new UserInputError( + 'Variable "$statusFilter" got invalid value "NOT_VALID" at "statusFilter[0]"; Value "NOT_VALID" does not exist in "ContributionStatus" enum.', + ), + ]) }) it('throws an error with a null in statusFilter', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: [null], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [ - new UserInputError( - 'Variable "$statusFilter" got invalid value null at "statusFilter[0]"; Expected non-nullable type "ContributionStatus!" not to be null.', - ), - ], - }), - ) + const { errors: errorObjects }: { errors: [Error] } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: [null], + }, + }) + expect(errorObjects).toMatchObject([ + new UserInputError( + 'Variable "$statusFilter" got invalid value null at "statusFilter[0]"; Expected non-nullable type "ContributionStatus!" not to be null.', + ), + ]) }) it('throws an error with null and "NOT_VALID" in statusFilter', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: [null, 'NOT_VALID'], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [ - new UserInputError( - 'Variable "$statusFilter" got invalid value null at "statusFilter[0]"; Expected non-nullable type "ContributionStatus!" not to be null.', - ), - new UserInputError( - 'Variable "$statusFilter" got invalid value "NOT_VALID" at "statusFilter[1]"; Value "NOT_VALID" does not exist in "ContributionStatus" enum.', - ), - ], - }), - ) + const { errors: errorObjects }: { errors: [Error] } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: [null, 'NOT_VALID'], + }, + }) + expect(errorObjects).toMatchObject([ + new UserInputError( + 'Variable "$statusFilter" got invalid value null at "statusFilter[0]"; Expected non-nullable type "ContributionStatus!" not to be null.', + ), + new UserInputError( + 'Variable "$statusFilter" got invalid value "NOT_VALID" at "statusFilter[1]"; Value "NOT_VALID" does not exist in "ContributionStatus" enum.', + ), + ]) }) it('returns all contributions without statusFilter', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 7, - contributionList: expect.arrayContaining([ - expect.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), - ]), - }, - }, - }), - ) + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 7, + contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: pendingContribution.data.createContribution.id, + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: contributionToDeny.data.createContribution.id, + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: contributionToDelete.data.createContribution.id, + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.objectContaining({ + id: bibiCreatedContribution.id, + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + ]), + }) }) it('returns all contributions for statusFilter = null', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: null, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 7, - contributionList: expect.arrayContaining([ - expect.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), - ]), - }, - }, - }), - ) + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: null, + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 7, + contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: pendingContribution.data.createContribution.id, + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: contributionToDeny.data.createContribution.id, + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: contributionToDelete.data.createContribution.id, + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.objectContaining({ + id: bibiCreatedContribution.id, + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + ]), + }) }) it('returns all contributions for statusFilter = []', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: [], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 7, - contributionList: expect.arrayContaining([ - expect.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), - ]), - }, - }, - }), - ) + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: [], + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 7, + contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: pendingContribution.data.createContribution.id, + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: contributionToDeny.data.createContribution.id, + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: contributionToDelete.data.createContribution.id, + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.objectContaining({ + id: bibiCreatedContribution.id, + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + ]), + }) }) it('returns all CONFIRMED contributions', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: ['CONFIRMED'], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 3, - contributionList: expect.arrayContaining([ - expect.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), - ]), - }, - }, - }), - ) + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: ['CONFIRMED'], + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 3, + contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.not.objectContaining({ + id: pendingContribution.data.createContribution.id, + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.not.objectContaining({ + id: contributionToDeny.data.createContribution.id, + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: contributionToDelete.data.createContribution.id, + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.not.objectContaining({ + id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.objectContaining({ + id: bibiCreatedContribution.id, + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + ]), + }) }) it('returns all PENDING contributions', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: ['PENDING'], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 1, - contributionList: expect.arrayContaining([ - expect.not.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), - ]), - }, - }, - }), - ) + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: ['PENDING'], + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 1, + contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: pendingContribution.data.createContribution.id, + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.not.objectContaining({ + id: contributionToDeny.data.createContribution.id, + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: contributionToDelete.data.createContribution.id, + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.not.objectContaining({ + id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.not.objectContaining({ + id: bibiCreatedContribution.id, + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + ]), + }) }) it('returns all IN_PROGRESS Creation', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: ['IN_PROGRESS'], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 1, - contributionList: expect.arrayContaining([ - expect.not.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), - ]), - }, - }, - }), - ) + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: ['IN_PROGRESS'], + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 1, + contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.not.objectContaining({ + id: pendingContribution.data.createContribution.id, + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.not.objectContaining({ + id: contributionToDeny.data.createContribution.id, + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: contributionToDelete.data.createContribution.id, + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.objectContaining({ + id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.not.objectContaining({ + id: bibiCreatedContribution.id, + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + ]), + }) }) it('returns all DENIED Creation', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: ['DENIED'], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 2, - contributionList: expect.arrayContaining([ - expect.not.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), - ]), - }, - }, - }), - ) + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: ['DENIED'], + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 2, + contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.not.objectContaining({ + id: pendingContribution.data.createContribution.id, + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.objectContaining({ + id: contributionToDeny.data.createContribution.id, + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: contributionToDelete.data.createContribution.id, + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.not.objectContaining({ + id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.not.objectContaining({ + id: bibiCreatedContribution.id, + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + ]), + }) }) - it('returns all DELETED Creation', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: ['DELETED'], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 0, - contributionList: [], - }, - }, - }), - ) + it('does not return any DELETED Creation', async () => { + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: ['DELETED'], + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 0, + contributionList: [], + }) }) it('returns all CONFIRMED and PENDING Creation', async () => { - await expect( - query({ - query: listAllContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - statusFilter: ['CONFIRMED', 'PENDING'], - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - data: { - listAllContributions: { - contributionCount: 4, - contributionList: expect.arrayContaining([ - expect.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: expect.any(Number), - memo: 'Test contribution to confirm', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - ]), - }, - }, - }), - ) + const { + data: { listAllContributions: contributionListObject }, + }: { data: { listAllContributions: ContributionListResult } } = await query({ + query: listAllContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + statusFilter: ['CONFIRMED', 'PENDING'], + }, + }) + expect(contributionListObject).toMatchObject({ + contributionCount: 4, + contributionList: expect.arrayContaining([ + expect.objectContaining({ + amount: '100', + state: 'CONFIRMED', + id: contributionToConfirm.data.createContribution.id, + memo: 'Test contribution to confirm', + }), + expect.objectContaining({ + id: pendingContribution.data.createContribution.id, + state: 'PENDING', + memo: 'Test PENDING contribution update', + amount: '10', + }), + expect.not.objectContaining({ + id: contributionToDeny.data.createContribution.id, + state: 'DENIED', + memo: 'Test contribution to deny', + amount: '100', + }), + expect.not.objectContaining({ + id: contributionToDelete.data.createContribution.id, + state: 'DELETED', + memo: 'Test contribution to delete', + amount: '100', + }), + expect.not.objectContaining({ + id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', + memo: 'Test IN_PROGRESS contribution', + amount: '100', + }), + expect.objectContaining({ + id: bibiCreatedContribution.id, + state: 'CONFIRMED', + memo: 'Herzlich Willkommen bei Gradido!', + amount: '1000', + }), + expect.not.objectContaining({ + id: expect.any(Number), + state: 'DENIED', + memo: 'Whatever contribution', + amount: '166', + }), + expect.objectContaining({ + id: expect.any(Number), + state: 'CONFIRMED', + memo: 'Whatever contribution', + amount: '166', + }), + ]), + }) }) }) }) From e5025a906cd649a3094b6822b8ea1232855fded0 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 9 Feb 2023 16:24:18 +0100 Subject: [PATCH 12/22] Deconstruct not authenticated. --- .../resolver/ContributionResolver.test.ts | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index eff7925b1..93a31fb77 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -938,21 +938,16 @@ describe('ContributionResolver', () => { describe('listContributions', () => { describe('unauthenticated', () => { it('returns an error', async () => { - await expect( - query({ - query: listContributions, - variables: { - currentPage: 1, - pageSize: 25, - order: 'DESC', - filterConfirmed: false, - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('401 Unauthorized')], - }), - ) + const { errors: errorObjects }: { errors: [GraphQLError] } = await query({ + query: listContributions, + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + filterConfirmed: false, + }, + }) + expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) }) }) From 6ff43e2d4c4355261e7c6cd6676d5adb1a53a110 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 9 Feb 2023 17:10:27 +0100 Subject: [PATCH 13/22] Change the expect.not.objectContaining to the state instead of the whole object. --- .../resolver/ContributionResolver.test.ts | 225 ++++-------------- 1 file changed, 49 insertions(+), 176 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 93a31fb77..5b2c0fcaf 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -96,11 +96,10 @@ afterAll(async () => { describe('ContributionResolver', () => { let bibi: any - let peter: any beforeAll(async () => { bibi = await userFactory(testEnv, bibiBloxberg) - admin = peter = await userFactory(testEnv, peterLustig) + admin = await userFactory(testEnv, peterLustig) await userFactory(testEnv, raeuberHotzenplotz) const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de') // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -1163,6 +1162,9 @@ describe('ContributionResolver', () => { expect(contributionListObject).toMatchObject({ contributionCount: 7, contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + state: 'DELETED', + }), expect.objectContaining({ amount: '100', state: 'CONFIRMED', @@ -1181,12 +1183,6 @@ describe('ContributionResolver', () => { memo: 'Test contribution to deny', amount: '100', }), - expect.not.objectContaining({ - id: contributionToDelete.data.createContribution.id, - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), expect.objectContaining({ id: inProgressContribution.data.createContribution.id, state: 'IN_PROGRESS', @@ -1230,6 +1226,9 @@ describe('ContributionResolver', () => { expect(contributionListObject).toMatchObject({ contributionCount: 7, contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + state: 'DELETED', + }), expect.objectContaining({ amount: '100', state: 'CONFIRMED', @@ -1248,12 +1247,6 @@ describe('ContributionResolver', () => { memo: 'Test contribution to deny', amount: '100', }), - expect.not.objectContaining({ - id: contributionToDelete.data.createContribution.id, - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), expect.objectContaining({ id: inProgressContribution.data.createContribution.id, state: 'IN_PROGRESS', @@ -1297,6 +1290,9 @@ describe('ContributionResolver', () => { expect(contributionListObject).toMatchObject({ contributionCount: 7, contributionList: expect.arrayContaining([ + expect.not.objectContaining({ + state: 'DELETED', + }), expect.objectContaining({ amount: '100', state: 'CONFIRMED', @@ -1315,12 +1311,6 @@ describe('ContributionResolver', () => { memo: 'Test contribution to deny', amount: '100', }), - expect.not.objectContaining({ - id: contributionToDelete.data.createContribution.id, - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), expect.objectContaining({ id: inProgressContribution.data.createContribution.id, state: 'IN_PROGRESS', @@ -1370,30 +1360,6 @@ describe('ContributionResolver', () => { id: contributionToConfirm.data.createContribution.id, memo: 'Test contribution to confirm', }), - expect.not.objectContaining({ - id: pendingContribution.data.createContribution.id, - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), - expect.not.objectContaining({ - id: contributionToDeny.data.createContribution.id, - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: contributionToDelete.data.createContribution.id, - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.not.objectContaining({ - id: inProgressContribution.data.createContribution.id, - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), expect.objectContaining({ id: bibiCreatedContribution.id, state: 'CONFIRMED', @@ -1407,10 +1373,16 @@ describe('ContributionResolver', () => { amount: '166', }), expect.not.objectContaining({ - id: expect.any(Number), + state: 'PENDING', + }), + expect.not.objectContaining({ state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', + }), + expect.not.objectContaining({ + state: 'DELETED', + }), + expect.not.objectContaining({ + state: 'IN_PROGRESS', }), ]), }) @@ -1432,10 +1404,16 @@ describe('ContributionResolver', () => { contributionCount: 1, contributionList: expect.arrayContaining([ expect.not.objectContaining({ - amount: '100', state: 'CONFIRMED', - id: contributionToConfirm.data.createContribution.id, - memo: 'Test contribution to confirm', + }), + expect.not.objectContaining({ + state: 'DENIED', + }), + expect.not.objectContaining({ + state: 'DELETED', + }), + expect.not.objectContaining({ + state: 'IN_PROGRESS', }), expect.objectContaining({ id: pendingContribution.data.createContribution.id, @@ -1443,42 +1421,6 @@ describe('ContributionResolver', () => { memo: 'Test PENDING contribution update', amount: '10', }), - expect.not.objectContaining({ - id: contributionToDeny.data.createContribution.id, - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: contributionToDelete.data.createContribution.id, - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.not.objectContaining({ - id: inProgressContribution.data.createContribution.id, - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.not.objectContaining({ - id: bibiCreatedContribution.id, - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), ]), }) }) @@ -1499,28 +1441,16 @@ describe('ContributionResolver', () => { contributionCount: 1, contributionList: expect.arrayContaining([ expect.not.objectContaining({ - amount: '100', state: 'CONFIRMED', - id: contributionToConfirm.data.createContribution.id, - memo: 'Test contribution to confirm', }), expect.not.objectContaining({ - id: pendingContribution.data.createContribution.id, state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', }), expect.not.objectContaining({ - id: contributionToDeny.data.createContribution.id, state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', }), expect.not.objectContaining({ - id: contributionToDelete.data.createContribution.id, state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', }), expect.objectContaining({ id: inProgressContribution.data.createContribution.id, @@ -1528,24 +1458,6 @@ describe('ContributionResolver', () => { memo: 'Test IN_PROGRESS contribution', amount: '100', }), - expect.not.objectContaining({ - id: bibiCreatedContribution.id, - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), ]), }) }) @@ -1565,54 +1477,30 @@ describe('ContributionResolver', () => { expect(contributionListObject).toMatchObject({ contributionCount: 2, contributionList: expect.arrayContaining([ - expect.not.objectContaining({ - amount: '100', - state: 'CONFIRMED', - id: contributionToConfirm.data.createContribution.id, - memo: 'Test contribution to confirm', - }), - expect.not.objectContaining({ - id: pendingContribution.data.createContribution.id, - state: 'PENDING', - memo: 'Test PENDING contribution update', - amount: '10', - }), expect.objectContaining({ id: contributionToDeny.data.createContribution.id, state: 'DENIED', memo: 'Test contribution to deny', amount: '100', }), - expect.not.objectContaining({ - id: contributionToDelete.data.createContribution.id, - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.not.objectContaining({ - id: inProgressContribution.data.createContribution.id, - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), - expect.not.objectContaining({ - id: bibiCreatedContribution.id, - state: 'CONFIRMED', - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'CONFIRMED', - memo: 'Whatever contribution', - amount: '166', - }), expect.objectContaining({ id: expect.any(Number), state: 'DENIED', memo: 'Whatever contribution', amount: '166', }), + expect.not.objectContaining({ + state: 'CONFIRMED', + }), + expect.not.objectContaining({ + state: 'DELETED', + }), + expect.not.objectContaining({ + state: 'IN_PROGRESS', + }), + expect.not.objectContaining({ + state: 'PENDING', + }), ]), }) }) @@ -1662,42 +1550,27 @@ describe('ContributionResolver', () => { memo: 'Test PENDING contribution update', amount: '10', }), - expect.not.objectContaining({ - id: contributionToDeny.data.createContribution.id, - state: 'DENIED', - memo: 'Test contribution to deny', - amount: '100', - }), - expect.not.objectContaining({ - id: contributionToDelete.data.createContribution.id, - state: 'DELETED', - memo: 'Test contribution to delete', - amount: '100', - }), - expect.not.objectContaining({ - id: inProgressContribution.data.createContribution.id, - state: 'IN_PROGRESS', - memo: 'Test IN_PROGRESS contribution', - amount: '100', - }), expect.objectContaining({ id: bibiCreatedContribution.id, state: 'CONFIRMED', memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', }), - expect.not.objectContaining({ - id: expect.any(Number), - state: 'DENIED', - memo: 'Whatever contribution', - amount: '166', - }), expect.objectContaining({ id: expect.any(Number), state: 'CONFIRMED', memo: 'Whatever contribution', amount: '166', }), + expect.not.objectContaining({ + state: 'DENIED', + }), + expect.not.objectContaining({ + state: 'DELETED', + }), + expect.not.objectContaining({ + state: 'IN_PROGRESS', + }), ]), }) }) From a615c741c28bdd49c25295af237b58ec1d04f612 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 14 Feb 2023 07:55:38 +0100 Subject: [PATCH 14/22] Add tests that EVENT is stored in DB and has right values in userId. --- .../src/graphql/resolver/ContributionResolver.test.ts | 9 +++++++++ backend/src/graphql/resolver/ContributionResolver.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index fe98c0f6f..e8cdad748 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -815,6 +815,15 @@ describe('ContributionResolver', () => { }) expect(isDenied).toBeTruthy() }) + + it('stores the admin deny contribution event in the database', async () => { + await expect(EventProtocol.find()).resolves.toContainEqual( + expect.objectContaining({ + type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, + userId: admin.id, + }), + ) + }) }) }) }) diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 926742d8a..a18be7c38 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -732,7 +732,7 @@ export class ContributionResolver { const event = new Event() const eventAdminContributionDeny = new EventAdminContributionDeny() - eventAdminContributionDeny.userId = contributionToUpdate.userId + eventAdminContributionDeny.userId = moderator.id eventAdminContributionDeny.amount = contributionToUpdate.amount eventAdminContributionDeny.contributionId = contributionToUpdate.id await writeEvent(event.setEventAdminContributionDeny(eventAdminContributionDeny)) From 34fe6b4e90a5fc6233105f1b56239459bb5e1a00 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 15 Feb 2023 09:44:00 +0100 Subject: [PATCH 15/22] Rework reviews, add the properties used in the ui for listContributions. --- .../resolver/ContributionResolver.test.ts | 61 +++++++++++-------- backend/src/seeds/graphql/queries.ts | 9 +++ 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 6031bac30..a467cd9c9 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -813,14 +813,15 @@ describe('ContributionResolver', () => { id: contributionToDeny.data.createContribution.id, }, }) - expect(isDenied).toBeTruthy() + expect(isDenied).toBe(true) }) it('stores the admin deny contribution event in the database', async () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, - userId: admin.id, + userId: bibi.id, + xUserId: admin.id, }), ) }) @@ -925,7 +926,7 @@ describe('ContributionResolver', () => { id: contributionToDelete.data.createContribution.id, }, }) - expect(isDenied).toBeTruthy() + expect(isDenied).toBe(true) }) it('stores the CONTRIBUTION_DELETE event in the database', async () => { @@ -1022,38 +1023,39 @@ describe('ContributionResolver', () => { expect(contributionListResult).toMatchObject({ contributionCount: 6, contributionList: expect.arrayContaining([ - { + expect.objectContaining({ amount: '100', id: contributionToConfirm.data.createContribution.id, memo: 'Test contribution to confirm', - }, - { + }), + expect.objectContaining({ id: pendingContribution.data.createContribution.id, memo: 'Test PENDING contribution update', amount: '10', - }, - { + }), + expect.objectContaining({ id: contributionToDeny.data.createContribution.id, memo: 'Test contribution to deny', amount: '100', - }, - { + }), + expect.objectContaining({ id: contributionToDelete.data.createContribution.id, memo: 'Test contribution to delete', amount: '100', - }, - { + }), + expect.objectContaining({ id: inProgressContribution.data.createContribution.id, memo: 'Test IN_PROGRESS contribution', amount: '100', - }, - { + }), + expect.objectContaining({ id: bibiCreatedContribution.id, memo: 'Herzlich Willkommen bei Gradido!', amount: '1000', - }, + }), ]), }) + expect(contributionListResult.contributionList).toHaveLength(6) }) }) @@ -1074,37 +1076,35 @@ describe('ContributionResolver', () => { contributionCount: 4, contributionList: expect.arrayContaining([ expect.not.objectContaining({ - amount: '100', - id: contributionToConfirm.data.createContribution.id, - memo: 'Test contribution to confirm', + state: 'CONFIRMED', }), expect.objectContaining({ id: pendingContribution.data.createContribution.id, + state: 'PENDING', memo: 'Test PENDING contribution update', amount: '10', }), expect.objectContaining({ id: contributionToDeny.data.createContribution.id, + state: 'DENIED', memo: 'Test contribution to deny', amount: '100', }), expect.objectContaining({ id: contributionToDelete.data.createContribution.id, + state: 'DELETED', memo: 'Test contribution to delete', amount: '100', }), expect.objectContaining({ id: inProgressContribution.data.createContribution.id, + state: 'IN_PROGRESS', memo: 'Test IN_PROGRESS contribution', amount: '100', }), - expect.not.objectContaining({ - id: bibiCreatedContribution.id, - memo: 'Herzlich Willkommen bei Gradido!', - amount: '1000', - }), ]), }) + expect(contributionListResult.contributionList).toHaveLength(4) }) }) }) @@ -1253,6 +1253,7 @@ describe('ContributionResolver', () => { }), ]), }) + expect(contributionListObject.contributionList).toHaveLength(7) }) it('returns all contributions for statusFilter = null', async () => { @@ -1317,6 +1318,7 @@ describe('ContributionResolver', () => { }), ]), }) + expect(contributionListObject.contributionList).toHaveLength(7) }) it('returns all contributions for statusFilter = []', async () => { @@ -1381,6 +1383,7 @@ describe('ContributionResolver', () => { }), ]), }) + expect(contributionListObject.contributionList).toHaveLength(7) }) it('returns all CONFIRMED contributions', async () => { @@ -1430,6 +1433,7 @@ describe('ContributionResolver', () => { }), ]), }) + expect(contributionListObject.contributionList).toHaveLength(3) }) it('returns all PENDING contributions', async () => { @@ -1467,6 +1471,7 @@ describe('ContributionResolver', () => { }), ]), }) + expect(contributionListObject.contributionList).toHaveLength(1) }) it('returns all IN_PROGRESS Creation', async () => { @@ -1504,6 +1509,7 @@ describe('ContributionResolver', () => { }), ]), }) + expect(contributionListObject.contributionList).toHaveLength(1) }) it('returns all DENIED Creation', async () => { @@ -1547,6 +1553,7 @@ describe('ContributionResolver', () => { }), ]), }) + expect(contributionListObject.contributionList).toHaveLength(2) }) it('does not return any DELETED Creation', async () => { @@ -1565,6 +1572,7 @@ describe('ContributionResolver', () => { contributionCount: 0, contributionList: [], }) + expect(contributionListObject.contributionList).toHaveLength(0) }) it('returns all CONFIRMED and PENDING Creation', async () => { @@ -1617,6 +1625,7 @@ describe('ContributionResolver', () => { }), ]), }) + expect(contributionListObject.contributionList).toHaveLength(4) }) }) }) @@ -2336,7 +2345,7 @@ describe('ContributionResolver', () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, - userId: admin.id, + userId: bibi.id, }), ) }) @@ -2376,7 +2385,7 @@ describe('ContributionResolver', () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, - userId: admin.id, + userId: bibi.id, }), ) }) @@ -2554,7 +2563,7 @@ describe('ContributionResolver', () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, - userId: admin.id, + userId: bibi.id, }), ) }) diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 385a69479..3469c200d 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -166,6 +166,15 @@ export const listContributions = gql` id amount memo + createdAt + contributionDate + confirmedAt + confirmedBy + deletedAt + state + messagesCount + deniedAt + deniedBy } } } From d32b520145e35478270e8c4bbeddadcc832cff55 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 15 Feb 2023 10:00:30 +0100 Subject: [PATCH 16/22] Change test description to better naming. --- backend/src/graphql/resolver/ContributionResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index a467cd9c9..1e7b451e1 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -816,7 +816,7 @@ describe('ContributionResolver', () => { expect(isDenied).toBe(true) }) - it('stores the admin deny contribution event in the database', async () => { + it('stores the ADMIN_CONTRIBUTION_DENY event in the database', async () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, From 11f19262b00c4cfaea393f68f654d21f68d05132 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 15 Feb 2023 11:40:02 +0100 Subject: [PATCH 17/22] Add expected data to Protocols tests. --- .../graphql/resolver/ContributionResolver.test.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 1e7b451e1..e41c416ff 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -822,6 +822,8 @@ describe('ContributionResolver', () => { type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, userId: bibi.id, xUserId: admin.id, + contributionId: contributionToDeny.data.createContribution.id, + amount: expect.decimalEqual(100), }), ) }) @@ -2080,6 +2082,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE, userId: admin.id, + amount: expect.decimalEqual(200), }), ) }) @@ -2345,7 +2348,8 @@ describe('ContributionResolver', () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, - userId: bibi.id, + userId: admin.id, + amount: 300, }), ) }) @@ -2385,7 +2389,8 @@ describe('ContributionResolver', () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, - userId: bibi.id, + userId: admin.id, + amount: expect.decimalEqual(200), }), ) }) @@ -2563,7 +2568,8 @@ describe('ContributionResolver', () => { await expect(EventProtocol.find()).resolves.toContainEqual( expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, - userId: bibi.id, + userId: admin.id, + amount: expect.decimalEqual(400), }), ) }) From 00a45d780517ba7c61a8750f3340f676aee86ca3 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 15 Feb 2023 12:17:17 +0100 Subject: [PATCH 18/22] Corrected the expected amount from the ADMIN_CONTRIBUTION_DELETE event. --- backend/src/graphql/resolver/ContributionResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index e41c416ff..93ddb7c83 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -2569,7 +2569,7 @@ describe('ContributionResolver', () => { expect.objectContaining({ type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, userId: admin.id, - amount: expect.decimalEqual(400), + amount: expect.decimalEqual(200), }), ) }) From b9c46d223849298deff72bbbef7313e6ebbab8cb Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 15 Feb 2023 12:33:13 +0100 Subject: [PATCH 19/22] Correct spelling error. --- backend/src/graphql/resolver/ContributionResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 93ddb7c83..ce37449df 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -505,7 +505,7 @@ describe('ContributionResolver', () => { }) }) - describe('update to much so that the limit is exceeded', () => { + describe('update too much so that the limit is exceeded', () => { beforeAll(async () => { await mutate({ mutation: login, From 86e52e5d712853780e8501c02d21b2416fde4156 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 16 Feb 2023 15:40:28 +0100 Subject: [PATCH 20/22] Change coverage from 80 to 81. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7819a0703..3ef94cfbd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -545,7 +545,7 @@ jobs: report_name: Coverage Backend type: lcov result_path: ./backend/coverage/lcov.info - min_coverage: 80 + min_coverage: 81 token: ${{ github.token }} ########################################################################## From 40b2944b2474cb1a2742de0466d622b85a9d1f51 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 16 Feb 2023 15:41:04 +0100 Subject: [PATCH 21/22] Check toEqual. --- .../resolver/ContributionResolver.test.ts | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index ce37449df..670eaac2d 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -174,7 +174,7 @@ describe('ContributionResolver', () => { variables: { amount: 100.0, memo: 'Test Contribution', creationDate: 'not-valid' }, }) - expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) + expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')]) }) }) @@ -203,7 +203,7 @@ describe('ContributionResolver', () => { }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Memo text is too short')]) + expect(errorObjects).toEqual([new GraphQLError('Memo text is too short')]) }) it('logs the error found', () => { @@ -221,7 +221,7 @@ describe('ContributionResolver', () => { creationDate: date.toString(), }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Memo text is too long')]) + expect(errorObjects).toEqual([new GraphQLError('Memo text is too long')]) }) it('logs the error found', () => { @@ -238,7 +238,7 @@ describe('ContributionResolver', () => { creationDate: 'not-valid', }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new GraphQLError('No information for available creations for the given date'), ]) }) @@ -261,7 +261,7 @@ describe('ContributionResolver', () => { creationDate: date.setMonth(date.getMonth() - 3).toString(), }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new GraphQLError('No information for available creations for the given date'), ]) }) @@ -309,7 +309,7 @@ describe('ContributionResolver', () => { creationDate: 'not-valid', }, }) - expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) + expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')]) }) }) @@ -338,7 +338,7 @@ describe('ContributionResolver', () => { creationDate: date.toString(), }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Memo text is too short')]) + expect(errorObjects).toEqual([new GraphQLError('Memo text is too short')]) }) it('logs the error found', () => { @@ -359,7 +359,7 @@ describe('ContributionResolver', () => { creationDate: date.toString(), }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Memo text is too long')]) + expect(errorObjects).toEqual([new GraphQLError('Memo text is too long')]) }) it('logs the error found', () => { @@ -411,7 +411,7 @@ describe('ContributionResolver', () => { creationDate: new Date().toString(), }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new GraphQLError('Can not update contribution of another user'), ]) }) @@ -445,7 +445,7 @@ describe('ContributionResolver', () => { creationDate: new Date().toString(), }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new GraphQLError('An admin is not allowed to update an user contribution'), ]) }) @@ -524,7 +524,7 @@ describe('ContributionResolver', () => { creationDate: new Date().toString(), }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new GraphQLError( 'The amount (1019 GDD) to be created exceeds the amount (600 GDD) still available for this month.', ), @@ -551,7 +551,7 @@ describe('ContributionResolver', () => { creationDate: date.setMonth(date.getMonth() - 3).toString(), }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new GraphQLError('Month of contribution can not be changed'), ]) }) @@ -609,7 +609,7 @@ describe('ContributionResolver', () => { id: 1, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) + expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')]) }) }) @@ -632,7 +632,7 @@ describe('ContributionResolver', () => { id: 1, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) + expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')]) }) }) @@ -657,7 +657,7 @@ describe('ContributionResolver', () => { id: -1, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Contribution not found')]) + expect(errorObjects).toEqual([new GraphQLError('Contribution not found')]) }) it('logs the error found', () => { @@ -701,7 +701,7 @@ describe('ContributionResolver', () => { id: contribution.data.createContribution.id, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Contribution not found')]) + expect(errorObjects).toEqual([new GraphQLError('Contribution not found')]) }) it('logs the error found', () => { @@ -746,7 +746,7 @@ describe('ContributionResolver', () => { id: contribution.data.createContribution.id, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Contribution not found')]) + expect(errorObjects).toEqual([new GraphQLError('Contribution not found')]) }) it('logs the error found', () => { @@ -791,7 +791,7 @@ describe('ContributionResolver', () => { id: contribution.data.createContribution.id, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Contribution not found')]) + expect(errorObjects).toEqual([new GraphQLError('Contribution not found')]) }) it('logs the error found', () => { @@ -840,7 +840,7 @@ describe('ContributionResolver', () => { id: -1, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) + expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')]) }) }) @@ -865,7 +865,7 @@ describe('ContributionResolver', () => { id: -1, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('Contribution not found')]) + expect(errorObjects).toEqual([new GraphQLError('Contribution not found')]) }) it('logs the error found', () => { @@ -893,7 +893,7 @@ describe('ContributionResolver', () => { id: contributionToDelete.data.createContribution.id, }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new GraphQLError('Can not delete contribution of another user'), ]) }) @@ -966,7 +966,7 @@ describe('ContributionResolver', () => { id: contributionToConfirm.data.createContribution.id, }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new GraphQLError('A confirmed contribution can not be deleted'), ]) }) @@ -993,7 +993,7 @@ describe('ContributionResolver', () => { filterConfirmed: false, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) + expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')]) }) }) @@ -1124,7 +1124,7 @@ describe('ContributionResolver', () => { statusFilter: null, }, }) - expect(errorObjects).toMatchObject([new GraphQLError('401 Unauthorized')]) + expect(errorObjects).toEqual([new GraphQLError('401 Unauthorized')]) }) }) @@ -1150,7 +1150,7 @@ describe('ContributionResolver', () => { statusFilter: ['NOT_VALID'], }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new UserInputError( 'Variable "$statusFilter" got invalid value "NOT_VALID" at "statusFilter[0]"; Value "NOT_VALID" does not exist in "ContributionStatus" enum.', ), @@ -1167,7 +1167,7 @@ describe('ContributionResolver', () => { statusFilter: [null], }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new UserInputError( 'Variable "$statusFilter" got invalid value null at "statusFilter[0]"; Expected non-nullable type "ContributionStatus!" not to be null.', ), @@ -1184,7 +1184,7 @@ describe('ContributionResolver', () => { statusFilter: [null, 'NOT_VALID'], }, }) - expect(errorObjects).toMatchObject([ + expect(errorObjects).toEqual([ new UserInputError( 'Variable "$statusFilter" got invalid value null at "statusFilter[0]"; Expected non-nullable type "ContributionStatus!" not to be null.', ), @@ -1570,7 +1570,7 @@ describe('ContributionResolver', () => { statusFilter: ['DELETED'], }, }) - expect(contributionListObject).toMatchObject({ + expect(contributionListObject).toEqual({ contributionCount: 0, contributionList: [], }) From 72b8e2dc97c17005923f31330d5e7cd696c88b07 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 16 Feb 2023 17:22:41 +0100 Subject: [PATCH 22/22] Revert "Change coverage from 80 to 81." This reverts commit 86e52e5d712853780e8501c02d21b2416fde4156. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61000381d..de45a35aa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -545,7 +545,7 @@ jobs: report_name: Coverage Backend type: lcov result_path: ./backend/coverage/lcov.info - min_coverage: 81 + min_coverage: 80 token: ${{ github.token }} ##########################################################################