Skip to content

Commit

Permalink
Merge pull request #124 from GeneralMagicio/fix/round-matching
Browse files Browse the repository at this point in the history
Fixed issue in calculating project user record
  • Loading branch information
ae2079 authored Oct 31, 2024
2 parents 469715b + 25ff03e commit 56dc9b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/repositories/projectUserRecordRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,33 @@ import {
getProjectUserRecordAmount,
updateOrCreateProjectUserRecord,
} from './projectUserRecordRepository';
import { DONATION_STATUS } from '../entities/donation';
import { Donation, DONATION_STATUS } from '../entities/donation';
import { QfRound } from '../entities/qfRound';
import { ProjectRoundRecord } from '../entities/projectRoundRecord';

describe('projectUserRecordRepository', () => {
let project;
let user;
let eaRound;

beforeEach(async () => {
project = await saveProjectDirectlyToDb(createProjectData());
user = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
eaRound = await saveEARoundDirectlyToDb({
roundNumber: generateEARoundNumber(),
startDate: new Date('2024-09-01'),
endDate: new Date('2024-09-05'),
});
});

afterEach(async () => {
if (eaRound) {
Donation.delete({ earlyAccessRoundId: eaRound.id });
ProjectRoundRecord.delete({ earlyAccessRoundId: eaRound.id });

await eaRound.remove();
eaRound = null;
}
});

it('should return 0 when there is no donation', async () => {
Expand All @@ -47,6 +64,7 @@ describe('projectUserRecordRepository', () => {
...createDonationData(),
amount: verifiedDonationAmount,
status: DONATION_STATUS.VERIFIED,
earlyAccessRoundId: eaRound.id,
},
user.id,
project.id,
Expand All @@ -56,6 +74,7 @@ describe('projectUserRecordRepository', () => {
...createDonationData(),
amount: pendingDonationAmount,
status: DONATION_STATUS.PENDING,
earlyAccessRoundId: eaRound.id,
},
user.id,
project.id,
Expand All @@ -65,6 +84,7 @@ describe('projectUserRecordRepository', () => {
...createDonationData(),
amount: faildDonationAmount,
status: DONATION_STATUS.FAILED,
earlyAccessRoundId: eaRound.id,
},
user.id,
project.id,
Expand Down Expand Up @@ -92,6 +112,7 @@ describe('projectUserRecordRepository', () => {
...createDonationData(),
amount: verifiedDonationAmount,
status: DONATION_STATUS.VERIFIED,
earlyAccessRoundId: eaRound.id,
},
user.id,
project.id,
Expand All @@ -101,6 +122,7 @@ describe('projectUserRecordRepository', () => {
...createDonationData(),
amount: pendingDonationAmount,
status: DONATION_STATUS.PENDING,
earlyAccessRoundId: eaRound.id,
},
user.id,
project.id,
Expand All @@ -110,6 +132,7 @@ describe('projectUserRecordRepository', () => {
...createDonationData(),
amount: failedDonationAmount,
status: DONATION_STATUS.FAILED,
earlyAccessRoundId: eaRound.id,
},
user.id,
project.id,
Expand Down Expand Up @@ -214,6 +237,7 @@ describe('projectUserRecordRepository', () => {
...createDonationData(),
amount: donationAmount1,
status: DONATION_STATUS.VERIFIED,
earlyAccessRoundId: eaRound.id,
},
user.id,
project.id,
Expand All @@ -232,6 +256,7 @@ describe('projectUserRecordRepository', () => {
...createDonationData(),
amount: donationAmount2,
status: DONATION_STATUS.VERIFIED,
earlyAccessRoundId: eaRound.id,
},
user.id,
project.id,
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/projectUserRecordRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function updateOrCreateProjectUserRecord({
$2 AS userId,
COALESCE(SUM(CASE WHEN donation."earlyAccessRoundId" IS NOT NULL THEN donation.amount ELSE 0 END), 0) AS eaTotalDonationAmount,
COALESCE(SUM(CASE WHEN donation."qfRoundId" IS NOT NULL THEN donation.amount ELSE 0 END), 0) AS qfTotalDonationAmount,
COALESCE(SUM(donation.amount), 0) AS totalDonationAmount
COALESCE(SUM(CASE WHEN ((donation."earlyAccessRoundId" IS NOT NULL) OR (donation."qfRoundId" IS NOT NULL)) THEN donation.amount ELSE 0 END), 0) AS totalDonationAmount
FROM donation
WHERE donation."projectId" = $1
AND donation."userId" = $2
Expand Down

0 comments on commit 56dc9b5

Please sign in to comment.