@labdigital/commercetools-mock 2.51.0 → 2.53.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.
Files changed (42) hide show
  1. package/dist/index.d.ts +34 -23
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +140 -13
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/lib/product-review-statistics.test.ts +349 -0
  7. package/src/lib/productSearchFilter.test.ts +77 -0
  8. package/src/lib/review-statistics.ts +58 -0
  9. package/src/product-projection-search.ts +17 -2
  10. package/src/product-search-availability.test.ts +242 -0
  11. package/src/product-search.ts +22 -4
  12. package/src/repositories/as-associate.test.ts +126 -0
  13. package/src/repositories/attribute-group.test.ts +221 -0
  14. package/src/repositories/business-unit.test.ts +425 -0
  15. package/src/repositories/business-unit.ts +57 -1
  16. package/src/repositories/channel.test.ts +374 -0
  17. package/src/repositories/customer-group.test.ts +262 -0
  18. package/src/repositories/extension.test.ts +306 -0
  19. package/src/repositories/index.test.ts +17 -0
  20. package/src/repositories/product/index.ts +22 -1
  21. package/src/repositories/product-projection.ts +8 -2
  22. package/src/repositories/review.test.ts +636 -0
  23. package/src/repositories/review.ts +145 -4
  24. package/src/repositories/subscription.test.ts +207 -0
  25. package/src/repositories/zone.test.ts +278 -0
  26. package/src/services/as-associate-cart.test.ts +58 -0
  27. package/src/services/as-associate.test.ts +34 -0
  28. package/src/services/attribute-group.test.ts +114 -0
  29. package/src/services/channel.test.ts +90 -0
  30. package/src/services/customer-group.test.ts +85 -0
  31. package/src/services/discount-code.test.ts +120 -0
  32. package/src/services/extension.test.ts +130 -0
  33. package/src/services/my-business-unit.test.ts +113 -0
  34. package/src/services/my-business-unit.ts +6 -0
  35. package/src/services/my-customer.test.ts +24 -0
  36. package/src/services/order.test.ts +18 -0
  37. package/src/services/product-discount.test.ts +146 -0
  38. package/src/services/project.test.ts +17 -0
  39. package/src/services/reviews.test.ts +230 -0
  40. package/src/services/subscription.test.ts +151 -0
  41. package/src/services/type.test.ts +127 -0
  42. package/src/services/zone.test.ts +117 -0
