Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Nov 27, 2024
1 parent 240912a commit d935172
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/resolvers/qAccResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE,
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD,
} from '../constants/gitcoin';
import { PrivadoAdapter } from '../adapters/privado/privadoAdapter';

describe(
'projectUserTotalDonationAmount() test cases',
Expand Down Expand Up @@ -269,7 +270,7 @@ function userCapsTestCases() {
tokenPrice: 0.5,
}).save();
sinon.useFakeTimers({
now: qfRound1.beginDate.getTime(),
now: new Date('2001-01-15').getTime(),
});
});
afterEach(async () => {
Expand All @@ -295,18 +296,20 @@ function userCapsTestCases() {
);

// Simulate valid GitcoinPassport score
sinon.stub(user, 'analysisScore').value(80);
sinon.stub(user, 'passportScoreUpdateTimestamp').value(new Date());
sinon.stub(user, 'hasEnoughGitcoinAnalysisScore').value(true);
user.analysisScore = 80;
user.passportScoreUpdateTimestamp = new Date();
await user.save();

const response: ExecutionResult<{
userCaps: {
qAccCap: number;
gitcoinPassport?: {
unusedCap: number;
};
zkId?: {
unusedCap: number;
data: {
userCaps: {
qAccCap: number;
gitcoinPassport?: {
unusedCap: number;
};
zkId?: {
unusedCap: number;
};
};
};
}> = await axios.post(
Expand All @@ -323,18 +326,18 @@ function userCapsTestCases() {
);

assert.equal(
response.data?.userCaps?.qAccCap,
response.data?.data.userCaps?.qAccCap,
Number(qfRound1.roundUSDCapPerUserPerProject) /
Number(qfRound1.tokenPrice) -
donationAmount,
);
assert.equal(
response.data?.userCaps?.gitcoinPassport?.unusedCap,
response.data?.data.userCaps?.gitcoinPassport?.unusedCap,
MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_USD /
Number(qfRound1.tokenPrice) -
donationAmount,
);
assert.isUndefined(response.data?.userCaps?.zkId);
assert.isNull(response.data?.data.userCaps?.zkId);
});

it('should return correct caps for a user with ZkId', async () => {
Expand All @@ -351,16 +354,19 @@ function userCapsTestCases() {
project.id,
);

sinon.stub(user, 'privadoVerified').value(true);
user.privadoVerifiedRequestIds = [PrivadoAdapter.privadoRequestId];
await user.save();

const response: ExecutionResult<{
userCaps: {
qAccCap: number;
gitcoinPassport?: {
unusedCap: number;
};
zkId?: {
unusedCap: number;
data: {
userCaps: {
qAccCap: number;
gitcoinPassport?: {
unusedCap: number;
};
zkId?: {
unusedCap: number;
};
};
};
}> = await axios.post(
Expand All @@ -378,18 +384,18 @@ function userCapsTestCases() {

// Assert: Verify the response matches expected values
assert.equal(
response.data?.userCaps?.qAccCap,
response.data?.data.userCaps?.qAccCap,
Number(qfRound1.roundUSDCapPerUserPerProject) /
Number(qfRound1.tokenPrice) -
donationAmount,
);
assert.equal(
response.data?.userCaps?.zkId?.unusedCap,
response.data?.data.userCaps?.zkId?.unusedCap,
Number(qfRound1.roundUSDCapPerUserPerProject) /
Number(qfRound1.tokenPrice) -
donationAmount,
);
assert.isUndefined(response.data?.userCaps?.gitcoinPassport);
assert.isNull(response.data?.data.userCaps?.gitcoinPassport);
});

it('should throw an error if the user does not meet the minimum analysis score', async () => {
Expand Down

0 comments on commit d935172

Please sign in to comment.