@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,26 +1,18 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import type {
|
|
3
3
|
Category,
|
|
4
|
-
CategoryDraft,
|
|
5
4
|
Image,
|
|
6
|
-
InventoryEntryDraft,
|
|
7
5
|
PriceDraft,
|
|
8
6
|
Product,
|
|
9
7
|
ProductData,
|
|
10
|
-
ProductDraft,
|
|
11
8
|
ProductPagedSearchResponse,
|
|
12
9
|
ProductSearchRequest,
|
|
13
10
|
ProductSearchResult,
|
|
14
11
|
ProductType,
|
|
15
|
-
ProductTypeDraft,
|
|
16
12
|
State,
|
|
17
|
-
StateDraft,
|
|
18
13
|
TaxCategory,
|
|
19
|
-
TaxCategoryDraft,
|
|
20
14
|
Type,
|
|
21
|
-
TypeDraft,
|
|
22
15
|
} from "@commercetools/platform-sdk";
|
|
23
|
-
import supertest from "supertest";
|
|
24
16
|
import {
|
|
25
17
|
afterAll,
|
|
26
18
|
beforeAll,
|
|
@@ -29,93 +21,120 @@ import {
|
|
|
29
21
|
expect,
|
|
30
22
|
test,
|
|
31
23
|
} from "vitest";
|
|
24
|
+
import {
|
|
25
|
+
categoryDraftFactory,
|
|
26
|
+
channelDraftFactory,
|
|
27
|
+
inventoryEntryDraftFactory,
|
|
28
|
+
productDraftFactory,
|
|
29
|
+
productTypeDraftFactory,
|
|
30
|
+
stateDraftFactory,
|
|
31
|
+
taxCategoryDraftFactory,
|
|
32
|
+
typeDraftFactory,
|
|
33
|
+
} from "#src/testing/index.ts";
|
|
32
34
|
import { CommercetoolsMock } from "../index.ts";
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
let productType: ProductType;
|
|
37
|
+
let category1: Category;
|
|
38
|
+
let category2: Category;
|
|
39
|
+
let taxCategory1: TaxCategory;
|
|
40
|
+
let taxCategory2: TaxCategory;
|
|
41
|
+
let productState1: State;
|
|
42
|
+
let productState2: State;
|
|
43
|
+
let productPriceType: Type;
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"nl-NL": "category_1",
|
|
47
|
-
},
|
|
48
|
-
};
|
|
45
|
+
async function beforeAllProductTests(mock: CommercetoolsMock) {
|
|
46
|
+
const productTypeFactory = productTypeDraftFactory(mock);
|
|
47
|
+
const categoryFactory = categoryDraftFactory(mock);
|
|
48
|
+
const taxCategoryFactory = taxCategoryDraftFactory(mock);
|
|
49
|
+
const stateFactory = stateDraftFactory(mock);
|
|
50
|
+
const typeFactory = typeDraftFactory(mock);
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
slug: {
|
|
56
|
-
"nl-NL": "category_2",
|
|
57
|
-
},
|
|
58
|
-
};
|
|
52
|
+
productType = await productTypeFactory.create({
|
|
53
|
+
key: "test-product-type",
|
|
54
|
+
name: "Test Product Type",
|
|
55
|
+
description: "Test Product Type description",
|
|
56
|
+
});
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
category1 = await categoryFactory.create({
|
|
59
|
+
key: "category-1",
|
|
60
|
+
name: {
|
|
61
|
+
"nl-NL": "Category One",
|
|
62
|
+
},
|
|
63
|
+
slug: {
|
|
64
|
+
"nl-NL": "category_1",
|
|
65
|
+
},
|
|
66
|
+
});
|
|
64
67
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
category2 = await categoryFactory.create({
|
|
69
|
+
key: "category-2",
|
|
70
|
+
name: {
|
|
71
|
+
"nl-NL": "Category Two",
|
|
72
|
+
},
|
|
73
|
+
slug: {
|
|
74
|
+
"nl-NL": "category_2",
|
|
75
|
+
},
|
|
76
|
+
});
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
name: {
|
|
75
|
-
"nl-NL": "Initial state",
|
|
76
|
-
},
|
|
77
|
-
description: {
|
|
78
|
-
"nl-NL": "Product initial state",
|
|
79
|
-
},
|
|
80
|
-
};
|
|
78
|
+
taxCategory1 = await taxCategoryFactory.create({
|
|
79
|
+
name: "Tax category 1",
|
|
80
|
+
key: "tax-category-1",
|
|
81
|
+
});
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
name: {
|
|
87
|
-
"nl-NL": "Another state",
|
|
88
|
-
},
|
|
89
|
-
description: {
|
|
90
|
-
"nl-NL": "Product another state",
|
|
91
|
-
},
|
|
92
|
-
};
|
|
83
|
+
taxCategory2 = await taxCategoryFactory.create({
|
|
84
|
+
name: "Tax category 2",
|
|
85
|
+
key: "tax-category-2",
|
|
86
|
+
});
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
en: "Product Price Type",
|
|
101
|
-
},
|
|
102
|
-
resourceTypeIds: ["product-price"],
|
|
103
|
-
fieldDefinitions: [
|
|
104
|
-
{
|
|
105
|
-
name: "lastModifiedAt",
|
|
106
|
-
label: {
|
|
107
|
-
en: "Last modified at",
|
|
108
|
-
},
|
|
109
|
-
required: false,
|
|
110
|
-
type: {
|
|
111
|
-
name: "DateTime",
|
|
112
|
-
},
|
|
113
|
-
inputHint: "SingleLine",
|
|
88
|
+
productState1 = await stateFactory.create({
|
|
89
|
+
key: "initial-state",
|
|
90
|
+
type: "ProductState",
|
|
91
|
+
initial: true,
|
|
92
|
+
name: {
|
|
93
|
+
"nl-NL": "Initial state",
|
|
114
94
|
},
|
|
115
|
-
|
|
116
|
-
|
|
95
|
+
description: {
|
|
96
|
+
"nl-NL": "Product initial state",
|
|
97
|
+
},
|
|
98
|
+
});
|
|
117
99
|
|
|
118
|
-
|
|
100
|
+
productState2 = await stateFactory.create({
|
|
101
|
+
key: "another-state",
|
|
102
|
+
type: "ProductState",
|
|
103
|
+
initial: true,
|
|
104
|
+
name: {
|
|
105
|
+
"nl-NL": "Another state",
|
|
106
|
+
},
|
|
107
|
+
description: {
|
|
108
|
+
"nl-NL": "Product another state",
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
productPriceType = await typeFactory.create({
|
|
113
|
+
key: "product-price",
|
|
114
|
+
name: {
|
|
115
|
+
en: "ProductPriceType",
|
|
116
|
+
},
|
|
117
|
+
description: {
|
|
118
|
+
en: "Product Price Type",
|
|
119
|
+
},
|
|
120
|
+
resourceTypeIds: ["product-price"],
|
|
121
|
+
fieldDefinitions: [
|
|
122
|
+
{
|
|
123
|
+
name: "lastModifiedAt",
|
|
124
|
+
label: {
|
|
125
|
+
en: "Last modified at",
|
|
126
|
+
},
|
|
127
|
+
required: false,
|
|
128
|
+
type: {
|
|
129
|
+
name: "DateTime",
|
|
130
|
+
},
|
|
131
|
+
inputHint: "SingleLine",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const publishedProductDraftOverrides = {
|
|
119
138
|
name: {
|
|
120
139
|
"nl-NL": "test published product",
|
|
121
140
|
},
|
|
@@ -123,21 +142,21 @@ const publishedProductDraft: ProductDraft = {
|
|
|
123
142
|
"nl-NL": "Test published product description",
|
|
124
143
|
},
|
|
125
144
|
productType: {
|
|
126
|
-
typeId: "product-type",
|
|
145
|
+
typeId: "product-type" as const,
|
|
127
146
|
key: "test-product-type",
|
|
128
147
|
},
|
|
129
148
|
categories: [
|
|
130
149
|
{
|
|
131
|
-
typeId: "category",
|
|
150
|
+
typeId: "category" as const,
|
|
132
151
|
key: "category-1",
|
|
133
152
|
},
|
|
134
153
|
],
|
|
135
154
|
taxCategory: {
|
|
136
|
-
typeId: "tax-category",
|
|
137
|
-
key:
|
|
155
|
+
typeId: "tax-category" as const,
|
|
156
|
+
key: "tax-category-1",
|
|
138
157
|
},
|
|
139
158
|
state: {
|
|
140
|
-
typeId: "state",
|
|
159
|
+
typeId: "state" as const,
|
|
141
160
|
key: "initial-state",
|
|
142
161
|
},
|
|
143
162
|
masterVariant: {
|
|
@@ -197,7 +216,7 @@ const publishedProductDraft: ProductDraft = {
|
|
|
197
216
|
publish: true,
|
|
198
217
|
};
|
|
199
218
|
|
|
200
|
-
const
|
|
219
|
+
const unpublishedProductDraftOverrides = {
|
|
201
220
|
key: "test-unpublished-product",
|
|
202
221
|
name: {
|
|
203
222
|
"nl-NL": "test unpublished product",
|
|
@@ -206,21 +225,21 @@ const unpublishedProductDraft: ProductDraft = {
|
|
|
206
225
|
"nl-NL": "Test published product description",
|
|
207
226
|
},
|
|
208
227
|
productType: {
|
|
209
|
-
typeId: "product-type",
|
|
228
|
+
typeId: "product-type" as const,
|
|
210
229
|
key: "test-product-type",
|
|
211
230
|
},
|
|
212
231
|
categories: [
|
|
213
232
|
{
|
|
214
|
-
typeId: "category",
|
|
233
|
+
typeId: "category" as const,
|
|
215
234
|
key: "category-1",
|
|
216
235
|
},
|
|
217
236
|
],
|
|
218
237
|
taxCategory: {
|
|
219
|
-
typeId: "tax-category",
|
|
220
|
-
key:
|
|
238
|
+
typeId: "tax-category" as const,
|
|
239
|
+
key: "tax-category-1",
|
|
221
240
|
},
|
|
222
241
|
state: {
|
|
223
|
-
typeId: "state",
|
|
242
|
+
typeId: "state" as const,
|
|
224
243
|
key: "initial-state",
|
|
225
244
|
},
|
|
226
245
|
masterVariant: {
|
|
@@ -280,82 +299,10 @@ const unpublishedProductDraft: ProductDraft = {
|
|
|
280
299
|
publish: false,
|
|
281
300
|
};
|
|
282
301
|
|
|
283
|
-
let productType: ProductType;
|
|
284
|
-
let category1: Category;
|
|
285
|
-
let category2: Category;
|
|
286
|
-
let taxCategory1: TaxCategory;
|
|
287
|
-
let taxCategory2: TaxCategory;
|
|
288
|
-
let productState1: State;
|
|
289
|
-
let productState2: State;
|
|
290
|
-
let productPriceType: Type;
|
|
291
|
-
|
|
292
|
-
async function beforeAllProductTests(mock: CommercetoolsMock) {
|
|
293
|
-
let response;
|
|
294
|
-
// Create Product Type
|
|
295
|
-
response = await supertest(mock.app)
|
|
296
|
-
.post("/dummy/product-types")
|
|
297
|
-
.send(productTypeDraft);
|
|
298
|
-
|
|
299
|
-
expect(response.status).toBe(201);
|
|
300
|
-
productType = response.body;
|
|
301
|
-
|
|
302
|
-
// Create Category 1
|
|
303
|
-
response = await supertest(mock.app)
|
|
304
|
-
.post("/dummy/categories")
|
|
305
|
-
.send(categoryDraft1);
|
|
306
|
-
|
|
307
|
-
expect(response.status).toBe(201);
|
|
308
|
-
category1 = response.body;
|
|
309
|
-
|
|
310
|
-
// Create Category 2
|
|
311
|
-
response = await supertest(mock.app)
|
|
312
|
-
.post("/dummy/categories")
|
|
313
|
-
.send(categoryDraft2);
|
|
314
|
-
|
|
315
|
-
expect(response.status).toBe(201);
|
|
316
|
-
category2 = response.body;
|
|
317
|
-
|
|
318
|
-
// Create Tax Category 1
|
|
319
|
-
response = await supertest(mock.app)
|
|
320
|
-
.post("/dummy/tax-categories")
|
|
321
|
-
.send(taxcategoryDraft1);
|
|
322
|
-
|
|
323
|
-
expect(response.status).toBe(201);
|
|
324
|
-
taxCategory1 = response.body;
|
|
325
|
-
|
|
326
|
-
// Create Tax Category 2
|
|
327
|
-
response = await supertest(mock.app)
|
|
328
|
-
.post("/dummy/tax-categories")
|
|
329
|
-
.send(taxcategoryDraft2);
|
|
330
|
-
|
|
331
|
-
expect(response.status).toBe(201);
|
|
332
|
-
taxCategory2 = response.body;
|
|
333
|
-
|
|
334
|
-
// Create Product State 1
|
|
335
|
-
response = await supertest(mock.app)
|
|
336
|
-
.post("/dummy/states")
|
|
337
|
-
.send(productState1Draft);
|
|
338
|
-
|
|
339
|
-
expect(response.status).toBe(201);
|
|
340
|
-
productState1 = response.body;
|
|
341
|
-
|
|
342
|
-
// Create Product State 2
|
|
343
|
-
response = await supertest(mock.app)
|
|
344
|
-
.post("/dummy/states")
|
|
345
|
-
.send(productState2Draft);
|
|
346
|
-
|
|
347
|
-
expect(response.status).toBe(201);
|
|
348
|
-
productState2 = response.body;
|
|
349
|
-
|
|
350
|
-
response = await supertest(mock.app)
|
|
351
|
-
.post("/dummy/types")
|
|
352
|
-
.send(productPriceTypeDraft);
|
|
353
|
-
expect(response.status).toBe(201);
|
|
354
|
-
productPriceType = response.body;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
302
|
describe("Product", () => {
|
|
358
303
|
const ctMock = new CommercetoolsMock();
|
|
304
|
+
const productFactory = productDraftFactory(ctMock);
|
|
305
|
+
|
|
359
306
|
beforeAll(async () => {
|
|
360
307
|
await beforeAllProductTests(ctMock);
|
|
361
308
|
});
|
|
@@ -363,18 +310,20 @@ describe("Product", () => {
|
|
|
363
310
|
test("Create product", async () => {
|
|
364
311
|
assert(productType, "product type not created");
|
|
365
312
|
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
313
|
+
const product = await productFactory.create(
|
|
314
|
+
unpublishedProductDraftOverrides,
|
|
315
|
+
);
|
|
369
316
|
|
|
370
317
|
const productData: ProductData = {
|
|
371
318
|
name: {
|
|
319
|
+
en: expect.any(String),
|
|
372
320
|
"nl-NL": "test unpublished product",
|
|
373
321
|
},
|
|
374
322
|
description: {
|
|
375
323
|
"nl-NL": "Test published product description",
|
|
376
324
|
},
|
|
377
325
|
slug: {
|
|
326
|
+
en: expect.any(String),
|
|
378
327
|
"nl-NL": "test-unpublished-product",
|
|
379
328
|
},
|
|
380
329
|
categories: [
|
|
@@ -450,10 +399,12 @@ describe("Product", () => {
|
|
|
450
399
|
searchKeywords: {},
|
|
451
400
|
};
|
|
452
401
|
|
|
453
|
-
expect(
|
|
402
|
+
expect(product).toEqual({
|
|
454
403
|
createdAt: expect.anything(),
|
|
404
|
+
createdBy: expect.anything(),
|
|
455
405
|
id: expect.anything(),
|
|
456
406
|
lastModifiedAt: expect.anything(),
|
|
407
|
+
lastModifiedBy: expect.anything(),
|
|
457
408
|
key: "test-unpublished-product",
|
|
458
409
|
taxCategory: {
|
|
459
410
|
typeId: "tax-category",
|
|
@@ -480,46 +431,42 @@ describe("Product", () => {
|
|
|
480
431
|
|
|
481
432
|
describe("Product update actions", () => {
|
|
482
433
|
const ctMock = new CommercetoolsMock();
|
|
434
|
+
const productFactory = productDraftFactory(ctMock);
|
|
483
435
|
let productPublished: Product | undefined;
|
|
436
|
+
|
|
484
437
|
beforeAll(async () => {
|
|
485
438
|
await beforeAllProductTests(ctMock);
|
|
486
439
|
});
|
|
487
440
|
|
|
488
441
|
beforeEach(async () => {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
.send(publishedProductDraft);
|
|
493
|
-
|
|
494
|
-
expect(response.status).toBe(201);
|
|
495
|
-
productPublished = response.body;
|
|
496
|
-
|
|
497
|
-
response = await supertest(ctMock.app)
|
|
498
|
-
.post("/dummy/products")
|
|
499
|
-
.send(unpublishedProductDraft);
|
|
442
|
+
productPublished = await productFactory.create(
|
|
443
|
+
publishedProductDraftOverrides,
|
|
444
|
+
);
|
|
500
445
|
|
|
501
|
-
|
|
446
|
+
await productFactory.create(unpublishedProductDraftOverrides);
|
|
502
447
|
});
|
|
503
448
|
|
|
504
449
|
afterAll(async () => {
|
|
505
|
-
ctMock.clear();
|
|
450
|
+
await ctMock.clear();
|
|
506
451
|
});
|
|
507
452
|
|
|
508
453
|
test("setAttribute masterVariant (staged)", async () => {
|
|
509
454
|
assert(productPublished, "product not created");
|
|
510
455
|
|
|
511
456
|
{
|
|
512
|
-
const response = await
|
|
513
|
-
|
|
514
|
-
.
|
|
457
|
+
const response = await ctMock.app.inject({
|
|
458
|
+
method: "POST",
|
|
459
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
460
|
+
payload: {
|
|
515
461
|
version: 1,
|
|
516
462
|
actions: [
|
|
517
463
|
{ action: "setAttribute", sku: "1337", name: "foo", value: "bar" },
|
|
518
464
|
],
|
|
519
|
-
}
|
|
465
|
+
},
|
|
466
|
+
});
|
|
520
467
|
|
|
521
|
-
expect(response.
|
|
522
|
-
const product: Product = response.
|
|
468
|
+
expect(response.statusCode).toBe(200);
|
|
469
|
+
const product: Product = response.json();
|
|
523
470
|
expect(product.version).toBe(2);
|
|
524
471
|
expect(product.masterData.hasStagedChanges).toBeTruthy();
|
|
525
472
|
expect(product.masterData.current.masterVariant.attributes).toHaveLength(
|
|
@@ -529,21 +476,23 @@ describe("Product update actions", () => {
|
|
|
529
476
|
2,
|
|
530
477
|
);
|
|
531
478
|
|
|
532
|
-
const attr =
|
|
479
|
+
const attr = product.masterData.staged.masterVariant.attributes?.[1];
|
|
533
480
|
expect(attr).toEqual({ name: "foo", value: "bar" });
|
|
534
481
|
}
|
|
535
482
|
|
|
536
483
|
// Publish
|
|
537
484
|
{
|
|
538
|
-
const response = await
|
|
539
|
-
|
|
540
|
-
.
|
|
485
|
+
const response = await ctMock.app.inject({
|
|
486
|
+
method: "POST",
|
|
487
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
488
|
+
payload: {
|
|
541
489
|
version: 2,
|
|
542
490
|
actions: [{ action: "publish", scope: "All" }],
|
|
543
|
-
}
|
|
491
|
+
},
|
|
492
|
+
});
|
|
544
493
|
|
|
545
|
-
expect(response.
|
|
546
|
-
const product: Product = response.
|
|
494
|
+
expect(response.statusCode).toBe(200);
|
|
495
|
+
const product: Product = response.json();
|
|
547
496
|
expect(product.version).toBe(3);
|
|
548
497
|
expect(product.masterData.hasStagedChanges).toBeFalsy();
|
|
549
498
|
expect(product.masterData.current.masterVariant.attributes).toHaveLength(
|
|
@@ -555,9 +504,10 @@ describe("Product update actions", () => {
|
|
|
555
504
|
test("setAttribute masterVariant (published)", async () => {
|
|
556
505
|
assert(productPublished, "product not created");
|
|
557
506
|
|
|
558
|
-
const response = await
|
|
559
|
-
|
|
560
|
-
.
|
|
507
|
+
const response = await ctMock.app.inject({
|
|
508
|
+
method: "POST",
|
|
509
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
510
|
+
payload: {
|
|
561
511
|
version: 1,
|
|
562
512
|
actions: [
|
|
563
513
|
{
|
|
@@ -568,10 +518,11 @@ describe("Product update actions", () => {
|
|
|
568
518
|
staged: false,
|
|
569
519
|
},
|
|
570
520
|
],
|
|
571
|
-
}
|
|
521
|
+
},
|
|
522
|
+
});
|
|
572
523
|
|
|
573
|
-
expect(response.
|
|
574
|
-
const product: Product = response.
|
|
524
|
+
expect(response.statusCode).toBe(200);
|
|
525
|
+
const product: Product = response.json();
|
|
575
526
|
|
|
576
527
|
// TODO: Since we auto publish it actually does two version updates. So the
|
|
577
528
|
// version should be 3
|
|
@@ -580,76 +531,80 @@ describe("Product update actions", () => {
|
|
|
580
531
|
expect(product.masterData.current.masterVariant.attributes).toHaveLength(2);
|
|
581
532
|
expect(product.masterData.staged.masterVariant.attributes).toHaveLength(2);
|
|
582
533
|
|
|
583
|
-
const attr =
|
|
534
|
+
const attr = product.masterData.staged.masterVariant.attributes?.[1];
|
|
584
535
|
expect(attr).toEqual({ name: "foo", value: "bar" });
|
|
585
536
|
});
|
|
586
537
|
|
|
587
538
|
test("setAttribute variant", async () => {
|
|
588
539
|
assert(productPublished, "product not created");
|
|
589
540
|
|
|
590
|
-
const response = await
|
|
591
|
-
|
|
592
|
-
.
|
|
541
|
+
const response = await ctMock.app.inject({
|
|
542
|
+
method: "POST",
|
|
543
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
544
|
+
payload: {
|
|
593
545
|
version: 1,
|
|
594
546
|
actions: [
|
|
595
547
|
{ action: "setAttribute", sku: "1338", name: "foo", value: "bar" },
|
|
596
548
|
],
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
expect(response.
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
);
|
|
603
|
-
const attr =
|
|
549
|
+
},
|
|
550
|
+
});
|
|
551
|
+
expect(response.statusCode).toBe(200);
|
|
552
|
+
const body = response.json();
|
|
553
|
+
expect(body.version).toBe(2);
|
|
554
|
+
expect(body.masterData.staged.variants[0].attributes).toHaveLength(2);
|
|
555
|
+
const attr = body.masterData.staged.variants[0].attributes[1];
|
|
604
556
|
expect(attr).toEqual({ name: "foo", value: "bar" });
|
|
605
557
|
});
|
|
606
558
|
|
|
607
559
|
test("setAttribute variant and publish", async () => {
|
|
608
560
|
assert(productPublished, "product not created");
|
|
609
561
|
|
|
610
|
-
const response = await
|
|
611
|
-
|
|
612
|
-
.
|
|
562
|
+
const response = await ctMock.app.inject({
|
|
563
|
+
method: "POST",
|
|
564
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
565
|
+
payload: {
|
|
613
566
|
version: 1,
|
|
614
567
|
actions: [
|
|
615
568
|
{ action: "setAttribute", sku: "1338", name: "foo", value: "bar" },
|
|
616
569
|
{ action: "publish" },
|
|
617
570
|
],
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
expect(response.
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
).toHaveLength(2);
|
|
624
|
-
const attr =
|
|
571
|
+
},
|
|
572
|
+
});
|
|
573
|
+
expect(response.statusCode).toBe(200);
|
|
574
|
+
const body = response.json();
|
|
575
|
+
expect(body.version).toBe(3);
|
|
576
|
+
expect(body.masterData.current.variants[0].attributes).toHaveLength(2);
|
|
577
|
+
const attr = body.masterData.current.variants[0].attributes[1];
|
|
625
578
|
expect(attr).toEqual({ name: "foo", value: "bar" });
|
|
626
579
|
});
|
|
627
580
|
|
|
628
581
|
test("setAttribute overwrite", async () => {
|
|
629
582
|
assert(productPublished, "product not created");
|
|
630
583
|
|
|
631
|
-
const response = await
|
|
632
|
-
|
|
633
|
-
.
|
|
584
|
+
const response = await ctMock.app.inject({
|
|
585
|
+
method: "POST",
|
|
586
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
587
|
+
payload: {
|
|
634
588
|
version: 1,
|
|
635
589
|
actions: [
|
|
636
590
|
{ action: "setAttribute", sku: "1337", name: "test", value: "foo" },
|
|
637
591
|
],
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
expect(response.
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
).toHaveLength(1);
|
|
644
|
-
const attr =
|
|
592
|
+
},
|
|
593
|
+
});
|
|
594
|
+
expect(response.statusCode).toBe(200);
|
|
595
|
+
const body = response.json();
|
|
596
|
+
expect(body.version).toBe(2);
|
|
597
|
+
expect(body.masterData.staged.masterVariant.attributes).toHaveLength(1);
|
|
598
|
+
const attr = body.masterData.staged.masterVariant.attributes[0];
|
|
645
599
|
expect(attr).toEqual({ name: "test", value: "foo" });
|
|
646
600
|
});
|
|
647
601
|
|
|
648
602
|
test("setAttributeInAllVariants overwrite", async () => {
|
|
649
603
|
assert(productPublished, "product not created");
|
|
650
|
-
const response = await
|
|
651
|
-
|
|
652
|
-
.
|
|
604
|
+
const response = await ctMock.app.inject({
|
|
605
|
+
method: "POST",
|
|
606
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
607
|
+
payload: {
|
|
653
608
|
version: 1,
|
|
654
609
|
actions: [
|
|
655
610
|
{
|
|
@@ -658,9 +613,10 @@ describe("Product update actions", () => {
|
|
|
658
613
|
value: "foo",
|
|
659
614
|
},
|
|
660
615
|
],
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
|
|
616
|
+
},
|
|
617
|
+
});
|
|
618
|
+
expect(response.statusCode).toBe(200);
|
|
619
|
+
const product = response.json() as Product;
|
|
664
620
|
expect(product.version).toBe(2);
|
|
665
621
|
expect(product.masterData.staged.masterVariant.attributes).toHaveLength(1);
|
|
666
622
|
|
|
@@ -679,9 +635,10 @@ describe("Product update actions", () => {
|
|
|
679
635
|
|
|
680
636
|
test("setAttributeInAllVariants product staged", async () => {
|
|
681
637
|
assert(productPublished, "product not created");
|
|
682
|
-
const response = await
|
|
683
|
-
|
|
684
|
-
.
|
|
638
|
+
const response = await ctMock.app.inject({
|
|
639
|
+
method: "POST",
|
|
640
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
641
|
+
payload: {
|
|
685
642
|
version: 1,
|
|
686
643
|
actions: [
|
|
687
644
|
{
|
|
@@ -690,9 +647,10 @@ describe("Product update actions", () => {
|
|
|
690
647
|
value: "bar",
|
|
691
648
|
},
|
|
692
649
|
],
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
|
|
650
|
+
},
|
|
651
|
+
});
|
|
652
|
+
expect(response.statusCode).toBe(200);
|
|
653
|
+
const product = response.json() as Product;
|
|
696
654
|
expect(product.version).toBe(2);
|
|
697
655
|
expect(product.masterData.staged.masterVariant.attributes).toHaveLength(2);
|
|
698
656
|
const masterVariantAttr1 =
|
|
@@ -717,18 +675,20 @@ describe("Product update actions", () => {
|
|
|
717
675
|
test("setAttributeInAllVariants and publish", async () => {
|
|
718
676
|
assert(productPublished, "product not created");
|
|
719
677
|
|
|
720
|
-
const response = await
|
|
721
|
-
|
|
722
|
-
.
|
|
678
|
+
const response = await ctMock.app.inject({
|
|
679
|
+
method: "POST",
|
|
680
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
681
|
+
payload: {
|
|
723
682
|
version: 1,
|
|
724
683
|
actions: [
|
|
725
684
|
{ action: "setAttributeInAllVariants", name: "foo", value: "bar" },
|
|
726
685
|
{ action: "publish" },
|
|
727
686
|
],
|
|
728
|
-
}
|
|
687
|
+
},
|
|
688
|
+
});
|
|
729
689
|
|
|
730
|
-
const product = response.
|
|
731
|
-
expect(response.
|
|
690
|
+
const product = response.json() as Product;
|
|
691
|
+
expect(response.statusCode).toBe(200);
|
|
732
692
|
expect(product.version).toBe(3);
|
|
733
693
|
expect(product.masterData.current.masterVariant.attributes).toHaveLength(2);
|
|
734
694
|
const attr = product.masterData.current.masterVariant.attributes?.[1];
|
|
@@ -750,16 +710,19 @@ describe("Product update actions", () => {
|
|
|
750
710
|
url: "http://example.com/image",
|
|
751
711
|
dimensions: { w: 100, h: 100 },
|
|
752
712
|
};
|
|
753
|
-
const response = await
|
|
754
|
-
|
|
755
|
-
.
|
|
713
|
+
const response = await ctMock.app.inject({
|
|
714
|
+
method: "POST",
|
|
715
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
716
|
+
payload: {
|
|
756
717
|
version: 1,
|
|
757
718
|
actions: [{ action: "addExternalImage", sku: "1338", image }],
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
expect(response.
|
|
761
|
-
|
|
762
|
-
|
|
719
|
+
},
|
|
720
|
+
});
|
|
721
|
+
expect(response.statusCode).toBe(200);
|
|
722
|
+
const body = response.json();
|
|
723
|
+
expect(body.version).toBe(2);
|
|
724
|
+
expect(body.masterData.staged.variants[0].images).toHaveLength(1);
|
|
725
|
+
const attr = body.masterData.staged.variants[0].images[0];
|
|
763
726
|
expect(attr).toEqual(image);
|
|
764
727
|
});
|
|
765
728
|
|
|
@@ -772,19 +735,22 @@ describe("Product update actions", () => {
|
|
|
772
735
|
};
|
|
773
736
|
|
|
774
737
|
{
|
|
775
|
-
const response = await
|
|
776
|
-
|
|
777
|
-
.
|
|
738
|
+
const response = await ctMock.app.inject({
|
|
739
|
+
method: "POST",
|
|
740
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
741
|
+
payload: {
|
|
778
742
|
version: 1,
|
|
779
743
|
actions: [{ action: "addExternalImage", sku: "1338", image }],
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
expect(response.
|
|
744
|
+
},
|
|
745
|
+
});
|
|
746
|
+
expect(response.statusCode).toBe(200);
|
|
747
|
+
expect(response.json().version).toBe(2);
|
|
783
748
|
}
|
|
784
749
|
|
|
785
|
-
const response = await
|
|
786
|
-
|
|
787
|
-
.
|
|
750
|
+
const response = await ctMock.app.inject({
|
|
751
|
+
method: "POST",
|
|
752
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
753
|
+
payload: {
|
|
788
754
|
version: 2,
|
|
789
755
|
actions: [
|
|
790
756
|
{
|
|
@@ -793,10 +759,12 @@ describe("Product update actions", () => {
|
|
|
793
759
|
imageUrl: image.url,
|
|
794
760
|
},
|
|
795
761
|
],
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
expect(response.
|
|
799
|
-
|
|
762
|
+
},
|
|
763
|
+
});
|
|
764
|
+
expect(response.statusCode).toBe(200);
|
|
765
|
+
const body = response.json();
|
|
766
|
+
expect(body.version).toBe(3);
|
|
767
|
+
expect(body.masterData.staged.variants[0].images).toHaveLength(0);
|
|
800
768
|
});
|
|
801
769
|
|
|
802
770
|
test("moveImageToPosition variant", async () => {
|
|
@@ -812,22 +780,25 @@ describe("Product update actions", () => {
|
|
|
812
780
|
};
|
|
813
781
|
|
|
814
782
|
{
|
|
815
|
-
const response = await
|
|
816
|
-
|
|
817
|
-
.
|
|
783
|
+
const response = await ctMock.app.inject({
|
|
784
|
+
method: "POST",
|
|
785
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
786
|
+
payload: {
|
|
818
787
|
version: 1,
|
|
819
788
|
actions: [
|
|
820
789
|
{ action: "addExternalImage", sku: "1338", image: image1 },
|
|
821
790
|
{ action: "addExternalImage", sku: "1338", image: image2 },
|
|
822
791
|
],
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
expect(response.
|
|
792
|
+
},
|
|
793
|
+
});
|
|
794
|
+
expect(response.statusCode).toBe(200);
|
|
795
|
+
expect(response.json().version).toBe(3);
|
|
826
796
|
}
|
|
827
797
|
|
|
828
|
-
const response = await
|
|
829
|
-
|
|
830
|
-
.
|
|
798
|
+
const response = await ctMock.app.inject({
|
|
799
|
+
method: "POST",
|
|
800
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
801
|
+
payload: {
|
|
831
802
|
version: 3,
|
|
832
803
|
actions: [
|
|
833
804
|
{
|
|
@@ -837,10 +808,12 @@ describe("Product update actions", () => {
|
|
|
837
808
|
position: 0,
|
|
838
809
|
},
|
|
839
810
|
],
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
expect(response.
|
|
843
|
-
|
|
811
|
+
},
|
|
812
|
+
});
|
|
813
|
+
expect(response.statusCode).toBe(200);
|
|
814
|
+
const body = response.json();
|
|
815
|
+
expect(body.version).toBe(4);
|
|
816
|
+
expect(body.masterData.staged.variants[0].images).toEqual([
|
|
844
817
|
{ url: "http://example.com/image2", dimensions: { w: 100, h: 100 } },
|
|
845
818
|
{ url: "http://example.com/image1", dimensions: { w: 100, h: 100 } },
|
|
846
819
|
]);
|
|
@@ -857,9 +830,10 @@ describe("Product update actions", () => {
|
|
|
857
830
|
},
|
|
858
831
|
};
|
|
859
832
|
|
|
860
|
-
const response = await
|
|
861
|
-
|
|
862
|
-
.
|
|
833
|
+
const response = await ctMock.app.inject({
|
|
834
|
+
method: "POST",
|
|
835
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
836
|
+
payload: {
|
|
863
837
|
version: 1,
|
|
864
838
|
actions: [
|
|
865
839
|
{
|
|
@@ -869,10 +843,12 @@ describe("Product update actions", () => {
|
|
|
869
843
|
staged: false,
|
|
870
844
|
},
|
|
871
845
|
],
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
expect(response.
|
|
875
|
-
|
|
846
|
+
},
|
|
847
|
+
});
|
|
848
|
+
expect(response.statusCode).toBe(200);
|
|
849
|
+
const body = response.json();
|
|
850
|
+
expect(body.version).toBe(2);
|
|
851
|
+
expect(body.masterData.staged.masterVariant.prices).toMatchObject([
|
|
876
852
|
{
|
|
877
853
|
country: "NL",
|
|
878
854
|
value: {
|
|
@@ -888,8 +864,8 @@ describe("Product update actions", () => {
|
|
|
888
864
|
},
|
|
889
865
|
},
|
|
890
866
|
]);
|
|
891
|
-
expect(
|
|
892
|
-
|
|
867
|
+
expect(body.masterData.staged.masterVariant.prices[1].id).toBe(
|
|
868
|
+
body.masterData.current.masterVariant.prices[1].id,
|
|
893
869
|
);
|
|
894
870
|
});
|
|
895
871
|
|
|
@@ -907,9 +883,10 @@ describe("Product update actions", () => {
|
|
|
907
883
|
},
|
|
908
884
|
};
|
|
909
885
|
|
|
910
|
-
const response = await
|
|
911
|
-
|
|
912
|
-
.
|
|
886
|
+
const response = await ctMock.app.inject({
|
|
887
|
+
method: "POST",
|
|
888
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
889
|
+
payload: {
|
|
913
890
|
version: 1,
|
|
914
891
|
actions: [
|
|
915
892
|
{
|
|
@@ -918,10 +895,12 @@ describe("Product update actions", () => {
|
|
|
918
895
|
price: priceDraft,
|
|
919
896
|
},
|
|
920
897
|
],
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
expect(response.
|
|
924
|
-
|
|
898
|
+
},
|
|
899
|
+
});
|
|
900
|
+
expect(response.statusCode).toBe(200);
|
|
901
|
+
const body = response.json();
|
|
902
|
+
expect(body.version).toBe(2);
|
|
903
|
+
expect(body.masterData.staged.masterVariant.prices).toMatchObject([
|
|
925
904
|
{
|
|
926
905
|
id: priceId,
|
|
927
906
|
country: "BE",
|
|
@@ -939,9 +918,10 @@ describe("Product update actions", () => {
|
|
|
939
918
|
productPublished?.masterData.current.masterVariant.prices?.[0].id;
|
|
940
919
|
assert(priceId);
|
|
941
920
|
|
|
942
|
-
const response = await
|
|
943
|
-
|
|
944
|
-
.
|
|
921
|
+
const response = await ctMock.app.inject({
|
|
922
|
+
method: "POST",
|
|
923
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
924
|
+
payload: {
|
|
945
925
|
version: 1,
|
|
946
926
|
actions: [
|
|
947
927
|
{
|
|
@@ -949,19 +929,20 @@ describe("Product update actions", () => {
|
|
|
949
929
|
priceId,
|
|
950
930
|
},
|
|
951
931
|
],
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
expect(response.
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
);
|
|
932
|
+
},
|
|
933
|
+
});
|
|
934
|
+
expect(response.statusCode).toBe(200);
|
|
935
|
+
const body = response.json();
|
|
936
|
+
expect(body.version).toBe(2);
|
|
937
|
+
expect(body.masterData.staged.masterVariant.prices).toHaveLength(0);
|
|
958
938
|
});
|
|
959
939
|
|
|
960
940
|
test("changeName product", async () => {
|
|
961
941
|
assert(productPublished, "product not created");
|
|
962
|
-
const response = await
|
|
963
|
-
|
|
964
|
-
.
|
|
942
|
+
const response = await ctMock.app.inject({
|
|
943
|
+
method: "POST",
|
|
944
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
945
|
+
payload: {
|
|
965
946
|
version: 1,
|
|
966
947
|
actions: [
|
|
967
948
|
{
|
|
@@ -970,22 +951,21 @@ describe("Product update actions", () => {
|
|
|
970
951
|
staged: false,
|
|
971
952
|
},
|
|
972
953
|
],
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
expect(response.
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
);
|
|
979
|
-
expect(
|
|
980
|
-
"new test published product",
|
|
981
|
-
);
|
|
954
|
+
},
|
|
955
|
+
});
|
|
956
|
+
expect(response.statusCode).toBe(200);
|
|
957
|
+
const body = response.json();
|
|
958
|
+
expect(body.version).toBe(2);
|
|
959
|
+
expect(body.masterData.staged.name).toBe("new test published product");
|
|
960
|
+
expect(body.masterData.current.name).toBe("new test published product");
|
|
982
961
|
});
|
|
983
962
|
|
|
984
963
|
test("changeSlug product", async () => {
|
|
985
964
|
assert(productPublished, "product not created");
|
|
986
|
-
const response = await
|
|
987
|
-
|
|
988
|
-
.
|
|
965
|
+
const response = await ctMock.app.inject({
|
|
966
|
+
method: "POST",
|
|
967
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
968
|
+
payload: {
|
|
989
969
|
version: 1,
|
|
990
970
|
actions: [
|
|
991
971
|
{
|
|
@@ -996,22 +976,25 @@ describe("Product update actions", () => {
|
|
|
996
976
|
staged: false,
|
|
997
977
|
},
|
|
998
978
|
],
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
expect(response.
|
|
1002
|
-
|
|
979
|
+
},
|
|
980
|
+
});
|
|
981
|
+
expect(response.statusCode).toBe(200);
|
|
982
|
+
const body = response.json();
|
|
983
|
+
expect(body.version).toBe(2);
|
|
984
|
+
expect(body.masterData.staged.slug).toMatchObject({
|
|
1003
985
|
"nl-NL": "test-published-product-new",
|
|
1004
986
|
});
|
|
1005
|
-
expect(
|
|
987
|
+
expect(body.masterData.current.slug).toMatchObject({
|
|
1006
988
|
"nl-NL": "test-published-product-new",
|
|
1007
989
|
});
|
|
1008
990
|
});
|
|
1009
991
|
|
|
1010
992
|
test("setMetaTitle product", async () => {
|
|
1011
993
|
assert(productPublished, "product not created");
|
|
1012
|
-
const response = await
|
|
1013
|
-
|
|
1014
|
-
.
|
|
994
|
+
const response = await ctMock.app.inject({
|
|
995
|
+
method: "POST",
|
|
996
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
997
|
+
payload: {
|
|
1015
998
|
version: 1,
|
|
1016
999
|
actions: [
|
|
1017
1000
|
{
|
|
@@ -1022,22 +1005,25 @@ describe("Product update actions", () => {
|
|
|
1022
1005
|
staged: false,
|
|
1023
1006
|
},
|
|
1024
1007
|
],
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
expect(response.
|
|
1028
|
-
|
|
1008
|
+
},
|
|
1009
|
+
});
|
|
1010
|
+
expect(response.statusCode).toBe(200);
|
|
1011
|
+
const body = response.json();
|
|
1012
|
+
expect(body.version).toBe(2);
|
|
1013
|
+
expect(body.masterData.staged.metaTitle).toMatchObject({
|
|
1029
1014
|
"nl-NL": "Unpublished product (new meta title)",
|
|
1030
1015
|
});
|
|
1031
|
-
expect(
|
|
1016
|
+
expect(body.masterData.current.metaTitle).toMatchObject({
|
|
1032
1017
|
"nl-NL": "Unpublished product (new meta title)",
|
|
1033
1018
|
});
|
|
1034
1019
|
});
|
|
1035
1020
|
|
|
1036
1021
|
test("setMetaDescription product", async () => {
|
|
1037
1022
|
assert(productPublished, "product not created");
|
|
1038
|
-
const response = await
|
|
1039
|
-
|
|
1040
|
-
.
|
|
1023
|
+
const response = await ctMock.app.inject({
|
|
1024
|
+
method: "POST",
|
|
1025
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1026
|
+
payload: {
|
|
1041
1027
|
version: 1,
|
|
1042
1028
|
actions: [
|
|
1043
1029
|
{
|
|
@@ -1048,22 +1034,25 @@ describe("Product update actions", () => {
|
|
|
1048
1034
|
staged: false,
|
|
1049
1035
|
},
|
|
1050
1036
|
],
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
expect(response.
|
|
1054
|
-
|
|
1037
|
+
},
|
|
1038
|
+
});
|
|
1039
|
+
expect(response.statusCode).toBe(200);
|
|
1040
|
+
const body = response.json();
|
|
1041
|
+
expect(body.version).toBe(2);
|
|
1042
|
+
expect(body.masterData.staged.metaDescription).toMatchObject({
|
|
1055
1043
|
"nl-NL": "Unpublished product description (new meta description)",
|
|
1056
1044
|
});
|
|
1057
|
-
expect(
|
|
1045
|
+
expect(body.masterData.current.metaDescription).toMatchObject({
|
|
1058
1046
|
"nl-NL": "Unpublished product description (new meta description)",
|
|
1059
1047
|
});
|
|
1060
1048
|
});
|
|
1061
1049
|
|
|
1062
1050
|
test("setMetaKeywords product", async () => {
|
|
1063
1051
|
assert(productPublished, "product not created");
|
|
1064
|
-
const response = await
|
|
1065
|
-
|
|
1066
|
-
.
|
|
1052
|
+
const response = await ctMock.app.inject({
|
|
1053
|
+
method: "POST",
|
|
1054
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1055
|
+
payload: {
|
|
1067
1056
|
version: 1,
|
|
1068
1057
|
actions: [
|
|
1069
1058
|
{
|
|
@@ -1074,22 +1063,25 @@ describe("Product update actions", () => {
|
|
|
1074
1063
|
staged: false,
|
|
1075
1064
|
},
|
|
1076
1065
|
],
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
expect(response.
|
|
1080
|
-
|
|
1066
|
+
},
|
|
1067
|
+
});
|
|
1068
|
+
expect(response.statusCode).toBe(200);
|
|
1069
|
+
const body = response.json();
|
|
1070
|
+
expect(body.version).toBe(2);
|
|
1071
|
+
expect(body.masterData.staged.metaKeywords).toMatchObject({
|
|
1081
1072
|
"nl-NL": "Test product (newmeta Keywords)",
|
|
1082
1073
|
});
|
|
1083
|
-
expect(
|
|
1074
|
+
expect(body.masterData.current.metaKeywords).toMatchObject({
|
|
1084
1075
|
"nl-NL": "Test product (newmeta Keywords)",
|
|
1085
1076
|
});
|
|
1086
1077
|
});
|
|
1087
1078
|
|
|
1088
1079
|
test("addVariant product", async () => {
|
|
1089
1080
|
assert(productPublished, "product not created");
|
|
1090
|
-
const response = await
|
|
1091
|
-
|
|
1092
|
-
.
|
|
1081
|
+
const response = await ctMock.app.inject({
|
|
1082
|
+
method: "POST",
|
|
1083
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1084
|
+
payload: {
|
|
1093
1085
|
version: 1,
|
|
1094
1086
|
actions: [
|
|
1095
1087
|
{
|
|
@@ -1117,20 +1109,23 @@ describe("Product update actions", () => {
|
|
|
1117
1109
|
staged: false,
|
|
1118
1110
|
},
|
|
1119
1111
|
],
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
expect(response.
|
|
1123
|
-
|
|
1124
|
-
expect(
|
|
1125
|
-
expect(
|
|
1126
|
-
expect(
|
|
1112
|
+
},
|
|
1113
|
+
});
|
|
1114
|
+
expect(response.statusCode).toBe(200);
|
|
1115
|
+
const body = response.json();
|
|
1116
|
+
expect(body.version).toBe(2);
|
|
1117
|
+
expect(body.masterData.staged.variants).toHaveLength(2);
|
|
1118
|
+
expect(body.masterData.current.variants).toHaveLength(2);
|
|
1119
|
+
expect(body.masterData.staged.variants[1].id).toBe(3);
|
|
1120
|
+
expect(body.masterData.current.variants[1].id).toBe(3);
|
|
1127
1121
|
});
|
|
1128
1122
|
|
|
1129
1123
|
test("removeVariant by id", async () => {
|
|
1130
1124
|
assert(productPublished, "product not created");
|
|
1131
|
-
const response = await
|
|
1132
|
-
|
|
1133
|
-
.
|
|
1125
|
+
const response = await ctMock.app.inject({
|
|
1126
|
+
method: "POST",
|
|
1127
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1128
|
+
payload: {
|
|
1134
1129
|
version: 1,
|
|
1135
1130
|
actions: [
|
|
1136
1131
|
{
|
|
@@ -1139,18 +1134,21 @@ describe("Product update actions", () => {
|
|
|
1139
1134
|
staged: false,
|
|
1140
1135
|
},
|
|
1141
1136
|
],
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
expect(response.
|
|
1145
|
-
|
|
1146
|
-
expect(
|
|
1137
|
+
},
|
|
1138
|
+
});
|
|
1139
|
+
expect(response.statusCode).toBe(200);
|
|
1140
|
+
const body = response.json();
|
|
1141
|
+
expect(body.version).toBe(2);
|
|
1142
|
+
expect(body.masterData.staged.variants).toHaveLength(0);
|
|
1143
|
+
expect(body.masterData.current.variants).toHaveLength(0);
|
|
1147
1144
|
});
|
|
1148
1145
|
|
|
1149
1146
|
test("removeVariant by sku", async () => {
|
|
1150
1147
|
assert(productPublished, "product not created");
|
|
1151
|
-
const response = await
|
|
1152
|
-
|
|
1153
|
-
.
|
|
1148
|
+
const response = await ctMock.app.inject({
|
|
1149
|
+
method: "POST",
|
|
1150
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1151
|
+
payload: {
|
|
1154
1152
|
version: 1,
|
|
1155
1153
|
actions: [
|
|
1156
1154
|
{
|
|
@@ -1159,18 +1157,21 @@ describe("Product update actions", () => {
|
|
|
1159
1157
|
staged: false,
|
|
1160
1158
|
},
|
|
1161
1159
|
],
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
expect(response.
|
|
1165
|
-
|
|
1166
|
-
expect(
|
|
1160
|
+
},
|
|
1161
|
+
});
|
|
1162
|
+
expect(response.statusCode).toBe(200);
|
|
1163
|
+
const body = response.json();
|
|
1164
|
+
expect(body.version).toBe(2);
|
|
1165
|
+
expect(body.masterData.staged.variants).toHaveLength(0);
|
|
1166
|
+
expect(body.masterData.current.variants).toHaveLength(0);
|
|
1167
1167
|
});
|
|
1168
1168
|
|
|
1169
1169
|
test("removeVariant master", async () => {
|
|
1170
1170
|
assert(productPublished, "product not created");
|
|
1171
|
-
const response = await
|
|
1172
|
-
|
|
1173
|
-
.
|
|
1171
|
+
const response = await ctMock.app.inject({
|
|
1172
|
+
method: "POST",
|
|
1173
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1174
|
+
payload: {
|
|
1174
1175
|
version: 1,
|
|
1175
1176
|
actions: [
|
|
1176
1177
|
{
|
|
@@ -1179,18 +1180,21 @@ describe("Product update actions", () => {
|
|
|
1179
1180
|
staged: false,
|
|
1180
1181
|
},
|
|
1181
1182
|
],
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
expect(response.
|
|
1183
|
+
},
|
|
1184
|
+
});
|
|
1185
|
+
expect(response.statusCode).toBe(400);
|
|
1186
|
+
expect(response.json().errors[0].code).toBe("InvalidOperation");
|
|
1187
|
+
expect(response.json().message).toBe(
|
|
1185
1188
|
`Can not remove the variant [ID:1] for [Product:${productPublished.id}] since it's the master variant`,
|
|
1186
1189
|
);
|
|
1187
1190
|
});
|
|
1188
1191
|
|
|
1189
1192
|
test("changeMasterVariant", async () => {
|
|
1190
1193
|
assert(productPublished, "product not created");
|
|
1191
|
-
const response = await
|
|
1192
|
-
|
|
1193
|
-
.
|
|
1194
|
+
const response = await ctMock.app.inject({
|
|
1195
|
+
method: "POST",
|
|
1196
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1197
|
+
payload: {
|
|
1194
1198
|
version: 1,
|
|
1195
1199
|
actions: [
|
|
1196
1200
|
{
|
|
@@ -1199,23 +1203,26 @@ describe("Product update actions", () => {
|
|
|
1199
1203
|
staged: false,
|
|
1200
1204
|
},
|
|
1201
1205
|
],
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
expect(response.
|
|
1205
|
-
|
|
1206
|
-
expect(
|
|
1207
|
-
expect(
|
|
1208
|
-
|
|
1209
|
-
expect(
|
|
1210
|
-
|
|
1211
|
-
expect(
|
|
1206
|
+
},
|
|
1207
|
+
});
|
|
1208
|
+
expect(response.statusCode).toBe(200);
|
|
1209
|
+
const body = response.json();
|
|
1210
|
+
expect(body.version).toBe(2);
|
|
1211
|
+
expect(body.masterData.staged.variants).toHaveLength(1);
|
|
1212
|
+
expect(body.masterData.staged.masterVariant.id).toBe(2);
|
|
1213
|
+
expect(body.masterData.staged.variants[0].id).toBe(1);
|
|
1214
|
+
|
|
1215
|
+
expect(body.masterData.current.variants).toHaveLength(1);
|
|
1216
|
+
expect(body.masterData.current.masterVariant.id).toBe(2);
|
|
1217
|
+
expect(body.masterData.current.variants[0].id).toBe(1);
|
|
1212
1218
|
});
|
|
1213
1219
|
|
|
1214
1220
|
test("changeMasterVariant same master", async () => {
|
|
1215
1221
|
assert(productPublished, "product not created");
|
|
1216
|
-
const response = await
|
|
1217
|
-
|
|
1218
|
-
.
|
|
1222
|
+
const response = await ctMock.app.inject({
|
|
1223
|
+
method: "POST",
|
|
1224
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1225
|
+
payload: {
|
|
1219
1226
|
version: 1,
|
|
1220
1227
|
actions: [
|
|
1221
1228
|
{
|
|
@@ -1224,23 +1231,26 @@ describe("Product update actions", () => {
|
|
|
1224
1231
|
staged: false,
|
|
1225
1232
|
},
|
|
1226
1233
|
],
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
expect(response.
|
|
1230
|
-
|
|
1231
|
-
expect(
|
|
1232
|
-
expect(
|
|
1233
|
-
|
|
1234
|
-
expect(
|
|
1235
|
-
|
|
1236
|
-
expect(
|
|
1234
|
+
},
|
|
1235
|
+
});
|
|
1236
|
+
expect(response.statusCode).toBe(200);
|
|
1237
|
+
const body = response.json();
|
|
1238
|
+
expect(body.version).toBe(1);
|
|
1239
|
+
expect(body.masterData.staged.variants).toHaveLength(1);
|
|
1240
|
+
expect(body.masterData.staged.masterVariant.id).toBe(1);
|
|
1241
|
+
expect(body.masterData.staged.variants[0].id).toBe(2);
|
|
1242
|
+
|
|
1243
|
+
expect(body.masterData.current.variants).toHaveLength(1);
|
|
1244
|
+
expect(body.masterData.current.masterVariant.id).toBe(1);
|
|
1245
|
+
expect(body.masterData.current.variants[0].id).toBe(2);
|
|
1237
1246
|
});
|
|
1238
1247
|
|
|
1239
1248
|
test("setTaxCategory", async () => {
|
|
1240
1249
|
assert(productPublished, "product not created");
|
|
1241
|
-
const response = await
|
|
1242
|
-
|
|
1243
|
-
.
|
|
1250
|
+
const response = await ctMock.app.inject({
|
|
1251
|
+
method: "POST",
|
|
1252
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1253
|
+
payload: {
|
|
1244
1254
|
version: 1,
|
|
1245
1255
|
actions: [
|
|
1246
1256
|
{
|
|
@@ -1251,17 +1261,19 @@ describe("Product update actions", () => {
|
|
|
1251
1261
|
},
|
|
1252
1262
|
},
|
|
1253
1263
|
],
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
expect(response.
|
|
1264
|
+
},
|
|
1265
|
+
});
|
|
1266
|
+
expect(response.statusCode).toBe(200);
|
|
1267
|
+
expect(response.json().taxCategory.id).toBe(taxCategory2.id);
|
|
1257
1268
|
});
|
|
1258
1269
|
|
|
1259
1270
|
test("setTaxCategory fail 1", async () => {
|
|
1260
1271
|
assert(productPublished, "product not created");
|
|
1261
1272
|
const fakeTaxCategoryId = "00000000-0000-0000-0000-000000000000";
|
|
1262
|
-
const response = await
|
|
1263
|
-
|
|
1264
|
-
.
|
|
1273
|
+
const response = await ctMock.app.inject({
|
|
1274
|
+
method: "POST",
|
|
1275
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1276
|
+
payload: {
|
|
1265
1277
|
version: 1,
|
|
1266
1278
|
actions: [
|
|
1267
1279
|
{
|
|
@@ -1272,16 +1284,18 @@ describe("Product update actions", () => {
|
|
|
1272
1284
|
},
|
|
1273
1285
|
},
|
|
1274
1286
|
],
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
expect(response.
|
|
1287
|
+
},
|
|
1288
|
+
});
|
|
1289
|
+
expect(response.statusCode).toBe(400);
|
|
1290
|
+
expect(response.json().errors[0].code).toBe("ReferencedResourceNotFound");
|
|
1278
1291
|
});
|
|
1279
1292
|
|
|
1280
1293
|
test("setTaxCategory fail 2", async () => {
|
|
1281
1294
|
assert(productPublished, "product not created");
|
|
1282
|
-
const response = await
|
|
1283
|
-
|
|
1284
|
-
.
|
|
1295
|
+
const response = await ctMock.app.inject({
|
|
1296
|
+
method: "POST",
|
|
1297
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1298
|
+
payload: {
|
|
1285
1299
|
version: 1,
|
|
1286
1300
|
actions: [
|
|
1287
1301
|
{
|
|
@@ -1291,16 +1305,18 @@ describe("Product update actions", () => {
|
|
|
1291
1305
|
},
|
|
1292
1306
|
},
|
|
1293
1307
|
],
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
expect(response.
|
|
1308
|
+
},
|
|
1309
|
+
});
|
|
1310
|
+
expect(response.statusCode).toBe(400);
|
|
1311
|
+
expect(response.json().errors[0].code).toBe("InvalidJsonInput");
|
|
1297
1312
|
});
|
|
1298
1313
|
|
|
1299
1314
|
test("addToCategory by id", async () => {
|
|
1300
1315
|
assert(productPublished, "product not created");
|
|
1301
|
-
const response = await
|
|
1302
|
-
|
|
1303
|
-
.
|
|
1316
|
+
const response = await ctMock.app.inject({
|
|
1317
|
+
method: "POST",
|
|
1318
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1319
|
+
payload: {
|
|
1304
1320
|
version: 1,
|
|
1305
1321
|
actions: [
|
|
1306
1322
|
{
|
|
@@ -1312,17 +1328,20 @@ describe("Product update actions", () => {
|
|
|
1312
1328
|
staged: false,
|
|
1313
1329
|
},
|
|
1314
1330
|
],
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
expect(response.
|
|
1318
|
-
|
|
1331
|
+
},
|
|
1332
|
+
});
|
|
1333
|
+
expect(response.statusCode).toBe(200);
|
|
1334
|
+
const body = response.json();
|
|
1335
|
+
expect(body.masterData.staged.categories).toHaveLength(2);
|
|
1336
|
+
expect(body.masterData.current.categories).toHaveLength(2);
|
|
1319
1337
|
});
|
|
1320
1338
|
|
|
1321
1339
|
test("addToCategory by key", async () => {
|
|
1322
1340
|
assert(productPublished, "product not created");
|
|
1323
|
-
const response = await
|
|
1324
|
-
|
|
1325
|
-
.
|
|
1341
|
+
const response = await ctMock.app.inject({
|
|
1342
|
+
method: "POST",
|
|
1343
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1344
|
+
payload: {
|
|
1326
1345
|
version: 1,
|
|
1327
1346
|
actions: [
|
|
1328
1347
|
{
|
|
@@ -1334,18 +1353,21 @@ describe("Product update actions", () => {
|
|
|
1334
1353
|
staged: true,
|
|
1335
1354
|
},
|
|
1336
1355
|
],
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
expect(response.
|
|
1340
|
-
|
|
1356
|
+
},
|
|
1357
|
+
});
|
|
1358
|
+
expect(response.statusCode).toBe(200);
|
|
1359
|
+
const body = response.json();
|
|
1360
|
+
expect(body.masterData.staged.categories).toHaveLength(2);
|
|
1361
|
+
expect(body.masterData.current.categories).toHaveLength(1);
|
|
1341
1362
|
});
|
|
1342
1363
|
|
|
1343
1364
|
test("addToCategory fail 1", async () => {
|
|
1344
1365
|
assert(productPublished, "product not created");
|
|
1345
1366
|
const fakeCategoryId = "00000000-0000-0000-0000-000000000000";
|
|
1346
|
-
const response = await
|
|
1347
|
-
|
|
1348
|
-
.
|
|
1367
|
+
const response = await ctMock.app.inject({
|
|
1368
|
+
method: "POST",
|
|
1369
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1370
|
+
payload: {
|
|
1349
1371
|
version: 1,
|
|
1350
1372
|
actions: [
|
|
1351
1373
|
{
|
|
@@ -1357,16 +1379,18 @@ describe("Product update actions", () => {
|
|
|
1357
1379
|
staged: true,
|
|
1358
1380
|
},
|
|
1359
1381
|
],
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
expect(response.
|
|
1382
|
+
},
|
|
1383
|
+
});
|
|
1384
|
+
expect(response.statusCode).toBe(400);
|
|
1385
|
+
expect(response.json().errors[0].code).toBe("ReferencedResourceNotFound");
|
|
1363
1386
|
});
|
|
1364
1387
|
|
|
1365
1388
|
test("addToCategory fail 2", async () => {
|
|
1366
1389
|
assert(productPublished, "product not created");
|
|
1367
|
-
const response = await
|
|
1368
|
-
|
|
1369
|
-
.
|
|
1390
|
+
const response = await ctMock.app.inject({
|
|
1391
|
+
method: "POST",
|
|
1392
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1393
|
+
payload: {
|
|
1370
1394
|
version: 1,
|
|
1371
1395
|
actions: [
|
|
1372
1396
|
{
|
|
@@ -1375,16 +1399,18 @@ describe("Product update actions", () => {
|
|
|
1375
1399
|
staged: true,
|
|
1376
1400
|
},
|
|
1377
1401
|
],
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
expect(response.
|
|
1402
|
+
},
|
|
1403
|
+
});
|
|
1404
|
+
expect(response.statusCode).toBe(400);
|
|
1405
|
+
expect(response.json().errors[0].code).toBe("InvalidJsonInput");
|
|
1381
1406
|
});
|
|
1382
1407
|
|
|
1383
1408
|
test("removeFromCategory", async () => {
|
|
1384
1409
|
assert(productPublished, "product not created");
|
|
1385
|
-
const response = await
|
|
1386
|
-
|
|
1387
|
-
.
|
|
1410
|
+
const response = await ctMock.app.inject({
|
|
1411
|
+
method: "POST",
|
|
1412
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1413
|
+
payload: {
|
|
1388
1414
|
version: 1,
|
|
1389
1415
|
actions: [
|
|
1390
1416
|
{
|
|
@@ -1396,17 +1422,20 @@ describe("Product update actions", () => {
|
|
|
1396
1422
|
staged: false,
|
|
1397
1423
|
},
|
|
1398
1424
|
],
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
expect(response.
|
|
1402
|
-
|
|
1425
|
+
},
|
|
1426
|
+
});
|
|
1427
|
+
expect(response.statusCode).toBe(200);
|
|
1428
|
+
const body = response.json();
|
|
1429
|
+
expect(body.masterData.staged.categories).toHaveLength(0);
|
|
1430
|
+
expect(body.masterData.current.categories).toHaveLength(0);
|
|
1403
1431
|
});
|
|
1404
1432
|
|
|
1405
1433
|
test("removeFromCategory fail 1", async () => {
|
|
1406
1434
|
assert(productPublished, "product not created");
|
|
1407
|
-
const response = await
|
|
1408
|
-
|
|
1409
|
-
.
|
|
1435
|
+
const response = await ctMock.app.inject({
|
|
1436
|
+
method: "POST",
|
|
1437
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1438
|
+
payload: {
|
|
1410
1439
|
version: 1,
|
|
1411
1440
|
actions: [
|
|
1412
1441
|
{
|
|
@@ -1418,16 +1447,18 @@ describe("Product update actions", () => {
|
|
|
1418
1447
|
staged: false,
|
|
1419
1448
|
},
|
|
1420
1449
|
],
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
expect(response.
|
|
1450
|
+
},
|
|
1451
|
+
});
|
|
1452
|
+
expect(response.statusCode).toBe(400);
|
|
1453
|
+
expect(response.json().errors[0].code).toBe("ReferencedResourceNotFound");
|
|
1424
1454
|
});
|
|
1425
1455
|
|
|
1426
1456
|
test("removeFromCategory fail 2", async () => {
|
|
1427
1457
|
assert(productPublished, "product not created");
|
|
1428
|
-
const response = await
|
|
1429
|
-
|
|
1430
|
-
.
|
|
1458
|
+
const response = await ctMock.app.inject({
|
|
1459
|
+
method: "POST",
|
|
1460
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1461
|
+
payload: {
|
|
1431
1462
|
version: 1,
|
|
1432
1463
|
actions: [
|
|
1433
1464
|
{
|
|
@@ -1439,16 +1470,18 @@ describe("Product update actions", () => {
|
|
|
1439
1470
|
staged: false,
|
|
1440
1471
|
},
|
|
1441
1472
|
],
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
expect(response.
|
|
1473
|
+
},
|
|
1474
|
+
});
|
|
1475
|
+
expect(response.statusCode).toBe(400);
|
|
1476
|
+
expect(response.json().errors[0].code).toBe("InvalidOperation");
|
|
1445
1477
|
});
|
|
1446
1478
|
|
|
1447
1479
|
test("transitionState", async () => {
|
|
1448
1480
|
assert(productPublished, "product not created");
|
|
1449
|
-
const response = await
|
|
1450
|
-
|
|
1451
|
-
.
|
|
1481
|
+
const response = await ctMock.app.inject({
|
|
1482
|
+
method: "POST",
|
|
1483
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1484
|
+
payload: {
|
|
1452
1485
|
version: 1,
|
|
1453
1486
|
actions: [
|
|
1454
1487
|
{
|
|
@@ -1460,9 +1493,10 @@ describe("Product update actions", () => {
|
|
|
1460
1493
|
force: false,
|
|
1461
1494
|
},
|
|
1462
1495
|
],
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
expect(response.
|
|
1496
|
+
},
|
|
1497
|
+
});
|
|
1498
|
+
expect(response.statusCode).toBe(200);
|
|
1499
|
+
expect(response.json().state).toMatchObject({
|
|
1466
1500
|
typeId: "state",
|
|
1467
1501
|
id: productState2.id,
|
|
1468
1502
|
});
|
|
@@ -1474,9 +1508,10 @@ describe("Product update actions", () => {
|
|
|
1474
1508
|
productPublished?.masterData.current.masterVariant.prices?.[0].id;
|
|
1475
1509
|
assert(priceId);
|
|
1476
1510
|
|
|
1477
|
-
const response = await
|
|
1478
|
-
|
|
1479
|
-
.
|
|
1511
|
+
const response = await ctMock.app.inject({
|
|
1512
|
+
method: "POST",
|
|
1513
|
+
url: `/dummy/products/${productPublished.id}`,
|
|
1514
|
+
payload: {
|
|
1480
1515
|
version: 1,
|
|
1481
1516
|
actions: [
|
|
1482
1517
|
{
|
|
@@ -1494,10 +1529,11 @@ describe("Product update actions", () => {
|
|
|
1494
1529
|
priceId,
|
|
1495
1530
|
},
|
|
1496
1531
|
],
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1532
|
+
},
|
|
1533
|
+
});
|
|
1534
|
+
expect(response.statusCode).toBe(200);
|
|
1499
1535
|
expect(
|
|
1500
|
-
response.
|
|
1536
|
+
response.json().masterData.staged.masterVariant.prices?.[0].custom.fields
|
|
1501
1537
|
?.myCustomField,
|
|
1502
1538
|
).toBe("MyRandomValue");
|
|
1503
1539
|
});
|
|
@@ -1506,33 +1542,15 @@ describe("Product update actions", () => {
|
|
|
1506
1542
|
// Test the general product search implementation
|
|
1507
1543
|
describe("Product Search - Generic", () => {
|
|
1508
1544
|
const ctMock = new CommercetoolsMock();
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
const inventoryEntryDraft: InventoryEntryDraft = {
|
|
1512
|
-
key: `${sku}_stock`,
|
|
1513
|
-
sku,
|
|
1514
|
-
quantityOnStock: quantity,
|
|
1515
|
-
supplyChannel: {
|
|
1516
|
-
typeId: "channel",
|
|
1517
|
-
id: "dummy-inventory-channel",
|
|
1518
|
-
},
|
|
1519
|
-
};
|
|
1520
|
-
|
|
1521
|
-
await supertest(ctMock.app)
|
|
1522
|
-
.post("/dummy/inventory")
|
|
1523
|
-
.send(inventoryEntryDraft);
|
|
1524
|
-
}
|
|
1545
|
+
const productFactory = productDraftFactory(ctMock);
|
|
1546
|
+
const inventoryFactory = inventoryEntryDraftFactory(ctMock);
|
|
1525
1547
|
|
|
1526
1548
|
beforeAll(async () => {
|
|
1527
1549
|
await beforeAllProductTests(ctMock);
|
|
1528
1550
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
.send(publishedProductDraft);
|
|
1533
|
-
|
|
1534
|
-
expect(response.status).toBe(201);
|
|
1535
|
-
});
|
|
1551
|
+
for (let i = 0; i < 24; i++) {
|
|
1552
|
+
await productFactory.create(publishedProductDraftOverrides);
|
|
1553
|
+
}
|
|
1536
1554
|
});
|
|
1537
1555
|
|
|
1538
1556
|
test("Pagination", async () => {
|
|
@@ -1547,11 +1565,13 @@ describe("Product Search - Generic", () => {
|
|
|
1547
1565
|
},
|
|
1548
1566
|
limit: 24,
|
|
1549
1567
|
};
|
|
1550
|
-
const response = await
|
|
1551
|
-
|
|
1552
|
-
|
|
1568
|
+
const response = await ctMock.app.inject({
|
|
1569
|
+
method: "POST",
|
|
1570
|
+
url: "/dummy/products/search",
|
|
1571
|
+
payload: body,
|
|
1572
|
+
});
|
|
1553
1573
|
|
|
1554
|
-
const pagedSearchResponse: ProductPagedSearchResponse = response.
|
|
1574
|
+
const pagedSearchResponse: ProductPagedSearchResponse = response.json();
|
|
1555
1575
|
expect(pagedSearchResponse.limit).toBe(24);
|
|
1556
1576
|
expect(pagedSearchResponse.offset).toBe(0);
|
|
1557
1577
|
expect(pagedSearchResponse.total).toBeGreaterThan(0);
|
|
@@ -1582,11 +1602,13 @@ describe("Product Search - Generic", () => {
|
|
|
1582
1602
|
offset: 88,
|
|
1583
1603
|
};
|
|
1584
1604
|
|
|
1585
|
-
const response = await
|
|
1586
|
-
|
|
1587
|
-
|
|
1605
|
+
const response = await ctMock.app.inject({
|
|
1606
|
+
method: "POST",
|
|
1607
|
+
url: "/dummy/products/search",
|
|
1608
|
+
payload: body,
|
|
1609
|
+
});
|
|
1588
1610
|
|
|
1589
|
-
const pagedSearchResponse: ProductPagedSearchResponse = response.
|
|
1611
|
+
const pagedSearchResponse: ProductPagedSearchResponse = response.json();
|
|
1590
1612
|
expect(pagedSearchResponse.limit).toBe(88);
|
|
1591
1613
|
expect(pagedSearchResponse.offset).toBe(88);
|
|
1592
1614
|
expect(pagedSearchResponse.total).toBeGreaterThan(0);
|
|
@@ -1605,11 +1627,15 @@ describe("Product Search - Generic", () => {
|
|
|
1605
1627
|
});
|
|
1606
1628
|
|
|
1607
1629
|
test("Filter on inventory", async () => {
|
|
1630
|
+
const channel = await channelDraftFactory(ctMock).create({
|
|
1631
|
+
roles: ["InventorySupply"],
|
|
1632
|
+
});
|
|
1633
|
+
|
|
1608
1634
|
const body: ProductSearchRequest = {
|
|
1609
1635
|
query: {
|
|
1610
1636
|
exact: {
|
|
1611
1637
|
field: "variants.availability.isOnStockForChannel",
|
|
1612
|
-
value:
|
|
1638
|
+
value: channel.id,
|
|
1613
1639
|
},
|
|
1614
1640
|
},
|
|
1615
1641
|
productProjectionParameters: {
|
|
@@ -1621,24 +1647,33 @@ describe("Product Search - Generic", () => {
|
|
|
1621
1647
|
limit: 1,
|
|
1622
1648
|
};
|
|
1623
1649
|
|
|
1624
|
-
const response1 = await
|
|
1625
|
-
|
|
1626
|
-
|
|
1650
|
+
const response1 = await ctMock.app.inject({
|
|
1651
|
+
method: "POST",
|
|
1652
|
+
url: "/dummy/products/search",
|
|
1653
|
+
payload: body,
|
|
1654
|
+
});
|
|
1627
1655
|
|
|
1628
|
-
const pagedSearchResponse1: ProductPagedSearchResponse = response1.
|
|
1656
|
+
const pagedSearchResponse1: ProductPagedSearchResponse = response1.json();
|
|
1629
1657
|
|
|
1630
1658
|
expect(pagedSearchResponse1.results.length).toBe(0);
|
|
1631
1659
|
|
|
1632
|
-
await
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1660
|
+
await inventoryFactory.create({
|
|
1661
|
+
key: "1338_stock",
|
|
1662
|
+
sku: "1338",
|
|
1663
|
+
quantityOnStock: 10,
|
|
1664
|
+
supplyChannel: {
|
|
1665
|
+
typeId: "channel",
|
|
1666
|
+
id: channel.id,
|
|
1667
|
+
},
|
|
1668
|
+
});
|
|
1636
1669
|
|
|
1637
|
-
const response2 = await
|
|
1638
|
-
|
|
1639
|
-
|
|
1670
|
+
const response2 = await ctMock.app.inject({
|
|
1671
|
+
method: "POST",
|
|
1672
|
+
url: "/dummy/products/search",
|
|
1673
|
+
payload: body,
|
|
1674
|
+
});
|
|
1640
1675
|
|
|
1641
|
-
const pagedSearchResponse2: ProductPagedSearchResponse = response2.
|
|
1676
|
+
const pagedSearchResponse2: ProductPagedSearchResponse = response2.json();
|
|
1642
1677
|
|
|
1643
1678
|
const productFound = pagedSearchResponse2.results.find(
|
|
1644
1679
|
(result) => result?.productProjection?.masterVariant?.sku === "1337",
|