From 3ee817a9cc0823e05bcf91d2bccbd6073953f9ef Mon Sep 17 00:00:00 2001 From: Mohammad Ranjbar Z Date: Tue, 24 Sep 2024 11:33:41 +0330 Subject: [PATCH] Add isGivbackEligible filter --- src/entities/project.ts | 1 + .../projectResolver.allProject.test.ts | 95 ++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/entities/project.ts b/src/entities/project.ts index fee212f20..8a1a386c0 100644 --- a/src/entities/project.ts +++ b/src/entities/project.ts @@ -82,6 +82,7 @@ export enum SortingField { export enum FilterField { Verified = 'verified', + IsGivbackEligible = 'isGivbackEligible', AcceptGiv = 'givingBlocksId', AcceptFundOnGnosis = 'acceptFundOnGnosis', AcceptFundOnMainnet = 'acceptFundOnMainnet', diff --git a/src/resolvers/projectResolver.allProject.test.ts b/src/resolvers/projectResolver.allProject.test.ts index e7235cd42..533e61209 100644 --- a/src/resolvers/projectResolver.allProject.test.ts +++ b/src/resolvers/projectResolver.allProject.test.ts @@ -220,9 +220,10 @@ function allProjectsTestCases() { ); assert.isTrue(firstProjectIsOlder); }); - it('should return projects, filter by verified, true', async () => { + + it('should return projects, filter by verified, true #1', async () => { // There is two verified projects so I just need to create a project with verified: false and listed:true - await saveProjectDirectlyToDb({ + const unverifiedProject = await saveProjectDirectlyToDb({ ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), @@ -239,7 +240,97 @@ function allProjectsTestCases() { result.data.data.allProjects.projects.forEach(project => assert.isTrue(project.verified), ); + + // should not include unverified project in the response + assert.notExists( + result.data.data.allProjects.projects.find( + project => Number(project.id) === unverifiedProject.id, + ), + ); + }); + it('should return projects, filter by verified, true #2', async () => { + const verified = await saveProjectDirectlyToDb({ + ...createProjectData(), + title: String(new Date().getTime()), + slug: String(new Date().getTime()), + verified: true, + qualityScore: 0, + }); + const result = await axios.post(graphqlUrl, { + query: fetchMultiFilterAllProjectsQuery, + variables: { + filters: ['Verified'], + sortingBy: SortingField.Newest, + }, + }); + assert.isNotEmpty(result.data.data.allProjects.projects); + result.data.data.allProjects.projects.forEach(project => + assert.isTrue(project.verified), + ); + + // should not include unverified project in the response + assert.exists( + result.data.data.allProjects.projects.find( + project => Number(project.id) === verified.id, + ), + ); }); + + it('should return projects, filter by isGivbackEligible, true #1', async () => { + // There is two isGivbackEligible projects so I just need to create a project with isGivbackEligible: false and listed:true + const notGivbackEligibleProject = await saveProjectDirectlyToDb({ + ...createProjectData(), + title: String(new Date().getTime()), + slug: String(new Date().getTime()), + isGivbackEligible: false, + qualityScore: 0, + }); + const result = await axios.post(graphqlUrl, { + query: fetchMultiFilterAllProjectsQuery, + variables: { + filters: ['IsGivbackEligible'], + }, + }); + assert.isNotEmpty(result.data.data.allProjects.projects); + result.data.data.allProjects.projects.forEach(project => + assert.isTrue(project.isGivbackEligible), + ); + + // should not include unisGivbackEligible project in the response + assert.notExists( + result.data.data.allProjects.projects.find( + project => Number(project.id) === notGivbackEligibleProject.id, + ), + ); + }); + it('should return projects, filter by isGivbackEligible, true #2', async () => { + const givbackEligibleProject = await saveProjectDirectlyToDb({ + ...createProjectData(), + title: String(new Date().getTime()), + slug: String(new Date().getTime()), + isGivbackEligible: true, + qualityScore: 0, + }); + const result = await axios.post(graphqlUrl, { + query: fetchMultiFilterAllProjectsQuery, + variables: { + filters: ['IsGivbackEligible'], + sortingBy: SortingField.Newest, + }, + }); + assert.isNotEmpty(result.data.data.allProjects.projects); + result.data.data.allProjects.projects.forEach(project => + assert.isTrue(project.isGivbackEligible), + ); + + // should not include unisGivbackEligible project in the response + assert.exists( + result.data.data.allProjects.projects.find( + project => Number(project.id) === givbackEligibleProject.id, + ), + ); + }); + it('should return projects, filter by acceptGiv, true', async () => { await saveProjectDirectlyToDb({ ...createProjectData(),