diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index abae8e446..d48502c69 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -45,6 +45,7 @@ import { Transaction as DbTransaction } from '@entity/Transaction' import { User } from '@entity/User' import { EventProtocolType } from '@/event/EventProtocolType' import { logger, i18n as localization } from '@test/testSetup' +import { UserInputError } from 'apollo-server-express' // mock account activation email to avoid console spam // mock account activation email to avoid console spam @@ -681,7 +682,7 @@ describe('ContributionResolver', () => { currentPage: 1, pageSize: 25, order: 'DESC', - filterConfirmed: false, + statusFilter: null, }, }), ).resolves.toEqual( @@ -718,7 +719,76 @@ describe('ContributionResolver', () => { resetToken() }) - it('returns allCreation', async () => { + 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.', + ), + ], + }), + ) + }) + + 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.', + ), + ], + }), + ) + }) + + 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.', + ), + ], + }), + ) + }) + + it('returns all contributions without statusFilter', async () => { await expect( query({ query: listAllContributions, @@ -726,7 +796,6 @@ describe('ContributionResolver', () => { currentPage: 1, pageSize: 25, order: 'DESC', - filterConfirmed: false, }, }), ).resolves.toEqual( @@ -737,11 +806,301 @@ describe('ContributionResolver', () => { contributionList: expect.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', + }), + ]), + }, + }, + }), + ) + }) + + 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: 2, + contributionList: expect.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', + }), + ]), + }, + }, + }), + ) + }) + + 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: 2, + contributionList: expect.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', + }), + ]), + }, + }, + }), + ) + }) + + 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: 1, + contributionList: expect.arrayContaining([ + 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', + }), + ]), + }, + }, + }), + ) + }) + + 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({ + 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', + }), + ]), + }, + }, + }), + ) + }) + + 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: 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', + }), + ]), + }, + }, + }), + ) + }) + + 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: 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', + }), + ]), + }, + }, + }), + ) + }) + + 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: 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', + }), + ]), + }, + }, + }), + ) + }) + + 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: 2, + contributionList: expect.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', }), diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 0c758b52b..c7946d2c8 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -179,12 +179,23 @@ export class ContributionResolver { async listAllContributions( @Args() { currentPage = 1, pageSize = 5, order = Order.DESC }: Paginated, + @Arg('statusFilter', () => [ContributionStatus], { nullable: true }) + statusFilter?: ContributionStatus[], ): Promise { + const where: { + contributionStatus?: FindOperator | null + } = {} + + if (statusFilter && statusFilter.length) { + where.contributionStatus = In(statusFilter) + } + const [dbContributions, count] = await getConnection() .createQueryBuilder() .select('c') .from(DbContribution, 'c') .innerJoinAndSelect('c.user', 'u') + .where(where) .orderBy('c.createdAt', order) .limit(pageSize) .offset((currentPage - 1) * pageSize) diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 97f871235..385a69479 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -172,18 +172,23 @@ export const listContributions = gql` ` export const listAllContributions = ` -query ($currentPage: Int = 1, $pageSize: Int = 5, $order: Order = DESC) { - listAllContributions(currentPage: $currentPage, pageSize: $pageSize, order: $order) { +query ($currentPage: Int = 1, $pageSize: Int = 5, $order: Order = DESC, $statusFilter: [ContributionStatus!]) { + listAllContributions(currentPage: $currentPage, pageSize: $pageSize, order: $order, statusFilter: $statusFilter) { contributionCount contributionList { id - firstName - lastName - amount - memo - createdAt - confirmedAt - confirmedBy + firstName + lastName + amount + memo + createdAt + confirmedAt + confirmedBy + contributionDate + state + messagesCount + deniedAt + deniedBy } } }