@labdigital/commercetools-mock 2.61.3 → 2.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +9 -7
- package/dist/index.mjs +205 -178
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/repositories/as-associate.test.ts +25 -0
- package/src/repositories/as-associate.ts +2 -0
- package/src/repositories/index.ts +2 -0
- package/src/services/as-associate-shopping-list.test.ts +58 -0
- package/src/services/as-associate-shopping-list.ts +33 -0
- package/src/services/as-associate.ts +8 -0
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ShoppingListDraft } from "@commercetools/platform-sdk";
|
|
1
2
|
import { describe, expect, test } from "vitest";
|
|
2
3
|
import type { Config } from "#src/config.ts";
|
|
3
4
|
import { InMemoryStorage } from "#src/storage/index.ts";
|
|
@@ -5,6 +6,7 @@ import {
|
|
|
5
6
|
AsAssociateCartRepository,
|
|
6
7
|
AsAssociateOrderRepository,
|
|
7
8
|
AsAssociateQuoteRequestRepository,
|
|
9
|
+
AsAssociateShoppingListRepository,
|
|
8
10
|
} from "./as-associate.ts";
|
|
9
11
|
import { CustomerRepository } from "./customer/index.ts";
|
|
10
12
|
|
|
@@ -123,4 +125,27 @@ describe("As Associate Repositories", () => {
|
|
|
123
125
|
expect(retrieved).toBeDefined();
|
|
124
126
|
expect(retrieved?.id).toBe(quoteRequest.id);
|
|
125
127
|
});
|
|
128
|
+
|
|
129
|
+
test("AsAssociateShoppingListRepository can create and retrieve shopping lists", () => {
|
|
130
|
+
const repository = new AsAssociateShoppingListRepository(config);
|
|
131
|
+
const ctx = { projectKey: "test-project" };
|
|
132
|
+
|
|
133
|
+
const shoppingListDraft: ShoppingListDraft = {
|
|
134
|
+
name: { "en-US": "My Shopping List" },
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const shoppingList = repository.create(ctx, shoppingListDraft);
|
|
138
|
+
expect(shoppingList.id).toBeDefined();
|
|
139
|
+
expect(shoppingList.version).toBe(1);
|
|
140
|
+
|
|
141
|
+
// Test query
|
|
142
|
+
const result = repository.query(ctx);
|
|
143
|
+
expect(result.count).toBe(1);
|
|
144
|
+
expect(result.results[0].id).toBe(shoppingList.id);
|
|
145
|
+
|
|
146
|
+
// Test get
|
|
147
|
+
const retrieved = repository.get(ctx, shoppingList.id);
|
|
148
|
+
expect(retrieved).toBeDefined();
|
|
149
|
+
expect(retrieved?.id).toBe(shoppingList.id);
|
|
150
|
+
});
|
|
126
151
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { CartRepository } from "./cart/index.ts";
|
|
2
2
|
import { OrderRepository } from "./order/index.ts";
|
|
3
3
|
import { QuoteRequestRepository } from "./quote-request/index.ts";
|
|
4
|
+
import { ShoppingListRepository } from "./shopping-list/index.ts";
|
|
4
5
|
|
|
5
6
|
export class AsAssociateOrderRepository extends OrderRepository {}
|
|
6
7
|
export class AsAssociateCartRepository extends CartRepository {}
|
|
7
8
|
export class AsAssociateQuoteRequestRepository extends QuoteRequestRepository {}
|
|
9
|
+
export class AsAssociateShoppingListRepository extends ShoppingListRepository {}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
AsAssociateCartRepository,
|
|
5
5
|
AsAssociateOrderRepository,
|
|
6
6
|
AsAssociateQuoteRequestRepository,
|
|
7
|
+
AsAssociateShoppingListRepository,
|
|
7
8
|
} from "./as-associate.ts";
|
|
8
9
|
import { AssociateRoleRepository } from "./associate-role.ts";
|
|
9
10
|
import { AttributeGroupRepository } from "./attribute-group.ts";
|
|
@@ -53,6 +54,7 @@ export const createRepositories = (config: Config) => ({
|
|
|
53
54
|
cart: new AsAssociateCartRepository(config),
|
|
54
55
|
order: new AsAssociateOrderRepository(config),
|
|
55
56
|
"quote-request": new AsAssociateQuoteRequestRepository(config),
|
|
57
|
+
"shopping-list": new AsAssociateShoppingListRepository(config),
|
|
56
58
|
},
|
|
57
59
|
"associate-role": new AssociateRoleRepository(config),
|
|
58
60
|
"attribute-group": new AttributeGroupRepository(config),
|
|
@@ -0,0 +1,58 @@
|
|
|
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,0 +1,33 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import type { ShoppingListRepository } from "#src/repositories/shopping-list/index.ts";
|
|
3
|
+
import AbstractService from "./abstract.ts";
|
|
4
|
+
|
|
5
|
+
export class AsAssociateShoppingListService extends AbstractService {
|
|
6
|
+
public repository: ShoppingListRepository;
|
|
7
|
+
|
|
8
|
+
constructor(parent: Router, repository: ShoppingListRepository) {
|
|
9
|
+
super(parent);
|
|
10
|
+
this.repository = repository;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getBasePath() {
|
|
14
|
+
return "shopping-lists";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
registerRoutes(parent: Router) {
|
|
18
|
+
const basePath = this.getBasePath();
|
|
19
|
+
const router = Router({ mergeParams: true });
|
|
20
|
+
|
|
21
|
+
this.extraRoutes(router);
|
|
22
|
+
|
|
23
|
+
router.get("/", this.get.bind(this));
|
|
24
|
+
router.get("/:id", this.getWithId.bind(this));
|
|
25
|
+
|
|
26
|
+
router.delete("/:id", this.deleteWithId.bind(this));
|
|
27
|
+
|
|
28
|
+
router.post("/", this.post.bind(this));
|
|
29
|
+
router.post("/:id", this.postWithId.bind(this));
|
|
30
|
+
|
|
31
|
+
parent.use(`/${basePath}`, router);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -3,15 +3,18 @@ import type {
|
|
|
3
3
|
AsAssociateCartRepository,
|
|
4
4
|
AsAssociateOrderRepository,
|
|
5
5
|
AsAssociateQuoteRequestRepository,
|
|
6
|
+
AsAssociateShoppingListRepository,
|
|
6
7
|
} from "#src/repositories/as-associate.ts";
|
|
7
8
|
import { AsAssociateCartService } from "./as-associate-cart.ts";
|
|
8
9
|
import { AsAssociateOrderService } from "./as-associate-order.ts";
|
|
9
10
|
import { AsAssociateQuoteRequestService } from "./as-associate-quote-request.ts";
|
|
11
|
+
import { AsAssociateShoppingListService } from "./as-associate-shopping-list.ts";
|
|
10
12
|
|
|
11
13
|
type Repositories = {
|
|
12
14
|
cart: AsAssociateCartRepository;
|
|
13
15
|
order: AsAssociateOrderRepository;
|
|
14
16
|
"quote-request": AsAssociateQuoteRequestRepository;
|
|
17
|
+
"shopping-list": AsAssociateShoppingListRepository;
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
export class AsAssociateService {
|
|
@@ -21,6 +24,7 @@ export class AsAssociateService {
|
|
|
21
24
|
cart: AsAssociateCartService;
|
|
22
25
|
order: AsAssociateOrderService;
|
|
23
26
|
"quote-request": AsAssociateQuoteRequestService;
|
|
27
|
+
"shopping-list": AsAssociateShoppingListService;
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
constructor(parent: Router, repositories: Repositories) {
|
|
@@ -33,6 +37,10 @@ export class AsAssociateService {
|
|
|
33
37
|
this.router,
|
|
34
38
|
repositories["quote-request"],
|
|
35
39
|
),
|
|
40
|
+
"shopping-list": new AsAssociateShoppingListService(
|
|
41
|
+
this.router,
|
|
42
|
+
repositories["shopping-list"],
|
|
43
|
+
),
|
|
36
44
|
};
|
|
37
45
|
parent.use(
|
|
38
46
|
"/as-associate/:associateId/in-business-unit/key=:businessUnitId",
|