From 9d99aff20bb87bbd1433cc58a284ea78fc1a3b99 Mon Sep 17 00:00:00 2001 From: Cherik Date: Tue, 29 Oct 2024 19:16:57 +0330 Subject: [PATCH] add test:projectVerificationTab --- package.json | 1 + .../tabs/projectVerificationTab.test.ts | 151 ++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 src/server/adminJs/tabs/projectVerificationTab.test.ts diff --git a/package.json b/package.json index 17349eadc..dcc849d62 100644 --- a/package.json +++ b/package.json @@ -136,6 +136,7 @@ "test:qfRoundService": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/qfRoundService.test.ts", "test:project": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/entities/project.test.ts", "test:projectsTab": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/server/adminJs/tabs/projectsTab.test.ts", + "test:projectVerificationTab": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/server/adminJs/tabs/projectVerificationTab.test.ts", "test:syncUsersModelScore": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/cronJobs/syncUsersModelScore.test.ts", "test:notifyDonationsWithSegment": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/cronJobs/notifyDonationsWithSegment.test.ts", "test:checkProjectVerificationStatus": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/services/cronJobs/checkProjectVerificationStatus.test.ts", diff --git a/src/server/adminJs/tabs/projectVerificationTab.test.ts b/src/server/adminJs/tabs/projectVerificationTab.test.ts new file mode 100644 index 000000000..7a2d4ad45 --- /dev/null +++ b/src/server/adminJs/tabs/projectVerificationTab.test.ts @@ -0,0 +1,151 @@ +import { assert } from 'chai'; +import { + createProjectData, + saveProjectDirectlyToDb, + SEED_DATA, +} from '../../../../test/testUtils'; +import { PROJECT_VERIFICATION_STATUSES } from '../../../entities/projectVerificationForm'; +import { User } from '../../../entities/user'; +import { + createProjectVerificationForm, + findProjectVerificationFormById, +} from '../../../repositories/projectVerificationRepository'; +import { findUserById } from '../../../repositories/userRepository'; +import { approveVerificationForms } from './projectVerificationTab'; +import { findProjectById } from '../../../repositories/projectRepository'; + +describe( + 'approveGivbacksEligibilityForm() TestCases', + approveGivbacksEligibilityFormTestCases, +); + +function approveGivbacksEligibilityFormTestCases() { + it('Should throw error if Givback Eligibility Form is on draft', async () => { + const project = await saveProjectDirectlyToDb({ + ...createProjectData(), + title: String(new Date().getTime()), + slug: String(new Date().getTime()), + verified: true, + listed: true, + }); + + const projectVerificationForm = await createProjectVerificationForm({ + projectId: project.id, + userId: project.adminUserId, + }); + + projectVerificationForm.status = PROJECT_VERIFICATION_STATUSES.DRAFT; + await projectVerificationForm.save(); + + const adminUser = await findUserById(SEED_DATA.ADMIN_USER.id); + + await approveVerificationForms( + { + currentAdmin: adminUser as User, + h: {}, + resource: {}, + records: [], + }, + { + query: { + recordIds: String(projectVerificationForm.id), + }, + }, + true, + ); + + const updatedForm = await findProjectVerificationFormById( + projectVerificationForm.id, + ); + assert.isOk(updatedForm); + assert.equal(updatedForm?.status, PROJECT_VERIFICATION_STATUSES.DRAFT); + }); + + it('Should be able approve Givback Eligibility Form for not draft form', async () => { + const project = await saveProjectDirectlyToDb({ + ...createProjectData(), + title: String(new Date().getTime()), + slug: String(new Date().getTime()), + verified: true, + listed: true, + isGivbackEligible: false, + }); + + const projectVerificationForm = await createProjectVerificationForm({ + projectId: project.id, + userId: project.adminUserId, + }); + projectVerificationForm.status = PROJECT_VERIFICATION_STATUSES.SUBMITTED; + await projectVerificationForm.save(); + + const adminUser = await findUserById(SEED_DATA.ADMIN_USER.id); + + await approveVerificationForms( + { + currentAdmin: adminUser as User, + h: {}, + resource: {}, + records: [], + }, + { + query: { + recordIds: String(projectVerificationForm.id), + }, + }, + true, + ); + + const updatedForm = await findProjectVerificationFormById( + projectVerificationForm.id, + ); + const updatedPorject = await findProjectById(project.id); + assert.isOk(updatedForm); + assert.equal(updatedForm?.status, PROJECT_VERIFICATION_STATUSES.VERIFIED); + assert.isTrue(updatedPorject?.isGivbackEligible); + assert.equal(updatedPorject?.verificationFormStatus); + }); + + it('Should be able to reject Givback Eligibility Form for not draft form', async () => { + const project = await saveProjectDirectlyToDb({ + ...createProjectData(), + title: String(new Date().getTime()), + slug: String(new Date().getTime()), + verified: true, + listed: true, + isGivbackEligible: false, + }); + + const projectVerificationForm = await createProjectVerificationForm({ + projectId: project.id, + userId: project.adminUserId, + }); + projectVerificationForm.status = PROJECT_VERIFICATION_STATUSES.SUBMITTED; + await projectVerificationForm.save(); + + const adminUser = await findUserById(SEED_DATA.ADMIN_USER.id); + + await approveVerificationForms( + { + currentAdmin: adminUser as User, + h: {}, + resource: {}, + records: [], + }, + { + query: { + recordIds: String(projectVerificationForm.id), + }, + }, + false, + ); + + const updatedForm = await findProjectVerificationFormById( + projectVerificationForm.id, + ); + const updatedPorject = await findProjectById(project.id); + + assert.isOk(updatedForm); + assert.equal(updatedForm?.status, PROJECT_VERIFICATION_STATUSES.REJECTED); + assert.isFalse(updatedPorject?.isGivbackEligible); + }); +}