@labdigital/commercetools-mock 2.65.1 → 3.0.0-beta.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/README.md +31 -8
- package/dist/abstract-BKFcva6S.mjs +1044 -0
- package/dist/abstract-BKFcva6S.mjs.map +1 -0
- package/dist/config-BcNSzPZz.d.mts +1718 -0
- package/dist/index.d.mts +50 -1633
- package/dist/index.mjs +3771 -2654
- package/dist/index.mjs.map +1 -1
- package/dist/storage/sqlite.d.mts +59 -0
- package/dist/storage/sqlite.mjs +234 -0
- package/dist/storage/sqlite.mjs.map +1 -0
- package/package.json +26 -29
- package/src/ctMock.ts +125 -136
- package/src/helpers.ts +14 -6
- package/src/index.ts +5 -0
- package/src/lib/masking.ts +4 -5
- package/src/lib/product-review-statistics.test.ts +257 -294
- package/src/lib/review-statistics.ts +17 -4
- package/src/oauth/helpers.ts +7 -4
- package/src/oauth/server.test.ts +102 -62
- package/src/oauth/server.ts +215 -213
- package/src/oauth/store.ts +20 -6
- package/src/orderSearch.ts +3 -3
- package/src/product-projection-search.ts +38 -20
- package/src/product-search-availability.test.ts +31 -52
- package/src/product-search.ts +19 -10
- package/src/projectAPI.ts +6 -22
- package/src/repositories/abstract.ts +182 -48
- package/src/repositories/as-associate.test.ts +19 -19
- package/src/repositories/associate-role.ts +12 -23
- package/src/repositories/attribute-group.test.ts +23 -23
- package/src/repositories/attribute-group.ts +6 -4
- package/src/repositories/business-unit.test.ts +63 -57
- package/src/repositories/business-unit.ts +107 -55
- package/src/repositories/cart/actions.ts +96 -65
- package/src/repositories/cart/helpers.ts +15 -11
- package/src/repositories/cart/index.test.ts +136 -30
- package/src/repositories/cart/index.ts +76 -59
- package/src/repositories/cart-discount/actions.ts +12 -44
- package/src/repositories/cart-discount/index.ts +20 -8
- package/src/repositories/category/actions.ts +27 -27
- package/src/repositories/category/index.test.ts +13 -9
- package/src/repositories/category/index.ts +40 -23
- package/src/repositories/channel.test.ts +53 -51
- package/src/repositories/channel.ts +12 -22
- package/src/repositories/custom-object.ts +34 -25
- package/src/repositories/customer/actions.ts +47 -25
- package/src/repositories/customer/index.test.ts +11 -11
- package/src/repositories/customer/index.ts +65 -35
- package/src/repositories/customer-group.test.ts +44 -42
- package/src/repositories/customer-group.ts +12 -22
- package/src/repositories/discount-code/actions.ts +3 -19
- package/src/repositories/discount-code/index.ts +9 -4
- package/src/repositories/discount-group/index.ts +8 -3
- package/src/repositories/extension.test.ts +27 -27
- package/src/repositories/extension.ts +10 -5
- package/src/repositories/helpers.ts +126 -47
- package/src/repositories/inventory-entry/actions.ts +3 -24
- package/src/repositories/inventory-entry/index.ts +19 -11
- package/src/repositories/my-customer.ts +13 -12
- package/src/repositories/my-order.ts +5 -2
- package/src/repositories/order/actions.ts +89 -56
- package/src/repositories/order/index.test.ts +36 -31
- package/src/repositories/order/index.ts +83 -49
- package/src/repositories/order-edit.ts +8 -3
- package/src/repositories/payment/actions.ts +64 -44
- package/src/repositories/payment/helpers.ts +3 -3
- package/src/repositories/payment/index.ts +28 -12
- package/src/repositories/product/actions.ts +133 -98
- package/src/repositories/product/helpers.ts +29 -16
- package/src/repositories/product/index.ts +42 -25
- package/src/repositories/product-discount.ts +6 -4
- package/src/repositories/product-projection.ts +41 -21
- package/src/repositories/product-selection.ts +8 -15
- package/src/repositories/product-tailoring.ts +22 -3
- package/src/repositories/product-type.ts +45 -4
- package/src/repositories/project.ts +57 -13
- package/src/repositories/quote/actions.ts +5 -28
- package/src/repositories/quote/index.ts +29 -6
- package/src/repositories/quote-request/actions.ts +5 -28
- package/src/repositories/quote-request/index.test.ts +3 -3
- package/src/repositories/quote-request/index.ts +31 -11
- package/src/repositories/quote-staged/actions.ts +5 -28
- package/src/repositories/quote-staged/index.ts +22 -8
- package/src/repositories/recurrence-policy/index.ts +6 -4
- package/src/repositories/recurring-order/actions.ts +7 -32
- package/src/repositories/recurring-order/index.ts +8 -6
- package/src/repositories/review.test.ts +147 -142
- package/src/repositories/review.ts +31 -37
- package/src/repositories/shipping-method/actions.ts +11 -28
- package/src/repositories/shipping-method/index.ts +26 -15
- package/src/repositories/shopping-list/actions.ts +21 -31
- package/src/repositories/shopping-list/index.ts +44 -22
- package/src/repositories/standalone-price.ts +6 -4
- package/src/repositories/state.ts +15 -9
- package/src/repositories/store.ts +21 -32
- package/src/repositories/subscription.test.ts +22 -22
- package/src/repositories/subscription.ts +8 -3
- package/src/repositories/tax-category/index.ts +8 -3
- package/src/repositories/type/actions.ts +21 -3
- package/src/repositories/type/index.ts +5 -3
- package/src/repositories/zone.test.ts +112 -77
- package/src/repositories/zone.ts +5 -3
- package/src/schemas/generated/associate-role.ts +13 -0
- package/src/schemas/generated/attribute-group.ts +12 -0
- package/src/schemas/generated/business-unit.ts +38 -0
- package/src/schemas/generated/cart-discount.ts +33 -0
- package/src/schemas/generated/cart.ts +61 -0
- package/src/schemas/generated/category.ts +25 -0
- package/src/schemas/generated/channel.ts +21 -0
- package/src/schemas/generated/common.ts +1372 -0
- package/src/schemas/generated/custom-object.ts +11 -0
- package/src/schemas/generated/customer-group.ts +11 -0
- package/src/schemas/generated/customer.ts +47 -0
- package/src/schemas/generated/discount-code.ts +25 -0
- package/src/schemas/generated/discount-group.ts +13 -0
- package/src/schemas/generated/extension.ts +15 -0
- package/src/schemas/generated/index.ts +42 -0
- package/src/schemas/generated/inventory-entry.ts +20 -0
- package/src/schemas/generated/my-quote-request.ts +10 -0
- package/src/schemas/generated/order-edit.ts +18 -0
- package/src/schemas/generated/order-from-cart.ts +25 -0
- package/src/schemas/generated/payment.ts +30 -0
- package/src/schemas/generated/product-discount.ts +20 -0
- package/src/schemas/generated/product-selection.ts +18 -0
- package/src/schemas/generated/product-tailoring.ts +26 -0
- package/src/schemas/generated/product-type.ts +12 -0
- package/src/schemas/generated/product.ts +37 -0
- package/src/schemas/generated/quote-request.ts +19 -0
- package/src/schemas/generated/quote.ts +18 -0
- package/src/schemas/generated/recurrence-policy.ts +15 -0
- package/src/schemas/generated/recurring-order.ts +19 -0
- package/src/schemas/generated/review.ts +24 -0
- package/src/schemas/generated/shipping-method.ts +24 -0
- package/src/schemas/generated/shopping-list.ts +28 -0
- package/src/schemas/generated/staged-quote.ts +18 -0
- package/src/schemas/generated/standalone-price.ts +32 -0
- package/src/schemas/generated/state.ts +20 -0
- package/src/schemas/generated/store.ts +23 -0
- package/src/schemas/generated/subscription.ts +20 -0
- package/src/schemas/generated/tax-category.ts +12 -0
- package/src/schemas/generated/type.ts +17 -0
- package/src/schemas/generated/zone.ts +12 -0
- package/src/schemas/update-request.ts +3 -5
- package/src/server.ts +32 -4
- package/src/services/abstract.ts +207 -101
- package/src/services/as-associate-cart.test.ts +28 -36
- package/src/services/as-associate-cart.ts +15 -12
- package/src/services/as-associate-order.test.ts +33 -40
- package/src/services/as-associate-order.ts +15 -12
- package/src/services/as-associate-quote-request.ts +15 -12
- package/src/services/as-associate-shopping-list.test.ts +25 -35
- package/src/services/as-associate-shopping-list.ts +15 -12
- package/src/services/as-associate.test.ts +21 -15
- package/src/services/as-associate.ts +23 -22
- package/src/services/associate-roles.test.ts +16 -22
- package/src/services/associate-roles.ts +2 -2
- package/src/services/attribute-group.test.ts +40 -44
- package/src/services/attribute-group.ts +2 -2
- package/src/services/business-units.test.ts +227 -163
- package/src/services/business-units.ts +2 -2
- package/src/services/cart-discount.test.ts +253 -187
- package/src/services/cart-discount.ts +2 -2
- package/src/services/cart.test.ts +833 -832
- package/src/services/cart.ts +31 -12
- package/src/services/category.test.ts +208 -130
- package/src/services/category.ts +2 -2
- package/src/services/channel.test.ts +39 -44
- package/src/services/channel.ts +2 -2
- package/src/services/custom-object.test.ts +103 -79
- package/src/services/custom-object.ts +106 -38
- package/src/services/customer-group.test.ts +39 -44
- package/src/services/customer-group.ts +2 -2
- package/src/services/customer.test.ts +357 -292
- package/src/services/customer.ts +70 -23
- package/src/services/discount-code.test.ts +57 -68
- package/src/services/discount-code.ts +2 -2
- package/src/services/discount-group.test.ts +111 -134
- package/src/services/discount-group.ts +2 -2
- package/src/services/draft-validation.test.ts +255 -0
- package/src/services/extension.test.ts +39 -44
- package/src/services/extension.ts +2 -2
- package/src/services/inventory-entry.test.ts +106 -87
- package/src/services/inventory-entry.ts +2 -2
- package/src/services/my-business-unit.test.ts +82 -112
- package/src/services/my-business-unit.ts +25 -19
- package/src/services/my-cart.test.ts +46 -41
- package/src/services/my-cart.ts +32 -28
- package/src/services/my-customer.test.ts +153 -88
- package/src/services/my-customer.ts +130 -61
- package/src/services/my-order.ts +15 -12
- package/src/services/my-payment.test.ts +30 -24
- package/src/services/my-payment.ts +2 -2
- package/src/services/my-shopping-list.ts +2 -2
- package/src/services/order.test.ts +332 -276
- package/src/services/order.ts +45 -27
- package/src/services/payment.test.ts +31 -29
- package/src/services/payment.ts +2 -2
- package/src/services/product-discount.test.ts +39 -46
- package/src/services/product-discount.ts +2 -2
- package/src/services/product-projection.test.ts +176 -166
- package/src/services/product-projection.ts +31 -15
- package/src/services/product-selection.test.ts +17 -9
- package/src/services/product-selection.ts +2 -2
- package/src/services/product-type.test.ts +80 -21
- package/src/services/product-type.ts +2 -2
- package/src/services/product.test.ts +569 -534
- package/src/services/product.ts +14 -7
- package/src/services/project.test.ts +22 -12
- package/src/services/project.ts +28 -13
- package/src/services/quote-request.test.ts +36 -39
- package/src/services/quote-request.ts +2 -2
- package/src/services/quote-staged.ts +2 -2
- package/src/services/quote.ts +2 -2
- package/src/services/recurrence-policy.test.ts +114 -139
- package/src/services/recurrence-policy.ts +2 -2
- package/src/services/recurring-order.test.ts +149 -194
- package/src/services/recurring-order.ts +2 -2
- package/src/services/reviews.test.ts +127 -106
- package/src/services/reviews.ts +2 -2
- package/src/services/shipping-method.test.ts +96 -125
- package/src/services/shipping-method.ts +24 -12
- package/src/services/shopping-list.test.ts +183 -141
- package/src/services/shopping-list.ts +2 -2
- package/src/services/standalone-price.test.ts +60 -46
- package/src/services/standalone-price.ts +2 -2
- package/src/services/state.test.ts +20 -25
- package/src/services/state.ts +2 -2
- package/src/services/store.test.ts +26 -45
- package/src/services/store.ts +2 -2
- package/src/services/subscription.test.ts +39 -44
- package/src/services/subscription.ts +2 -2
- package/src/services/tax-category.test.ts +33 -36
- package/src/services/tax-category.ts +2 -2
- package/src/services/type.test.ts +45 -44
- package/src/services/type.ts +2 -2
- package/src/services/zone.test.ts +40 -44
- package/src/services/zone.ts +2 -2
- package/src/shipping.ts +41 -11
- package/src/storage/abstract.ts +248 -17
- package/src/storage/in-memory.ts +147 -290
- package/src/storage/sqlite.ts +429 -0
- package/src/storage/storage-map.ts +75 -0
- package/src/storage/storage.test-helpers.ts +97 -0
- package/src/storage/storage.test.ts +802 -0
- package/src/testing/associate-role.ts +28 -0
- package/src/testing/attribute-group.ts +27 -0
- package/src/testing/business-unit.ts +9 -8
- package/src/testing/cart-discount.ts +34 -0
- package/src/testing/cart.ts +20 -0
- package/src/testing/category.ts +25 -0
- package/src/testing/channel.ts +23 -0
- package/src/testing/custom-object.ts +27 -0
- package/src/testing/customer-group.ts +26 -0
- package/src/testing/customer.ts +36 -33
- package/src/testing/discount-code.ts +29 -0
- package/src/testing/discount-group.ts +27 -0
- package/src/testing/extension.ts +32 -0
- package/src/testing/index.ts +33 -0
- package/src/testing/inventory-entry.ts +26 -0
- package/src/testing/order.ts +27 -0
- package/src/testing/payment.ts +23 -0
- package/src/testing/product-discount.ts +33 -0
- package/src/testing/product-selection.ts +28 -0
- package/src/testing/product-type.ts +27 -0
- package/src/testing/product.ts +38 -0
- package/src/testing/quote-request.ts +29 -0
- package/src/testing/recurrence-policy.ts +33 -0
- package/src/testing/recurring-order.ts +32 -0
- package/src/testing/review.ts +24 -0
- package/src/testing/shipping-method.ts +31 -0
- package/src/testing/shopping-list.ts +25 -0
- package/src/testing/standalone-price.ts +31 -0
- package/src/testing/state.ts +21 -0
- package/src/testing/store.ts +26 -0
- package/src/testing/subscription.ts +38 -0
- package/src/testing/tax-category.ts +27 -0
- package/src/testing/type.ts +9 -6
- package/src/testing/zone.ts +22 -0
- package/src/validate.test.ts +122 -0
- package/src/validate.ts +78 -7
- package/src/.env +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { BusinessUnit } from "@commercetools/platform-sdk";
|
|
2
|
-
import supertest from "supertest";
|
|
3
2
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
4
3
|
import { businessUnitDraftFactory } from "#src/testing/business-unit.ts";
|
|
5
4
|
import { customerDraftFactory } from "#src/testing/customer.ts";
|
|
@@ -15,25 +14,30 @@ describe("Business units query", () => {
|
|
|
15
14
|
});
|
|
16
15
|
|
|
17
16
|
beforeEach(async () => {
|
|
18
|
-
const draft = businessUnitDraftFactory(ctMock).build(
|
|
17
|
+
const draft = businessUnitDraftFactory(ctMock).build({
|
|
18
|
+
key: "test-business-unit",
|
|
19
|
+
});
|
|
19
20
|
|
|
20
|
-
const response = await
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const response = await ctMock.app.inject({
|
|
22
|
+
method: "POST",
|
|
23
|
+
url: "/dummy/business-units",
|
|
24
|
+
payload: draft,
|
|
25
|
+
});
|
|
26
|
+
expect(response.statusCode).toBe(201);
|
|
27
|
+
businessUnit = response.json() as BusinessUnit;
|
|
25
28
|
});
|
|
26
29
|
|
|
27
30
|
test("no filter", async () => {
|
|
28
|
-
const response = await
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
expect(response.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const response = await ctMock.app.inject({
|
|
32
|
+
method: "GET",
|
|
33
|
+
url: "/dummy/business-units?{}",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(response.statusCode).toBe(200);
|
|
37
|
+
const body = response.json();
|
|
38
|
+
expect(body.count).toBe(1);
|
|
39
|
+
businessUnit = body.results[0] as BusinessUnit;
|
|
40
|
+
expect(businessUnit!.key).toBe("test-business-unit");
|
|
37
41
|
});
|
|
38
42
|
});
|
|
39
43
|
|
|
@@ -47,9 +51,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
47
51
|
test("addAddress", async () => {
|
|
48
52
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
49
53
|
|
|
50
|
-
const response = await
|
|
51
|
-
|
|
52
|
-
.
|
|
54
|
+
const response = await ctMock.app.inject({
|
|
55
|
+
method: "POST",
|
|
56
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
57
|
+
payload: {
|
|
53
58
|
version: 1,
|
|
54
59
|
actions: [
|
|
55
60
|
{
|
|
@@ -64,18 +69,21 @@ describe("Business Unit Update Actions", () => {
|
|
|
64
69
|
},
|
|
65
70
|
},
|
|
66
71
|
],
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
expect(response.
|
|
70
|
-
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
expect(response.statusCode).toBe(200);
|
|
75
|
+
const body = response.json();
|
|
76
|
+
expect(body.version).toBe(2);
|
|
77
|
+
expect(body.addresses).toHaveLength(2);
|
|
71
78
|
});
|
|
72
79
|
|
|
73
80
|
test("removeAddress by ID", async () => {
|
|
74
81
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
75
82
|
|
|
76
|
-
const response = await
|
|
77
|
-
|
|
78
|
-
.
|
|
83
|
+
const response = await ctMock.app.inject({
|
|
84
|
+
method: "POST",
|
|
85
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
86
|
+
payload: {
|
|
79
87
|
version: 1,
|
|
80
88
|
actions: [
|
|
81
89
|
{
|
|
@@ -83,10 +91,12 @@ describe("Business Unit Update Actions", () => {
|
|
|
83
91
|
addressId: businessUnit.addresses[0].id,
|
|
84
92
|
},
|
|
85
93
|
],
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
expect(response.body
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
const body = response.json();
|
|
97
|
+
expect(response.statusCode, JSON.stringify(body)).toBe(200);
|
|
98
|
+
expect(body.version).toBe(2);
|
|
99
|
+
expect(body.addresses).toHaveLength(0);
|
|
90
100
|
});
|
|
91
101
|
|
|
92
102
|
test("changeAddress by ID", async () => {
|
|
@@ -94,9 +104,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
94
104
|
|
|
95
105
|
const addressId = businessUnit.addresses[0].id;
|
|
96
106
|
|
|
97
|
-
const response = await
|
|
98
|
-
|
|
99
|
-
.
|
|
107
|
+
const response = await ctMock.app.inject({
|
|
108
|
+
method: "POST",
|
|
109
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
110
|
+
payload: {
|
|
100
111
|
version: 1,
|
|
101
112
|
actions: [
|
|
102
113
|
{
|
|
@@ -112,9 +123,11 @@ describe("Business Unit Update Actions", () => {
|
|
|
112
123
|
},
|
|
113
124
|
},
|
|
114
125
|
],
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
const body = response.json();
|
|
129
|
+
expect(response.statusCode, JSON.stringify(body)).toBe(200);
|
|
130
|
+
const result = body as BusinessUnit;
|
|
118
131
|
expect(result.version).toBe(2);
|
|
119
132
|
expect(result.addresses).toHaveLength(1);
|
|
120
133
|
expect(result.addresses).toStrictEqual([
|
|
@@ -133,9 +146,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
133
146
|
test("addShippingAddressId", async () => {
|
|
134
147
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
135
148
|
|
|
136
|
-
const response = await
|
|
137
|
-
|
|
138
|
-
.
|
|
149
|
+
const response = await ctMock.app.inject({
|
|
150
|
+
method: "POST",
|
|
151
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
152
|
+
payload: {
|
|
139
153
|
version: 1,
|
|
140
154
|
actions: [
|
|
141
155
|
{
|
|
@@ -143,19 +157,22 @@ describe("Business Unit Update Actions", () => {
|
|
|
143
157
|
addressId: businessUnit.addresses[0].id,
|
|
144
158
|
},
|
|
145
159
|
],
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
expect(response.
|
|
149
|
-
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
expect(response.statusCode).toBe(200);
|
|
163
|
+
const body = response.json();
|
|
164
|
+
expect(body.version).toBe(2);
|
|
165
|
+
expect(body.shippingAddressIds).toHaveLength(1);
|
|
150
166
|
});
|
|
151
167
|
|
|
152
168
|
test("removeShippingAddressId", async () => {
|
|
153
169
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
154
170
|
|
|
155
171
|
const addressId = businessUnit.addresses[0].id;
|
|
156
|
-
await
|
|
157
|
-
|
|
158
|
-
.
|
|
172
|
+
await ctMock.app.inject({
|
|
173
|
+
method: "POST",
|
|
174
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
175
|
+
payload: {
|
|
159
176
|
version: 1,
|
|
160
177
|
actions: [
|
|
161
178
|
{
|
|
@@ -163,11 +180,13 @@ describe("Business Unit Update Actions", () => {
|
|
|
163
180
|
addressId: addressId,
|
|
164
181
|
},
|
|
165
182
|
],
|
|
166
|
-
}
|
|
183
|
+
},
|
|
184
|
+
});
|
|
167
185
|
|
|
168
|
-
const response = await
|
|
169
|
-
|
|
170
|
-
.
|
|
186
|
+
const response = await ctMock.app.inject({
|
|
187
|
+
method: "POST",
|
|
188
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
189
|
+
payload: {
|
|
171
190
|
version: 2,
|
|
172
191
|
actions: [
|
|
173
192
|
{
|
|
@@ -175,9 +194,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
175
194
|
addressId: addressId,
|
|
176
195
|
},
|
|
177
196
|
],
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
expect(response.statusCode).toBe(200);
|
|
200
|
+
const result = response.json() as BusinessUnit;
|
|
181
201
|
expect(result.version).toBe(3);
|
|
182
202
|
expect(result.shippingAddressIds).toHaveLength(0);
|
|
183
203
|
});
|
|
@@ -187,9 +207,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
187
207
|
|
|
188
208
|
const addressId = businessUnit.addresses[0].id;
|
|
189
209
|
|
|
190
|
-
const response = await
|
|
191
|
-
|
|
192
|
-
.
|
|
210
|
+
const response = await ctMock.app.inject({
|
|
211
|
+
method: "POST",
|
|
212
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
213
|
+
payload: {
|
|
193
214
|
version: businessUnit.version,
|
|
194
215
|
actions: [
|
|
195
216
|
{
|
|
@@ -197,18 +218,21 @@ describe("Business Unit Update Actions", () => {
|
|
|
197
218
|
addressId: addressId,
|
|
198
219
|
},
|
|
199
220
|
],
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
expect(response.body
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
const body = response.json();
|
|
224
|
+
expect(response.statusCode, JSON.stringify(body)).toBe(200);
|
|
225
|
+
expect(body.version).toBe(2);
|
|
226
|
+
expect(body.defaultShippingAddressId).toBe(addressId);
|
|
204
227
|
});
|
|
205
228
|
|
|
206
229
|
test("addBillingAddressId", async () => {
|
|
207
230
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
208
231
|
|
|
209
|
-
const response = await
|
|
210
|
-
|
|
211
|
-
.
|
|
232
|
+
const response = await ctMock.app.inject({
|
|
233
|
+
method: "POST",
|
|
234
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
235
|
+
payload: {
|
|
212
236
|
version: 1,
|
|
213
237
|
actions: [
|
|
214
238
|
{
|
|
@@ -216,20 +240,23 @@ describe("Business Unit Update Actions", () => {
|
|
|
216
240
|
addressId: businessUnit.addresses[0].id,
|
|
217
241
|
},
|
|
218
242
|
],
|
|
219
|
-
}
|
|
243
|
+
},
|
|
244
|
+
});
|
|
220
245
|
|
|
221
|
-
expect(response.
|
|
222
|
-
|
|
223
|
-
expect(
|
|
246
|
+
expect(response.statusCode).toBe(200);
|
|
247
|
+
const body = response.json();
|
|
248
|
+
expect(body.version).toBe(2);
|
|
249
|
+
expect(body.billingAddressIds).toHaveLength(1);
|
|
224
250
|
});
|
|
225
251
|
|
|
226
252
|
test("removeBillingAddressId", async () => {
|
|
227
253
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
228
254
|
|
|
229
255
|
const addressId = businessUnit.addresses[0].id;
|
|
230
|
-
await
|
|
231
|
-
|
|
232
|
-
.
|
|
256
|
+
await ctMock.app.inject({
|
|
257
|
+
method: "POST",
|
|
258
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
259
|
+
payload: {
|
|
233
260
|
version: 1,
|
|
234
261
|
actions: [
|
|
235
262
|
{
|
|
@@ -237,11 +264,13 @@ describe("Business Unit Update Actions", () => {
|
|
|
237
264
|
addressId: addressId,
|
|
238
265
|
},
|
|
239
266
|
],
|
|
240
|
-
}
|
|
267
|
+
},
|
|
268
|
+
});
|
|
241
269
|
|
|
242
|
-
const response = await
|
|
243
|
-
|
|
244
|
-
.
|
|
270
|
+
const response = await ctMock.app.inject({
|
|
271
|
+
method: "POST",
|
|
272
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
273
|
+
payload: {
|
|
245
274
|
version: 2,
|
|
246
275
|
actions: [
|
|
247
276
|
{
|
|
@@ -249,9 +278,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
249
278
|
addressId: addressId,
|
|
250
279
|
},
|
|
251
280
|
],
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
expect(response.statusCode).toBe(200);
|
|
284
|
+
const result = response.json() as BusinessUnit;
|
|
255
285
|
expect(result.version).toBe(3);
|
|
256
286
|
expect(result.billingAddressIds).toHaveLength(0);
|
|
257
287
|
});
|
|
@@ -260,9 +290,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
260
290
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
261
291
|
const addressId = businessUnit.addresses[0].id;
|
|
262
292
|
|
|
263
|
-
const response = await
|
|
264
|
-
|
|
265
|
-
.
|
|
293
|
+
const response = await ctMock.app.inject({
|
|
294
|
+
method: "POST",
|
|
295
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
296
|
+
payload: {
|
|
266
297
|
version: businessUnit.version,
|
|
267
298
|
actions: [
|
|
268
299
|
{
|
|
@@ -270,54 +301,65 @@ describe("Business Unit Update Actions", () => {
|
|
|
270
301
|
addressId: addressId,
|
|
271
302
|
},
|
|
272
303
|
],
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
expect(response.body
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
const body = response.json();
|
|
307
|
+
expect(response.statusCode, JSON.stringify(body)).toBe(200);
|
|
308
|
+
expect(body.version).toBe(2);
|
|
309
|
+
expect(body.defaultBillingAddressId).toBe(addressId);
|
|
277
310
|
});
|
|
278
311
|
|
|
279
312
|
test("changeName", async () => {
|
|
280
313
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
281
314
|
|
|
282
|
-
const response = await
|
|
283
|
-
|
|
284
|
-
.
|
|
315
|
+
const response = await ctMock.app.inject({
|
|
316
|
+
method: "POST",
|
|
317
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
318
|
+
payload: {
|
|
285
319
|
version: 1,
|
|
286
320
|
actions: [{ action: "changeName", name: "Updated Business Unit Name" }],
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
expect(response.
|
|
290
|
-
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
expect(response.statusCode).toBe(200);
|
|
324
|
+
const body = response.json();
|
|
325
|
+
expect(body.version).toBe(2);
|
|
326
|
+
expect(body.name).toBe("Updated Business Unit Name");
|
|
291
327
|
});
|
|
292
328
|
|
|
293
329
|
test("setContactEmail", async () => {
|
|
294
330
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
295
331
|
|
|
296
|
-
const response = await
|
|
297
|
-
|
|
298
|
-
.
|
|
332
|
+
const response = await ctMock.app.inject({
|
|
333
|
+
method: "POST",
|
|
334
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
335
|
+
payload: {
|
|
299
336
|
version: 1,
|
|
300
337
|
actions: [
|
|
301
338
|
{ action: "setContactEmail", contactEmail: "newemail@business.com" },
|
|
302
339
|
],
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
expect(response.
|
|
306
|
-
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
expect(response.statusCode).toBe(200);
|
|
343
|
+
const body = response.json();
|
|
344
|
+
expect(body.version).toBe(2);
|
|
345
|
+
expect(body.contactEmail).toBe("newemail@business.com");
|
|
307
346
|
});
|
|
308
347
|
|
|
309
348
|
test("changeStatus", async () => {
|
|
310
349
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
311
350
|
|
|
312
|
-
const response = await
|
|
313
|
-
|
|
314
|
-
.
|
|
351
|
+
const response = await ctMock.app.inject({
|
|
352
|
+
method: "POST",
|
|
353
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
354
|
+
payload: {
|
|
315
355
|
version: 1,
|
|
316
356
|
actions: [{ action: "changeStatus", status: "Inactive" }],
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
expect(response.
|
|
320
|
-
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
expect(response.statusCode).toBe(200);
|
|
360
|
+
const body = response.json();
|
|
361
|
+
expect(body.version).toBe(2);
|
|
362
|
+
expect(body.status).toBe("Inactive");
|
|
321
363
|
});
|
|
322
364
|
|
|
323
365
|
test("changeParentUnit", async () => {
|
|
@@ -331,9 +373,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
331
373
|
name: "Division Unit",
|
|
332
374
|
});
|
|
333
375
|
|
|
334
|
-
const response = await
|
|
335
|
-
|
|
336
|
-
.
|
|
376
|
+
const response = await ctMock.app.inject({
|
|
377
|
+
method: "POST",
|
|
378
|
+
url: `/dummy/business-units/${divisionBusinessUnit.id}`,
|
|
379
|
+
payload: {
|
|
337
380
|
version: 1,
|
|
338
381
|
actions: [
|
|
339
382
|
{
|
|
@@ -344,19 +387,22 @@ describe("Business Unit Update Actions", () => {
|
|
|
344
387
|
},
|
|
345
388
|
},
|
|
346
389
|
],
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
expect(response.
|
|
350
|
-
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
expect(response.statusCode).toBe(200);
|
|
393
|
+
const body = response.json();
|
|
394
|
+
expect(body.version).toBe(2);
|
|
395
|
+
expect(body.parentUnit?.key).toBe(parentBusinessUnit.key);
|
|
351
396
|
});
|
|
352
397
|
|
|
353
398
|
test("addAssociate", async () => {
|
|
354
399
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
355
400
|
const customer = await customerDraftFactory(ctMock).create();
|
|
356
401
|
|
|
357
|
-
const response = await
|
|
358
|
-
|
|
359
|
-
.
|
|
402
|
+
const response = await ctMock.app.inject({
|
|
403
|
+
method: "POST",
|
|
404
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
405
|
+
payload: {
|
|
360
406
|
version: 1,
|
|
361
407
|
actions: [
|
|
362
408
|
{
|
|
@@ -370,10 +416,12 @@ describe("Business Unit Update Actions", () => {
|
|
|
370
416
|
},
|
|
371
417
|
},
|
|
372
418
|
],
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
expect(response.
|
|
376
|
-
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
expect(response.statusCode).toBe(200);
|
|
422
|
+
const body = response.json();
|
|
423
|
+
expect(body.version).toBe(2);
|
|
424
|
+
expect(body.associates).toHaveLength(1);
|
|
377
425
|
});
|
|
378
426
|
|
|
379
427
|
test("removeAssociate", async () => {
|
|
@@ -390,9 +438,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
390
438
|
],
|
|
391
439
|
});
|
|
392
440
|
|
|
393
|
-
const response = await
|
|
394
|
-
|
|
395
|
-
.
|
|
441
|
+
const response = await ctMock.app.inject({
|
|
442
|
+
method: "POST",
|
|
443
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
444
|
+
payload: {
|
|
396
445
|
version: 1,
|
|
397
446
|
actions: [
|
|
398
447
|
{
|
|
@@ -403,10 +452,12 @@ describe("Business Unit Update Actions", () => {
|
|
|
403
452
|
},
|
|
404
453
|
},
|
|
405
454
|
],
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
expect(response.
|
|
409
|
-
|
|
455
|
+
},
|
|
456
|
+
});
|
|
457
|
+
expect(response.statusCode).toBe(200);
|
|
458
|
+
const body = response.json();
|
|
459
|
+
expect(body.version).toBe(2);
|
|
460
|
+
expect(body.associates).toHaveLength(0);
|
|
410
461
|
});
|
|
411
462
|
|
|
412
463
|
test("changeAssociate", async () => {
|
|
@@ -423,9 +474,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
423
474
|
],
|
|
424
475
|
});
|
|
425
476
|
|
|
426
|
-
const response = await
|
|
427
|
-
|
|
428
|
-
.
|
|
477
|
+
const response = await ctMock.app.inject({
|
|
478
|
+
method: "POST",
|
|
479
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
480
|
+
payload: {
|
|
429
481
|
version: 1,
|
|
430
482
|
actions: [
|
|
431
483
|
{
|
|
@@ -451,12 +503,12 @@ describe("Business Unit Update Actions", () => {
|
|
|
451
503
|
},
|
|
452
504
|
},
|
|
453
505
|
],
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
expect(response.
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
);
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
expect(response.statusCode).toBe(200);
|
|
509
|
+
const body = response.json();
|
|
510
|
+
expect(body.version).toBe(2);
|
|
511
|
+
expect(body.associates[0].associateRoleAssignments).toHaveLength(1);
|
|
460
512
|
});
|
|
461
513
|
|
|
462
514
|
test("setCustomType", async () => {
|
|
@@ -474,9 +526,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
474
526
|
|
|
475
527
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
476
528
|
|
|
477
|
-
const response = await
|
|
478
|
-
|
|
479
|
-
.
|
|
529
|
+
const response = await ctMock.app.inject({
|
|
530
|
+
method: "POST",
|
|
531
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
532
|
+
payload: {
|
|
480
533
|
version: 1,
|
|
481
534
|
actions: [
|
|
482
535
|
{
|
|
@@ -487,10 +540,12 @@ describe("Business Unit Update Actions", () => {
|
|
|
487
540
|
},
|
|
488
541
|
},
|
|
489
542
|
],
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
expect(response.
|
|
493
|
-
|
|
543
|
+
},
|
|
544
|
+
});
|
|
545
|
+
expect(response.statusCode).toBe(200);
|
|
546
|
+
const body = response.json();
|
|
547
|
+
expect(body.version).toBe(2);
|
|
548
|
+
expect(body.custom.type.id).toBe(type.id);
|
|
494
549
|
});
|
|
495
550
|
|
|
496
551
|
test("setCustomField", async () => {
|
|
@@ -518,9 +573,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
518
573
|
},
|
|
519
574
|
});
|
|
520
575
|
|
|
521
|
-
const response = await
|
|
522
|
-
|
|
523
|
-
.
|
|
576
|
+
const response = await ctMock.app.inject({
|
|
577
|
+
method: "POST",
|
|
578
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
579
|
+
payload: {
|
|
524
580
|
version: 1,
|
|
525
581
|
actions: [
|
|
526
582
|
{
|
|
@@ -529,10 +585,12 @@ describe("Business Unit Update Actions", () => {
|
|
|
529
585
|
value: "bar",
|
|
530
586
|
},
|
|
531
587
|
],
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
expect(response.
|
|
535
|
-
|
|
588
|
+
},
|
|
589
|
+
});
|
|
590
|
+
expect(response.statusCode).toBe(200);
|
|
591
|
+
const body = response.json();
|
|
592
|
+
expect(body.version).toBe(2);
|
|
593
|
+
expect(body.custom.fields.customField).toBe("bar");
|
|
536
594
|
});
|
|
537
595
|
|
|
538
596
|
test("setAddressCustomType", async () => {
|
|
@@ -549,9 +607,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
549
607
|
});
|
|
550
608
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
551
609
|
|
|
552
|
-
const response = await
|
|
553
|
-
|
|
554
|
-
.
|
|
610
|
+
const response = await ctMock.app.inject({
|
|
611
|
+
method: "POST",
|
|
612
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
613
|
+
payload: {
|
|
555
614
|
version: 1,
|
|
556
615
|
actions: [
|
|
557
616
|
{
|
|
@@ -563,10 +622,12 @@ describe("Business Unit Update Actions", () => {
|
|
|
563
622
|
},
|
|
564
623
|
},
|
|
565
624
|
],
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
expect(response.
|
|
569
|
-
|
|
625
|
+
},
|
|
626
|
+
});
|
|
627
|
+
expect(response.statusCode).toBe(200);
|
|
628
|
+
const body = response.json();
|
|
629
|
+
expect(body.version).toBe(2);
|
|
630
|
+
expect(body.addresses[0].custom.type.id).toBe(type.id);
|
|
570
631
|
});
|
|
571
632
|
|
|
572
633
|
test("setAddressCustomField", async () => {
|
|
@@ -583,9 +644,10 @@ describe("Business Unit Update Actions", () => {
|
|
|
583
644
|
});
|
|
584
645
|
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
585
646
|
|
|
586
|
-
const response = await
|
|
587
|
-
|
|
588
|
-
.
|
|
647
|
+
const response = await ctMock.app.inject({
|
|
648
|
+
method: "POST",
|
|
649
|
+
url: `/dummy/business-units/${businessUnit.id}`,
|
|
650
|
+
payload: {
|
|
589
651
|
version: 1,
|
|
590
652
|
actions: [
|
|
591
653
|
{
|
|
@@ -603,10 +665,12 @@ describe("Business Unit Update Actions", () => {
|
|
|
603
665
|
value: "address custom value",
|
|
604
666
|
},
|
|
605
667
|
],
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
expect(response.
|
|
609
|
-
|
|
668
|
+
},
|
|
669
|
+
});
|
|
670
|
+
expect(response.statusCode).toBe(200);
|
|
671
|
+
const body = response.json();
|
|
672
|
+
expect(body.version).toBe(3);
|
|
673
|
+
expect(body.addresses[0].custom.fields.addressCustomField).toBe(
|
|
610
674
|
"address custom value",
|
|
611
675
|
);
|
|
612
676
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FastifyInstance } from "fastify";
|
|
2
2
|
import type { BusinessUnitRepository } from "../repositories/business-unit.ts";
|
|
3
3
|
import AbstractService from "./abstract.ts";
|
|
4
4
|
|
|
5
5
|
export class BusinessUnitServices extends AbstractService {
|
|
6
6
|
public repository: BusinessUnitRepository;
|
|
7
7
|
|
|
8
|
-
constructor(parent:
|
|
8
|
+
constructor(parent: FastifyInstance, repository: BusinessUnitRepository) {
|
|
9
9
|
super(parent);
|
|
10
10
|
|
|
11
11
|
this.repository = repository;
|