Skip to content

Commit

Permalink
Merge pull request #345 from AppQuality/fix-freespots-cp
Browse files Browse the repository at this point in the history
fix: add groupBy at validApplications query
  • Loading branch information
d-beezee authored Jul 18, 2024
2 parents e0b5bb9 + 3935318 commit d9db054
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/routes/users/me/campaigns/_get/cap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("GET /users/me/campaigns - cap", () => {
category_id: 1,
});
await tryber.seeds().campaign_statuses();
await tryber.tables.WpAppqEvdCampaign.do().insert({
const campaign = {
start_date: new Date().toISOString().split("T")[0],
end_date: endDate,
close_date: closeDate,
Expand All @@ -42,7 +42,11 @@ describe("GET /users/me/campaigns - cap", () => {
is_public: 4,
phase_id: 20,
desired_number_of_testers: 10,
});
};
await tryber.tables.WpAppqEvdCampaign.do().insert([
{ ...campaign, id: 1 },
{ ...campaign, id: 2 },
]);

await tryber.tables.CampaignDossierData.do().insert({
id: 1,
Expand All @@ -54,6 +58,7 @@ describe("GET /users/me/campaigns - cap", () => {
await tryber.tables.WpCrowdAppqHasCandidate.do().insert([
{ campaign_id: 1, user_id: 10, accepted: -1 },
{ campaign_id: 1, user_id: 20, accepted: 0 },
{ campaign_id: 2, user_id: 30, accepted: 0 },
]);
});

Expand All @@ -71,8 +76,9 @@ describe("GET /users/me/campaigns - cap", () => {
expect(response.status).toBe(200);
expect(response.body).toHaveProperty("results");
expect(Array.isArray(response.body.results)).toBe(true);
expect(response.body.results.length).toBe(1);
expect(response.body.results.length).toBe(2);
expect(response.body.results[0]).toHaveProperty("visibility");
expect(response.body.results[0]).toHaveProperty("id", 1);
expect(response.body.results[0].visibility).toHaveProperty("freeSpots", 9);
});

Expand All @@ -83,7 +89,7 @@ describe("GET /users/me/campaigns - cap", () => {
expect(response.status).toBe(200);
expect(response.body).toHaveProperty("results");
expect(Array.isArray(response.body.results)).toBe(true);
expect(response.body.results.length).toBe(1);
expect(response.body.results.length).toBe(2);
expect(response.body.results[0]).toHaveProperty("visibility");
expect(response.body.results[0].visibility).toHaveProperty(
"totalSpots",
Expand Down
1 change: 1 addition & 0 deletions src/routes/users/me/campaigns/_get/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class RouteItem extends UserRoute<{
"campaign_id",
campaignsWithTarget.map((c) => c.id)
)
.groupBy("campaign_id")
.then((res) =>
res.map((r) => ({
campaign_id: r.campaign_id,
Expand Down

0 comments on commit d9db054

Please sign in to comment.