@@ -0,0 +1,151 @@
1
+ import type { SubscriptionDraft } from "@commercetools/platform-sdk";
2
+ import supertest from "supertest";
3
+ import { describe, expect, test } from "vitest";
4
+ import { CommercetoolsMock } from "../index";
5
+
6
+ const ctMock = new CommercetoolsMock();
7
+
8
+ describe("Subscription", () => {
9
+ test("Create subscription", async () => {
10
+ const draft: SubscriptionDraft = {
11
+ key: "order-notifications",
12
+ destination: {
13
+ type: "SQS",
14
+ queueUrl: "https://sqs.us-east-1.amazonaws.com/123456789/orders",
15
+ accessKey: "AKIAIOSFODNN7EXAMPLE",
16
+ accessSecret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
17
+ region: "us-east-1",
18
+ },
19
+ messages: [
20
+ {
21
+ resourceTypeId: "order",
22
+ types: ["OrderCreated", "OrderStateChanged"],
23
+ },
24
+ ],
25
+ };
26
+ const response = await supertest(ctMock.app)
27
+ .post("/dummy/subscriptions")
28
+ .send(draft);
29
+
30
+ expect(response.status).toBe(201);
31
+
32
+ expect(response.body).toEqual({
33
+ changes: [],
34
+ createdAt: expect.anything(),
35
+ destination: {
36
+ accessKey: "AKIAIOSFODNN7EXAMPLE",
37
+ accessSecret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
38
+ queueUrl: "https://sqs.us-east-1.amazonaws.com/123456789/orders",
39
+ region: "us-east-1",
40
+ type: "SQS",
41
+ },
42
+ events: [],
43
+ format: {
44
+ type: "Platform",
45
+ },
46
+ id: expect.anything(),
47
+ key: "order-notifications",
48
+ lastModifiedAt: expect.anything(),
49
+ messages: [
50
+ {
51
+ resourceTypeId: "order",
52
+ types: ["OrderCreated", "OrderStateChanged"],
53
+ },
54
+ ],
55
+ status: "Healthy",
56
+ version: 1,
57
+ });
58
+ });
59
+
60
+ test("Get subscription", async () => {
61
+ const draft: SubscriptionDraft = {
62
+ key: "test-subscription",
63
+ destination: {
64
+ type: "SQS",
65
+ queueUrl: "https://sqs.us-east-1.amazonaws.com/123456789/test",
66
+ accessKey: "AKIAIOSFODNN7EXAMPLE",
67
+ accessSecret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
68
+ region: "us-east-1",
69
+ },
70
+ messages: [
71
+ {
72
+ resourceTypeId: "customer",
73
+ types: ["CustomerCreated"],
74
+ },
75
+ ],
76
+ };
77
+ const createResponse = await supertest(ctMock.app)
78
+ .post("/dummy/subscriptions")
79
+ .send(draft);
80
+
81
+ expect(createResponse.status).toBe(201);
82
+
83
+ const response = await supertest(ctMock.app).get(
84
+ `/dummy/subscriptions/${createResponse.body.id}`,
85
+ );
86
+
87
+ expect(response.status).toBe(200);
88
+ expect(response.body).toEqual(createResponse.body);
89
+ });
90
+
91
+ test("Get subscription by key", async () => {
92
+ const draft: SubscriptionDraft = {
93
+ key: "key-subscription",
94
+ destination: {
95
+ type: "SQS",
96
+ queueUrl: "https://sqs.us-east-1.amazonaws.com/123456789/key",
97
+ accessKey: "AKIAIOSFODNN7EXAMPLE",
98
+ accessSecret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
99
+ region: "us-east-1",
100
+ },
101
+ messages: [
102
+ {
103
+ resourceTypeId: "product",
104
+ types: ["ProductPublished"],
105
+ },
106
+ ],
107
+ };
108
+ const createResponse = await supertest(ctMock.app)
109
+ .post("/dummy/subscriptions")
110
+ .send(draft);
111
+
112
+ expect(createResponse.status).toBe(201);
113
+
114
+ const response = await supertest(ctMock.app).get(
115
+ "/dummy/subscriptions/key=key-subscription",
116
+ );
117
+
118
+ expect(response.status).toBe(200);
119
+ expect(response.body).toEqual(createResponse.body);
120
+ });
121
+
122
+ test("Query subscriptions", async () => {
123
+ const draft: SubscriptionDraft = {
124
+ key: "query-subscription",
125
+ destination: {
126
+ type: "SQS",
127
+ queueUrl: "https://sqs.us-east-1.amazonaws.com/123456789/query",
128
+ accessKey: "AKIAIOSFODNN7EXAMPLE",
129
+ accessSecret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
130
+ region: "us-east-1",
131
+ },
132
+ messages: [
133
+ {
134
+ resourceTypeId: "cart",
135
+ types: ["CartCreated"],
136
+ },
137
+ ],
138
+ };
139
+ const createResponse = await supertest(ctMock.app)
140
+ .post("/dummy/subscriptions")
141
+ .send(draft);
142
+
143
+ expect(createResponse.status).toBe(201);
144
+
145
+ const response = await supertest(ctMock.app).get("/dummy/subscriptions");
146
+
147
+ expect(response.status).toBe(200);
148
+ expect(response.body.count).toBeGreaterThan(0);
149
+ expect(response.body.results).toContainEqual(createResponse.body);
150
+ });
151
+ });
@@ -0,0 +1,127 @@
1
+ import type { TypeDraft } from "@commercetools/platform-sdk";
2
+ import supertest from "supertest";
3
+ import { describe, expect, test } from "vitest";
4
+ import { CommercetoolsMock } from "../index";
5
+
6
+ const ctMock = new CommercetoolsMock();
7
+
8
+ describe("Type", () => {
9
+ test("Create type", async () => {
10
+ const draft: TypeDraft = {
11
+ key: "my-custom-type",
12
+ name: {
13
+ en: "My Custom Type",
14
+ },
15
+ resourceTypeIds: ["category"],
16
+ fieldDefinitions: [
17
+ {
18
+ name: "customField",
19
+ label: {
20
+ en: "Custom Field",
21
+ },
22
+ required: false,
23
+ type: {
24
+ name: "String",
25
+ },
26
+ },
27
+ ],
28
+ };
29
+ const response = await supertest(ctMock.app)
30
+ .post("/dummy/types")
31
+ .send(draft);
32
+
33
+ expect(response.status).toBe(201);
34
+
35
+ expect(response.body).toEqual({
36
+ createdAt: expect.anything(),
37
+ fieldDefinitions: [
38
+ {
39
+ label: {
40
+ en: "Custom Field",
41
+ },
42
+ name: "customField",
43
+ required: false,
44
+ type: {
45
+ name: "String",
46
+ },
47
+ },
48
+ ],
49
+ id: expect.anything(),
50
+ key: "my-custom-type",
51
+ lastModifiedAt: expect.anything(),
52
+ name: {
53
+ en: "My Custom Type",
54
+ },
55
+ resourceTypeIds: ["category"],
56
+ version: 1,
57
+ });
58
+ });
59
+
60
+ test("Get type", async () => {
61
+ const draft: TypeDraft = {
62
+ key: "test-type",
63
+ name: {
64
+ en: "Test Type",
65
+ },
66
+ resourceTypeIds: ["product"],
67
+ fieldDefinitions: [],
68
+ };
69
+ const createResponse = await supertest(ctMock.app)
70
+ .post("/dummy/types")
71
+ .send(draft);
72
+
73
+ expect(createResponse.status).toBe(201);
74
+
75
+ const response = await supertest(ctMock.app).get(
76
+ `/dummy/types/${createResponse.body.id}`,
77
+ );
78
+
79
+ expect(response.status).toBe(200);
80
+ expect(response.body).toEqual(createResponse.body);
81
+ });
82
+
83
+ test("Get type by key", async () => {
84
+ const draft: TypeDraft = {
85
+ key: "key-type",
86
+ name: {
87
+ en: "Key Type",
88
+ },
89
+ resourceTypeIds: ["customer"],
90
+ fieldDefinitions: [],
91
+ };
92
+ const createResponse = await supertest(ctMock.app)
93
+ .post("/dummy/types")
94
+ .send(draft);
95
+
96
+ expect(createResponse.status).toBe(201);
97
+
98
+ const response = await supertest(ctMock.app).get(
99
+ "/dummy/types/key=key-type",
100
+ );
101
+
102
+ expect(response.status).toBe(200);
103
+ expect(response.body).toEqual(createResponse.body);
104
+ });
105
+
106
+ test("Query types", async () => {
107
+ const draft: TypeDraft = {
108
+ key: "query-type",
109
+ name: {
110
+ en: "Query Type",
111
+ },
112
+ resourceTypeIds: ["order"],
113
+ fieldDefinitions: [],
114
+ };
115
+ const createResponse = await supertest(ctMock.app)
116
+ .post("/dummy/types")
117
+ .send(draft);
118
+
119
+ expect(createResponse.status).toBe(201);
120
+
121
+ const response = await supertest(ctMock.app).get("/dummy/types");
122
+
123
+ expect(response.status).toBe(200);
124
+ expect(response.body.count).toBeGreaterThan(0);
125
+ expect(response.body.results).toContainEqual(createResponse.body);
126
+ });
127
+ });
@@ -0,0 +1,117 @@
1
+ import type { ZoneDraft } from "@commercetools/platform-sdk";
2
+ import supertest from "supertest";
3
+ import { describe, expect, test } from "vitest";
4
+ import { CommercetoolsMock } from "../index";
5
+
6
+ const ctMock = new CommercetoolsMock();
7
+
8
+ describe("Zone", () => {
9
+ test("Create zone", async () => {
10
+ const draft: ZoneDraft = {
11
+ key: "europe-zone",
12
+ name: "Europe",
13
+ locations: [
14
+ {
15
+ country: "DE",
16
+ },
17
+ {
18
+ country: "NL",
19
+ },
20
+ ],
21
+ };
22
+ const response = await supertest(ctMock.app)
23
+ .post("/dummy/zones")
24
+ .send(draft);
25
+
26
+ expect(response.status).toBe(201);
27
+
28
+ expect(response.body).toEqual({
29
+ createdAt: expect.anything(),
30
+ description: undefined,
31
+ id: expect.anything(),
32
+ key: "europe-zone",
33
+ lastModifiedAt: expect.anything(),
34
+ locations: [
35
+ {
36
+ country: "DE",
37
+ },
38
+ {
39
+ country: "NL",
40
+ },
41
+ ],
42
+ name: "Europe",
43
+ version: 1,
44
+ });
45
+ });
46
+
47
+ test("Get zone", async () => {
48
+ const draft: ZoneDraft = {
49
+ key: "test-zone",
50
+ name: "Test Zone",
51
+ locations: [
52
+ {
53
+ country: "US",
54
+ },
55
+ ],
56
+ };
57
+ const createResponse = await supertest(ctMock.app)
58
+ .post("/dummy/zones")
59
+ .send(draft);
60
+
61
+ expect(createResponse.status).toBe(201);
62
+
63
+ const response = await supertest(ctMock.app).get(
64
+ `/dummy/zones/${createResponse.body.id}`,
65
+ );
66
+
67
+ expect(response.status).toBe(200);
68
+ expect(response.body).toEqual(createResponse.body);
69
+ });
70
+
71
+ test("Get zone by key", async () => {
72
+ const draft: ZoneDraft = {
73
+ key: "key-zone",
74
+ name: "Key Zone",
75
+ locations: [
76
+ {
77
+ country: "CA",
78
+ },
79
+ ],
80
+ };
81
+ const createResponse = await supertest(ctMock.app)
82
+ .post("/dummy/zones")
83
+ .send(draft);
84
+
85
+ expect(createResponse.status).toBe(201);
86
+
87
+ const response = await supertest(ctMock.app).get(
88
+ "/dummy/zones/key=key-zone",
89
+ );
90
+
91
+ expect(response.status).toBe(200);
92
+ expect(response.body).toEqual(createResponse.body);
93
+ });
94
+
95
+ test("Query zones", async () => {
96
+ const draft: ZoneDraft = {
97
+ key: "query-zone",
98
+ name: "Query Zone",
99
+ locations: [
100
+ {
101
+ country: "FR",
102
+ },
103
+ ],
104
+ };
105
+ const createResponse = await supertest(ctMock.app)
106
+ .post("/dummy/zones")
107
+ .send(draft);
108
+
109
+ expect(createResponse.status).toBe(201);
110
+
111
+ const response = await supertest(ctMock.app).get("/dummy/zones");
112
+
113
+ expect(response.status).toBe(200);
114
+ expect(response.body.count).toBeGreaterThan(0);
115
+ expect(response.body.results).toContainEqual(createResponse.body);
116
+ });
117
+ });