Skip to content

Commit

Permalink
Fix instant boosting sort
Browse files Browse the repository at this point in the history
related to #Giveth/giveth-dapps-v2/4844
  • Loading branch information
mohammadranjbarz committed Oct 18, 2024
1 parent 7676e67 commit 041b4fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/repositories/projectRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
break;
case SortingField.InstantBoosting: // This is our default sorting
query
.addOrderBy('project.isGivbackEligible', 'DESC') // Primary sorting condition
.addOrderBy('project.verified', 'DESC') // Secondary sorting condition
.addOrderBy(
'projectInstantPower.totalPower',
OrderDirection.DESC,
'NULLS LAST',
);
)
.addOrderBy('project.isGivbackEligible', 'DESC') // Primary sorting condition
.addOrderBy('project.verified', 'DESC'); // Secondary sorting condition

if (isFilterByQF) {
query.addOrderBy(
'project.sumDonationValueUsdForActiveQfRound',
Expand Down
21 changes: 17 additions & 4 deletions src/resolvers/projectResolver.allProject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,19 +543,32 @@ function allProjectsTestCases() {
// await qfRound.save();
// });

it('should return projects, sort by project instant power DESC', async () => {
it.only('should return projects, sort by project instant power DESC', async () => {
await PowerBoosting.clear();
await InstantPowerBalance.clear();

const user1 = await saveUserDirectlyToDb(generateRandomEtheriumAddress());
const user2 = await saveUserDirectlyToDb(generateRandomEtheriumAddress());

const project1 = await saveProjectDirectlyToDb(createProjectData());
const project2 = await saveProjectDirectlyToDb(createProjectData());
const project3 = await saveProjectDirectlyToDb(createProjectData());
const project1 = await saveProjectDirectlyToDb({
...createProjectData(),
verified: true,
isGivbackEligible: true,
});
const project2 = await saveProjectDirectlyToDb({
...createProjectData(),
verified: true,
isGivbackEligible: false,
});
const project3 = await saveProjectDirectlyToDb({
...createProjectData(),
verified: true,
isGivbackEligible: true,
});
const project4 = await saveProjectDirectlyToDb({
...createProjectData(),
verified: false,
isGivbackEligible: false,
}); // Not boosted -Not verified project
await saveProjectDirectlyToDb(createProjectData()); // Not boosted project

Expand Down
4 changes: 2 additions & 2 deletions test/pre-test-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import { ProjectActualMatchingViewV161717646612482 } from '../migration/17176466
import { LastSnapshotProjectPowerViewV21717648491606 } from '../migration/1717648491606-LastSnapshotProjectPowerView_V2';
import { ProjectFuturePowerViewV21717643016553 } from '../migration/1717643016553-ProjectFuturePowerView_V2';
import { ProjectUserInstantPowerViewV21717644442966 } from '../migration/1717644442966-ProjectUserInstantPowerView_V2';
import { ProjectInstantPowerViewV21717648653115 } from '../migration/1717648653115-ProjectInstantPowerView_V2';
import { UserProjectPowerViewV21717645768886 } from '../migration/1717645768886-UserProjectPowerView_V2';
import { ProjectGivbackRankViewV31725260193333 } from '../migration/1725260193333-projectGivbackRankView';
import { ProjectInstantPowerViewV31724223781248 } from '../migration/1724223781248-ProjectInstantPowerViewV3';

async function seedDb() {
await seedUsers();
Expand Down Expand Up @@ -538,7 +538,7 @@ async function runMigrations() {
queryRunner,
);
await new createOrganisatioTokenTable1646302349926().up(queryRunner);
await new ProjectInstantPowerViewV21717648653115().up(queryRunner);
await new ProjectInstantPowerViewV31724223781248().up(queryRunner);
await new ProjectEstimatedMatchingViewV21717646357435().up(queryRunner);
await new ProjectUserInstantPowerViewV21717644442966().up(queryRunner);
await new TakePowerBoostingSnapshotProcedureSecondVersion1690723242749().up(
Expand Down

0 comments on commit 041b4fd

Please sign in to comment.