From 1649ca410ed5cd2e9d7cb8d0b9efa3ac9346f9ff Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 30 Aug 2023 00:21:06 -0500 Subject: [PATCH] add tests for staging goerli and alfajores --- src/resolvers/projectResolver.test.ts | 210 +++++++++++++++----------- 1 file changed, 125 insertions(+), 85 deletions(-) diff --git a/src/resolvers/projectResolver.test.ts b/src/resolvers/projectResolver.test.ts index 567ba0383..a7102d85e 100644 --- a/src/resolvers/projectResolver.test.ts +++ b/src/resolvers/projectResolver.test.ts @@ -109,7 +109,6 @@ import { } from '../services/projectViewsService'; import { addOrUpdatePowerSnapshotBalances } from '../repositories/powerBalanceSnapshotRepository'; import { findPowerSnapshots } from '../repositories/powerSnapshotRepository'; -import { logger } from '../utils/logger'; const ARGUMENT_VALIDATION_ERROR_MESSAGE = new ArgumentValidationError([ { property: '' }, @@ -878,9 +877,13 @@ function allProjectsTestCases() { ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.MAIN_NET, }); - + const gnosisAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.XDAI, + })) as ProjectAddress; + gnosisAddress.isRecipient = false; + await gnosisAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -909,9 +912,13 @@ function allProjectsTestCases() { ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.CELO, }); - + const celoAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.CELO, + })) as ProjectAddress; + celoAddress.isRecipient = true; + await celoAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -940,8 +947,13 @@ function allProjectsTestCases() { ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.XDAI, }); + const celoAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.CELO, + })) as ProjectAddress; + celoAddress.isRecipient = false; + await celoAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -970,9 +982,13 @@ function allProjectsTestCases() { ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.MAIN_NET, }); - + const mainnetAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.MAIN_NET, + })) as ProjectAddress; + mainnetAddress.isRecipient = true; + await mainnetAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -1001,9 +1017,13 @@ function allProjectsTestCases() { ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.XDAI, }); - + const mainnetAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.MAIN_NET, + })) as ProjectAddress; + mainnetAddress.isRecipient = false; + await mainnetAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -1032,9 +1052,13 @@ function allProjectsTestCases() { ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.POLYGON, }); - + const polygonAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.POLYGON, + })) as ProjectAddress; + polygonAddress.isRecipient = true; + await polygonAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -1063,9 +1087,13 @@ function allProjectsTestCases() { ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.XDAI, }); - + const polygonAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.POLYGON, + })) as ProjectAddress; + polygonAddress.isRecipient = false; + await polygonAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -1089,14 +1117,89 @@ function allProjectsTestCases() { ); }); - it('should return projects, filter by accept donation on optimism', async () => { + it('should return projects, filter by accept donation on GOERLI', async () => { const savedProject = await saveProjectDirectlyToDb({ ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.OPTIMISTIC, }); + const optimismAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.GOERLI, + })) as ProjectAddress; + optimismAddress.isRecipient = true; + await optimismAddress.save(); + const result = await axios.post(graphqlUrl, { + query: fetchMultiFilterAllProjectsQuery, + variables: { + filters: ['AcceptFundOnMainnet'], + sortingBy: SortingField.Newest, + limit: 50, + }, + }); + result.data.data.allProjects.projects.forEach(project => { + assert.isOk( + project.addresses.find( + address => + address.isRecipient === true && + address.networkId === NETWORK_IDS.GOERLI, + ), + ); + }); + assert.isOk( + result.data.data.allProjects.projects.find( + project => Number(project.id) === Number(savedProject.id), + ), + ); + }); + + it('should return projects, filter by accept donation on ALFAJORES', async () => { + const savedProject = await saveProjectDirectlyToDb({ + ...createProjectData(), + title: String(new Date().getTime()), + slug: String(new Date().getTime()), + }); + const optimismAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.CELO_ALFAJORES, + })) as ProjectAddress; + optimismAddress.isRecipient = true; + await optimismAddress.save(); + const result = await axios.post(graphqlUrl, { + query: fetchMultiFilterAllProjectsQuery, + variables: { + filters: ['AcceptFundOnCelo'], + sortingBy: SortingField.Newest, + }, + }); + result.data.data.allProjects.projects.forEach(project => { + assert.isOk( + project.addresses.find( + address => + address.isRecipient === true && + address.networkId === NETWORK_IDS.CELO_ALFAJORES, + ), + ); + }); + assert.isOk( + result.data.data.allProjects.projects.find( + project => Number(project.id) === Number(savedProject.id), + ), + ); + }); + it('should return projects, filter by accept donation on optimism', async () => { + const savedProject = await saveProjectDirectlyToDb({ + ...createProjectData(), + title: String(new Date().getTime()), + slug: String(new Date().getTime()), + }); + const optimismAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.OPTIMISTIC, + })) as ProjectAddress; + optimismAddress.isRecipient = true; + await optimismAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -1124,9 +1227,13 @@ function allProjectsTestCases() { ...createProjectData(), title: String(new Date().getTime()), slug: String(new Date().getTime()), - networkId: NETWORK_IDS.XDAI, }); - + const optimismAddress = (await findProjectRecipientAddressByNetworkId({ + projectId: savedProject.id, + networkId: NETWORK_IDS.OPTIMISTIC, + })) as ProjectAddress; + optimismAddress.isRecipient = false; + await optimismAddress.save(); const result = await axios.post(graphqlUrl, { query: fetchMultiFilterAllProjectsQuery, variables: { @@ -1226,73 +1333,6 @@ function allProjectsTestCases() { ), ); }); - - it('should return projects, return projects that matches with at least one of networks', async () => { - const mainnetProject = await saveProjectDirectlyToDb({ - ...createProjectData(), - title: String(new Date().getTime()), - slug: String(new Date().getTime()), - networkId: NETWORK_IDS.MAIN_NET, - }); - - const gnosisProject = await saveProjectDirectlyToDb({ - ...createProjectData(), - title: String(new Date().getTime()), - slug: String(new Date().getTime()), - networkId: NETWORK_IDS.XDAI, - }); - - const polygonProject = await saveProjectDirectlyToDb({ - ...createProjectData(), - title: String(new Date().getTime()), - slug: String(new Date().getTime()), - networkId: NETWORK_IDS.POLYGON, - }); - - const optimismProject = await saveProjectDirectlyToDb({ - ...createProjectData(), - title: String(new Date().getTime()), - slug: String(new Date().getTime()), - networkId: NETWORK_IDS.OPTIMISTIC, - }); - - const celoProject = await saveProjectDirectlyToDb({ - ...createProjectData(), - title: String(new Date().getTime()), - slug: String(new Date().getTime()), - networkId: NETWORK_IDS.CELO, - }); - - const projects = [ - celoProject, - mainnetProject, - gnosisProject, - polygonProject, - optimismProject, - ]; - - const result = await axios.post(graphqlUrl, { - query: fetchMultiFilterAllProjectsQuery, - variables: { - filters: [ - 'AcceptFundOnMainnet', - 'AcceptFundOnGnosis', - 'AcceptFundOnPolygon', - 'AcceptFundOnCelo', - 'AcceptFundOnOptimism', - ], - sortingBy: SortingField.Newest, - }, - }); - projects.forEach(p => { - assert.isOk( - result.data.data.allProjects.projects.find( - project => Number(project.id) === Number(p.id), - ), - ); - }); - }); - it('should return projects, filter by campaignSlug and limit, skip', async () => { const project1 = await saveProjectDirectlyToDb({ ...createProjectData(),