Skip to content

Commit

Permalink
add test:projectVerificationTab
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadPCh committed Oct 29, 2024
1 parent 4d8b591 commit 9d99aff
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
151 changes: 151 additions & 0 deletions src/server/adminJs/tabs/projectVerificationTab.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import { assert } from 'chai';

Check failure on line 1 in src/server/adminJs/tabs/projectVerificationTab.test.ts

View workflow job for this annotation

GitHub Actions / test

Expected 2-3 arguments, but got 1.
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);
});
}

0 comments on commit 9d99aff

Please sign in to comment.