|
1 | 1 | import type { BusinessUnitDraft } from "@commercetools/platform-sdk"; |
2 | 2 | import supertest from "supertest"; |
3 | | -import { describe, expect, test } from "vitest"; |
| 3 | +import { afterEach, describe, expect, test } from "vitest"; |
4 | 4 | import { CommercetoolsMock } from "../index"; |
5 | 5 |
|
6 | 6 | const ctMock = new CommercetoolsMock(); |
7 | 7 |
|
8 | 8 | describe("MyBusinessUnit", () => { |
| 9 | + afterEach(() => { |
| 10 | + ctMock.clear(); |
| 11 | + }); |
| 12 | + |
9 | 13 | test("Get my business units", async () => { |
10 | 14 | // First create a business unit |
11 | 15 | const draft: BusinessUnitDraft = { |
@@ -51,6 +55,28 @@ describe("MyBusinessUnit", () => { |
51 | 55 | expect(response.body).toEqual(createResponse.body); |
52 | 56 | }); |
53 | 57 |
|
| 58 | + test("Get my business unit by key", async () => { |
| 59 | + // First create a business unit |
| 60 | + const draft: BusinessUnitDraft = { |
| 61 | + key: "my-business-unit", |
| 62 | + unitType: "Company", |
| 63 | + name: "My Business Unit", |
| 64 | + contactEmail: "[email protected]", |
| 65 | + }; |
| 66 | + const createResponse = await supertest(ctMock.app) |
| 67 | + .post("/dummy/business-units") |
| 68 | + .send(draft); |
| 69 | + |
| 70 | + expect(createResponse.status).toBe(201); |
| 71 | + |
| 72 | + const response = await supertest(ctMock.app).get( |
| 73 | + `/dummy/me/business-units/key=${createResponse.body.key}`, |
| 74 | + ); |
| 75 | + |
| 76 | + expect(response.status).toBe(200); |
| 77 | + expect(response.body).toEqual(createResponse.body); |
| 78 | + }); |
| 79 | + |
54 | 80 | test("Delete my business unit", async () => { |
55 | 81 | // First create a business unit |
56 | 82 | const draft: BusinessUnitDraft = { |
@@ -80,6 +106,35 @@ describe("MyBusinessUnit", () => { |
80 | 106 | expect(newResponse.status).toBe(404); |
81 | 107 | }); |
82 | 108 |
|
| 109 | + test("Delete my business unit by key", async () => { |
| 110 | + // First create a business unit |
| 111 | + const draft: BusinessUnitDraft = { |
| 112 | + key: "my-business-unit", |
| 113 | + unitType: "Company", |
| 114 | + name: "My Business Unit", |
| 115 | + contactEmail: "[email protected]", |
| 116 | + }; |
| 117 | + const createResponse = await supertest(ctMock.app) |
| 118 | + .post("/dummy/business-units") |
| 119 | + .send(draft); |
| 120 | + |
| 121 | + expect(createResponse.status).toBe(201); |
| 122 | + |
| 123 | + // Now delete the business unit |
| 124 | + const deleteResponse = await supertest(ctMock.app).delete( |
| 125 | + `/dummy/me/business-units/key=${createResponse.body.key}`, |
| 126 | + ); |
| 127 | + |
| 128 | + expect(deleteResponse.status).toBe(200); |
| 129 | + expect(deleteResponse.body).toEqual(createResponse.body); |
| 130 | + |
| 131 | + // Verify that the business unit is deleted |
| 132 | + const newResponse = await supertest(ctMock.app).get( |
| 133 | + `/dummy/me/business-units/key=${createResponse.body.key}`, |
| 134 | + ); |
| 135 | + expect(newResponse.status).toBe(404); |
| 136 | + }); |
| 137 | + |
83 | 138 | test("Update my business unit", async () => { |
84 | 139 | // First create a business unit |
85 | 140 | const draft: BusinessUnitDraft = { |
@@ -110,4 +165,35 @@ describe("MyBusinessUnit", () => { |
110 | 165 | expect(updateResponse.status).toBe(200); |
111 | 166 | expect(updateResponse.body.name).toBe("Updated Business Unit Name"); |
112 | 167 | }); |
| 168 | + |
| 169 | + test("Update my business unit by key", async () => { |
| 170 | + // First create a business unit |
| 171 | + const draft: BusinessUnitDraft = { |
| 172 | + key: "my-business-unit", |
| 173 | + unitType: "Company", |
| 174 | + name: "My Business Unit", |
| 175 | + contactEmail: "[email protected]", |
| 176 | + }; |
| 177 | + const createResponse = await supertest(ctMock.app) |
| 178 | + .post("/dummy/business-units") |
| 179 | + .send(draft); |
| 180 | + |
| 181 | + expect(createResponse.status).toBe(201); |
| 182 | + |
| 183 | + const updateResponse = await supertest(ctMock.app) |
| 184 | + .post(`/dummy/me/business-units/key=${createResponse.body.key}`) |
| 185 | + .send({ |
| 186 | + id: createResponse.body.id, |
| 187 | + version: createResponse.body.version, |
| 188 | + actions: [ |
| 189 | + { |
| 190 | + action: "changeName", |
| 191 | + name: "Updated Business Unit Name", |
| 192 | + }, |
| 193 | + ], |
| 194 | + }); |
| 195 | + |
| 196 | + expect(updateResponse.status).toBe(200); |
| 197 | + expect(updateResponse.body.name).toBe("Updated Business Unit Name"); |
| 198 | + }); |
113 | 199 | }); |
0 commit comments