Skip to content

Commit d711323

Browse files
authored
feat(me/business-units): add missing routes (#308)
Add support for get/delete/post endpoints of my-business-units.
1 parent 6840ef0 commit d711323

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

.changeset/fresh-deer-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@labdigital/commercetools-mock": minor
3+
---
4+
5+
add missing "/me/business-units/\*" endpoints

src/services/my-business-unit.test.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,86 @@ describe("MyBusinessUnit", () => {
2828
expect(response.body.count).toBeGreaterThanOrEqual(0);
2929
expect(response.body.results).toBeDefined();
3030
});
31+
32+
test("Get my business unit by ID", async () => {
33+
// First create a business unit
34+
const draft: BusinessUnitDraft = {
35+
key: "my-business-unit",
36+
unitType: "Company",
37+
name: "My Business Unit",
38+
contactEmail: "contact@example.com",
39+
};
40+
const createResponse = await supertest(ctMock.app)
41+
.post("/dummy/business-units")
42+
.send(draft);
43+
44+
expect(createResponse.status).toBe(201);
45+
46+
const response = await supertest(ctMock.app).get(
47+
`/dummy/me/business-units/${createResponse.body.id}`,
48+
);
49+
50+
expect(response.status).toBe(200);
51+
expect(response.body).toEqual(createResponse.body);
52+
});
53+
54+
test("Delete my business unit", async () => {
55+
// First create a business unit
56+
const draft: BusinessUnitDraft = {
57+
key: "my-business-unit",
58+
unitType: "Company",
59+
name: "My Business Unit",
60+
contactEmail: "contact@example.com",
61+
};
62+
const createResponse = await supertest(ctMock.app)
63+
.post("/dummy/business-units")
64+
.send(draft);
65+
66+
expect(createResponse.status).toBe(201);
67+
68+
// Now delete the business unit
69+
const deleteResponse = await supertest(ctMock.app).delete(
70+
`/dummy/me/business-units/${createResponse.body.id}`,
71+
);
72+
73+
expect(deleteResponse.status).toBe(200);
74+
expect(deleteResponse.body).toEqual(createResponse.body);
75+
76+
// Verify that the business unit is deleted
77+
const newResponse = await supertest(ctMock.app).get(
78+
`/dummy/me/business-units/${createResponse.body.id}`,
79+
);
80+
expect(newResponse.status).toBe(404);
81+
});
82+
83+
test("Update my business unit", async () => {
84+
// First create a business unit
85+
const draft: BusinessUnitDraft = {
86+
key: "my-business-unit",
87+
unitType: "Company",
88+
name: "My Business Unit",
89+
contactEmail: "contact@example.com",
90+
};
91+
const createResponse = await supertest(ctMock.app)
92+
.post("/dummy/business-units")
93+
.send(draft);
94+
95+
expect(createResponse.status).toBe(201);
96+
97+
const updateResponse = await supertest(ctMock.app)
98+
.post(`/dummy/me/business-units/${createResponse.body.id}`)
99+
.send({
100+
id: createResponse.body.id,
101+
version: createResponse.body.version,
102+
actions: [
103+
{
104+
action: "changeName",
105+
name: "Updated Business Unit Name",
106+
},
107+
],
108+
});
109+
110+
expect(updateResponse.status).toBe(200);
111+
expect(updateResponse.body.name).toBe("Updated Business Unit Name");
112+
});
31113
});

src/services/my-business-unit.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export class MyBusinessUnitService extends AbstractService {
2222
this.extraRoutes(router);
2323

2424
router.get("/business-units/", this.get.bind(this));
25+
router.get("/business-units/:id", this.getWithId.bind(this));
26+
27+
router.delete("/business-units/:id", this.deleteWithId.bind(this));
28+
29+
router.post("/business-units/", this.post.bind(this));
30+
router.post("/business-units/:id", this.postWithId.bind(this));
2531

2632
parent.use(`/${basePath}`, router);
2733
}

0 commit comments

Comments
 (0)