|
| 1 | +import supertest from "supertest"; |
| 2 | +import { describe, expect, test } from "vitest"; |
| 3 | +import { CommercetoolsMock } from "../index.ts"; |
| 4 | + |
| 5 | +const ctMock = new CommercetoolsMock(); |
| 6 | +const projectKey = "dummy"; |
| 7 | +const customerId = "5fac8fca-2484-4b14-a1d1-cfdce2f8d3c4"; |
| 8 | +const businessUnitKey = "test-business-unit"; |
| 9 | + |
| 10 | +describe("AsAssociateShoppingList", () => { |
| 11 | + test("Create shopping list", async () => { |
| 12 | + const draft = { |
| 13 | + name: { en: "My list" }, |
| 14 | + }; |
| 15 | + const response = await supertest(ctMock.app) |
| 16 | + .post( |
| 17 | + `/${projectKey}/as-associate/${customerId}/in-business-unit/key=${businessUnitKey}/shopping-lists`, |
| 18 | + ) |
| 19 | + .send(draft); |
| 20 | + |
| 21 | + expect(response.status).toBe(201); |
| 22 | + expect(response.body.id).toBeDefined(); |
| 23 | + }); |
| 24 | + |
| 25 | + test("Get shopping list", async () => { |
| 26 | + const createResponse = await supertest(ctMock.app) |
| 27 | + .post( |
| 28 | + `/${projectKey}/as-associate/${customerId}/in-business-unit/key=${businessUnitKey}/shopping-lists`, |
| 29 | + ) |
| 30 | + .send({ name: { en: "Groceries" } }); |
| 31 | + |
| 32 | + expect(createResponse.status).toBe(201); |
| 33 | + |
| 34 | + const response = await supertest(ctMock.app).get( |
| 35 | + `/${projectKey}/as-associate/${customerId}/in-business-unit/key=${businessUnitKey}/shopping-lists/${createResponse.body.id}`, |
| 36 | + ); |
| 37 | + |
| 38 | + expect(response.status).toBe(200); |
| 39 | + expect(response.body).toEqual(createResponse.body); |
| 40 | + }); |
| 41 | + |
| 42 | + test("Query shopping lists", async () => { |
| 43 | + const createResponse = await supertest(ctMock.app) |
| 44 | + .post( |
| 45 | + `/${projectKey}/as-associate/${customerId}/in-business-unit/key=${businessUnitKey}/shopping-lists`, |
| 46 | + ) |
| 47 | + .send({ name: { en: "Errands" } }); |
| 48 | + |
| 49 | + expect(createResponse.status).toBe(201); |
| 50 | + |
| 51 | + const response = await supertest(ctMock.app).get( |
| 52 | + `/${projectKey}/as-associate/${customerId}/in-business-unit/key=${businessUnitKey}/shopping-lists`, |
| 53 | + ); |
| 54 | + |
| 55 | + expect(response.status).toBe(200); |
| 56 | + expect(response.body.count).toBeGreaterThan(0); |
| 57 | + }); |
| 58 | +}); |
0 commit comments