Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/routes/dossiers/campaignId/humanResources/_put/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ describe("Route PUT/dossiers/:campaignId/humanResources", () => {
await tryber.tables.CampaignHumanResources.do().delete();
});

it("Should return 200 if body is empty and simply delete all human resources", async () => {
const response = await request(app)
.put("/dossiers/1/humanResources")
.send([])
.set("Authorization", 'Bearer tester olp {"appq_campaign":[1]}');
const humanResources = await request(app)
.get("/dossiers/1/humanResources")
.set("Authorization", 'Bearer tester olp {"appq_campaign":[1]}')
.then((res) => res.body.items);
expect(humanResources).toHaveLength(0);
expect(response.status).toBe(200);
});

it("Should remove the old records and update the human resources", async () => {
const response = await request(app)
.put("/dossiers/1/humanResources")
Expand Down
4 changes: 4 additions & 0 deletions src/routes/dossiers/campaignId/humanResources/_put/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export default class RouteItem extends CampaignRoute<{
.delete()
.where("campaign_id", this.cp_id);

if (body.length === 0) {
return;
}

await tryber.tables.CampaignHumanResources.do().insert([
...body.map((item) => ({
campaign_id: this.cp_id,
Expand Down
Loading