-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1866 from Giveth/update-verify-approve-conditions
Update verify approve conditions
- Loading branch information
Showing
6 changed files
with
299 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 updatedProject = await findProjectById(project.id); | ||
assert.isOk(updatedForm); | ||
assert.equal(updatedForm?.status, PROJECT_VERIFICATION_STATUSES.VERIFIED); | ||
assert.isTrue(updatedProject?.isGivbackEligible); | ||
// assert.equal(updatedProject?.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 updatedProject = await findProjectById(project.id); | ||
|
||
assert.isOk(updatedForm); | ||
assert.equal(updatedForm?.status, PROJECT_VERIFICATION_STATUSES.REJECTED); | ||
assert.isFalse(updatedProject?.isGivbackEligible); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.