@labdigital/commercetools-mock 2.49.1 → 2.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1257 -1107
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7403 -9717
- package/dist/index.js.map +1 -1
- package/package.json +9 -20
- package/src/index.test.ts +66 -61
- package/src/repositories/abstract.ts +2 -2
- package/src/repositories/product/helpers.ts +4 -2
- package/src/repositories/shipping-method/actions.ts +2 -2
- package/src/repositories/type/actions.ts +2 -2
- package/dist/index.cjs +0 -9940
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1367
package/package.json
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.50.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Michael van Tellingen",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"import": "./dist/index.js",
|
|
11
|
-
"require": "./dist/index.cjs"
|
|
12
|
-
}
|
|
8
|
+
".": "./dist/index.js"
|
|
13
9
|
},
|
|
14
|
-
"main": "dist/index.
|
|
10
|
+
"main": "dist/index.js",
|
|
15
11
|
"module": "dist/index.js",
|
|
16
12
|
"typings": "dist/index.d.ts",
|
|
17
13
|
"files": [
|
|
@@ -19,16 +15,11 @@
|
|
|
19
15
|
"src"
|
|
20
16
|
],
|
|
21
17
|
"dependencies": {
|
|
22
|
-
"@biomejs/biome": "1.9.4",
|
|
23
|
-
"@types/express": "^5.0.1",
|
|
24
|
-
"@types/express-serve-static-core": "^5.0.6",
|
|
25
18
|
"basic-auth": "2.0.1",
|
|
26
19
|
"body-parser": "2.2.0",
|
|
27
20
|
"decimal.js": "10.5.0",
|
|
28
|
-
"deep-equal": "2.2.3",
|
|
29
21
|
"express": "5.1.0",
|
|
30
22
|
"light-my-request": "6.6.0",
|
|
31
|
-
"lodash.isequal": "4.5.0",
|
|
32
23
|
"morgan": "1.10.0",
|
|
33
24
|
"msw": "2.7.3",
|
|
34
25
|
"uuid": "11.1.0",
|
|
@@ -36,13 +27,14 @@
|
|
|
36
27
|
"zod-validation-error": "3.4.0"
|
|
37
28
|
},
|
|
38
29
|
"devDependencies": {
|
|
30
|
+
"@biomejs/biome": "1.9.4",
|
|
31
|
+
"@types/express": "^5.0.1",
|
|
39
32
|
"@changesets/changelog-github": "0.5.1",
|
|
40
33
|
"@changesets/cli": "2.28.1",
|
|
41
34
|
"@commercetools/platform-sdk": "8.8.0",
|
|
42
35
|
"@types/basic-auth": "1.1.8",
|
|
43
36
|
"@types/body-parser": "1.19.5",
|
|
44
|
-
"@types/
|
|
45
|
-
"@types/lodash.isequal": "4.5.8",
|
|
37
|
+
"@types/express-serve-static-core": "^5.0.6",
|
|
46
38
|
"@types/morgan": "1.9.9",
|
|
47
39
|
"@types/node": "20.16.14",
|
|
48
40
|
"@types/qs": "6.9.11",
|
|
@@ -51,12 +43,9 @@
|
|
|
51
43
|
"@vitest/coverage-v8": "3.1.1",
|
|
52
44
|
"esbuild": "0.25.2",
|
|
53
45
|
"fishery": "2.2.3",
|
|
54
|
-
"got": "14.2.0",
|
|
55
|
-
"husky": "9.1.7",
|
|
56
46
|
"supertest": "7.1.0",
|
|
57
47
|
"timekeeper": "2.3.1",
|
|
58
|
-
"
|
|
59
|
-
"tsup": "8.4.0",
|
|
48
|
+
"tsdown": "^0.9.9",
|
|
60
49
|
"typescript": "5.8.3",
|
|
61
50
|
"vitest": "3.1.1"
|
|
62
51
|
},
|
|
@@ -68,14 +57,14 @@
|
|
|
68
57
|
"access": "public"
|
|
69
58
|
},
|
|
70
59
|
"scripts": {
|
|
71
|
-
"build": "
|
|
60
|
+
"build": "tsdown",
|
|
72
61
|
"build:server": "esbuild src/server.ts --bundle --outfile=dist/server.js --platform=node",
|
|
73
62
|
"check": "biome check && tsc",
|
|
74
63
|
"format": "biome format --fix",
|
|
75
64
|
"lint": "biome check",
|
|
76
65
|
"publish:ci": "pnpm build && pnpm changeset publish",
|
|
77
66
|
"publish:version": "pnpm changeset version && pnpm format",
|
|
78
|
-
"start": "
|
|
67
|
+
"start": "tsdown src/server.ts --watch --onSuccess 'node dist/server'",
|
|
79
68
|
"test": "vitest run",
|
|
80
69
|
"test:ci": "vitest run --coverage"
|
|
81
70
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { InvalidTokenError } from "@commercetools/platform-sdk";
|
|
2
|
-
import got from "got";
|
|
3
2
|
import { setupServer } from "msw/node";
|
|
4
3
|
import { afterEach, beforeAll, expect, test } from "vitest";
|
|
5
4
|
import { CommercetoolsMock } from "./index";
|
|
@@ -57,7 +56,7 @@ test("node:fetch client", async () => {
|
|
|
57
56
|
});
|
|
58
57
|
});
|
|
59
58
|
|
|
60
|
-
test("
|
|
59
|
+
test("fetch client", async () => {
|
|
61
60
|
const ctMock = new CommercetoolsMock({
|
|
62
61
|
enableAuthentication: true,
|
|
63
62
|
validateCredentials: true,
|
|
@@ -65,31 +64,34 @@ test("got client", async () => {
|
|
|
65
64
|
authHost: "https://localhost:8080",
|
|
66
65
|
});
|
|
67
66
|
ctMock.registerHandlers(mswServer);
|
|
67
|
+
const params = new URLSearchParams({
|
|
68
|
+
grant_type: "client_credentials",
|
|
69
|
+
scope: "manage_project:commercetools-node-mock",
|
|
70
|
+
});
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
scope: "manage_project:commercetools-node-mock",
|
|
75
|
-
},
|
|
76
|
-
username: "foo",
|
|
77
|
-
password: "bar",
|
|
78
|
-
responseType: "json",
|
|
72
|
+
const authHeader = `Basic ${Buffer.from("foo:bar").toString("base64")}`;
|
|
73
|
+
let response = await fetch(`https://localhost:8080/oauth/token?${params}`, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: {
|
|
76
|
+
Authorization: authHeader,
|
|
79
77
|
},
|
|
80
|
-
);
|
|
81
|
-
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const authBody = await response.json();
|
|
81
|
+
expect(response.status).toBe(200);
|
|
82
|
+
|
|
83
|
+
const token = authBody.access_token;
|
|
84
|
+
expect(authBody.access_token).toBeDefined();
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
expect(response.body.access_token).toBeDefined();
|
|
85
|
-
response = await got.get("https://localhost/my-project/orders", {
|
|
86
|
+
response = await fetch("https://localhost/my-project/orders", {
|
|
86
87
|
headers: {
|
|
87
88
|
Authorization: `Bearer ${token}`,
|
|
88
89
|
},
|
|
89
|
-
responseType: "json",
|
|
90
90
|
});
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
|
|
92
|
+
const body = await response.json();
|
|
93
|
+
expect(response.status).toBe(200);
|
|
94
|
+
expect(body).toStrictEqual({
|
|
93
95
|
count: 0,
|
|
94
96
|
total: 0,
|
|
95
97
|
offset: 0,
|
|
@@ -105,18 +107,18 @@ test("Options.validateCredentials: true (error)", async () => {
|
|
|
105
107
|
});
|
|
106
108
|
ctMock.registerHandlers(mswServer);
|
|
107
109
|
|
|
108
|
-
const response = await
|
|
110
|
+
const response = await fetch(
|
|
109
111
|
"https://api.europe-west1.gcp.commercetools.com/my-project/orders",
|
|
110
112
|
{
|
|
111
113
|
headers: {
|
|
112
114
|
Authorization: "Bearer foobar",
|
|
113
115
|
},
|
|
114
|
-
responseType: "json",
|
|
115
|
-
throwHttpErrors: false,
|
|
116
116
|
},
|
|
117
117
|
);
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
|
|
119
|
+
const body = (await response.json()) as InvalidTokenError;
|
|
120
|
+
expect(response.status).toBe(401);
|
|
121
|
+
expect(body.message).toBe("invalid_token");
|
|
120
122
|
});
|
|
121
123
|
|
|
122
124
|
test("Options.validateCredentials: false", async () => {
|
|
@@ -126,17 +128,18 @@ test("Options.validateCredentials: false", async () => {
|
|
|
126
128
|
});
|
|
127
129
|
ctMock.registerHandlers(mswServer);
|
|
128
130
|
|
|
129
|
-
const response = await
|
|
131
|
+
const response = await fetch(
|
|
130
132
|
"https://api.europe-west1.gcp.commercetools.com/my-project/orders",
|
|
131
133
|
{
|
|
132
134
|
headers: {
|
|
133
135
|
Authorization: "Bearer foobar",
|
|
134
136
|
},
|
|
135
|
-
responseType: "json",
|
|
136
137
|
},
|
|
137
138
|
);
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
|
|
140
|
+
const body = await response.json();
|
|
141
|
+
expect(response.status).toBe(200);
|
|
142
|
+
expect(body).toStrictEqual({
|
|
140
143
|
count: 0,
|
|
141
144
|
total: 0,
|
|
142
145
|
offset: 0,
|
|
@@ -152,14 +155,13 @@ test("Options.enableAuthentication: false", async () => {
|
|
|
152
155
|
});
|
|
153
156
|
ctMock.registerHandlers(mswServer);
|
|
154
157
|
|
|
155
|
-
const response = await
|
|
158
|
+
const response = await fetch(
|
|
156
159
|
"https://api.europe-west1.gcp.commercetools.com/my-project/orders",
|
|
157
|
-
{
|
|
158
|
-
responseType: "json",
|
|
159
|
-
},
|
|
160
160
|
);
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
|
|
162
|
+
const body = await response.json();
|
|
163
|
+
expect(response.status).toBe(200);
|
|
164
|
+
expect(body).toStrictEqual({
|
|
163
165
|
count: 0,
|
|
164
166
|
total: 0,
|
|
165
167
|
offset: 0,
|
|
@@ -176,11 +178,11 @@ test("Options.apiHost: is overridden is set", async () => {
|
|
|
176
178
|
});
|
|
177
179
|
ctMock.registerHandlers(mswServer);
|
|
178
180
|
|
|
179
|
-
const response = await
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
expect(response.
|
|
183
|
-
expect(
|
|
181
|
+
const response = await fetch("http://api.localhost/my-project/orders");
|
|
182
|
+
|
|
183
|
+
const body = await response.json();
|
|
184
|
+
expect(response.status).toBe(200);
|
|
185
|
+
expect(body).toStrictEqual({
|
|
184
186
|
count: 0,
|
|
185
187
|
total: 0,
|
|
186
188
|
offset: 0,
|
|
@@ -196,22 +198,23 @@ test("Options.authHost: is set", async () => {
|
|
|
196
198
|
authHost: "http://auth.localhost",
|
|
197
199
|
});
|
|
198
200
|
ctMock.registerHandlers(mswServer);
|
|
201
|
+
const params = new URLSearchParams({
|
|
202
|
+
grant_type: "client_credentials",
|
|
203
|
+
scope: "manage_project:commercetools-node-mock",
|
|
204
|
+
});
|
|
199
205
|
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
scope: "manage_project:commercetools-node-mock",
|
|
206
|
-
},
|
|
207
|
-
username: "foo",
|
|
208
|
-
password: "bar",
|
|
209
|
-
responseType: "json",
|
|
206
|
+
const authHeader = `Basic ${Buffer.from("foo:bar").toString("base64")}`;
|
|
207
|
+
const response = await fetch(`http://auth.localhost/oauth/token?${params}`, {
|
|
208
|
+
method: "POST",
|
|
209
|
+
headers: {
|
|
210
|
+
Authorization: authHeader,
|
|
210
211
|
},
|
|
211
|
-
);
|
|
212
|
-
expect(response.statusCode).toBe(200);
|
|
212
|
+
});
|
|
213
213
|
|
|
214
|
-
const
|
|
214
|
+
const authBody = await response.json();
|
|
215
|
+
expect(response.status).toBe(200);
|
|
216
|
+
|
|
217
|
+
const token = authBody.access_token;
|
|
215
218
|
expect(token).toBeDefined();
|
|
216
219
|
});
|
|
217
220
|
|
|
@@ -223,16 +226,18 @@ test("apiHost mock proxy: querystring", async () => {
|
|
|
223
226
|
});
|
|
224
227
|
ctMock.registerHandlers(mswServer);
|
|
225
228
|
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
where: 'orderNumber="foobar"',
|
|
230
|
-
expand: "custom.type",
|
|
231
|
-
},
|
|
229
|
+
const queryParams = new URLSearchParams({
|
|
230
|
+
where: 'orderNumber="foobar"',
|
|
231
|
+
expand: "custom.type",
|
|
232
232
|
});
|
|
233
233
|
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
const response = await fetch(
|
|
235
|
+
`http://api.localhost/my-project/orders?${queryParams}`,
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
const body = await response.json();
|
|
239
|
+
expect(response.status).toBe(200);
|
|
240
|
+
expect(body).toStrictEqual({
|
|
236
241
|
count: 0,
|
|
237
242
|
total: 0,
|
|
238
243
|
offset: 0,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1
2
|
import type {
|
|
2
3
|
BaseResource,
|
|
3
4
|
InvalidInputError,
|
|
@@ -6,7 +7,6 @@ import type {
|
|
|
6
7
|
ResourceNotFoundError,
|
|
7
8
|
UpdateAction,
|
|
8
9
|
} from "@commercetools/platform-sdk";
|
|
9
|
-
import deepEqual from "deep-equal";
|
|
10
10
|
import type { Config } from "~src/config";
|
|
11
11
|
import { CommercetoolsError } from "~src/exceptions";
|
|
12
12
|
import { cloneObject } from "../helpers";
|
|
@@ -291,7 +291,7 @@ export class AbstractUpdateHandler {
|
|
|
291
291
|
// an object per action which does an actual modification.
|
|
292
292
|
// This isn't the most performant method to do this (the update action
|
|
293
293
|
// should return a flag) but for now the easiest.
|
|
294
|
-
if (!
|
|
294
|
+
if (!isDeepStrictEqual(beforeUpdate, updatedResource)) {
|
|
295
295
|
// We only check the version when there is an actual modification to
|
|
296
296
|
// be stored.
|
|
297
297
|
checkConcurrentModification(resource.version, version, identifier);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1
2
|
import type {
|
|
2
3
|
Asset,
|
|
3
4
|
AssetDraft,
|
|
@@ -9,7 +10,6 @@ import type {
|
|
|
9
10
|
ProductVariant,
|
|
10
11
|
ProductVariantDraft,
|
|
11
12
|
} from "@commercetools/platform-sdk";
|
|
12
|
-
import deepEqual from "deep-equal";
|
|
13
13
|
import { v4 as uuidv4 } from "uuid";
|
|
14
14
|
import type { AbstractStorage } from "~src/storage";
|
|
15
15
|
import type { Writable } from "~src/types";
|
|
@@ -60,7 +60,9 @@ export const checkForStagedChanges = (product: Writable<Product>) => {
|
|
|
60
60
|
product.masterData.staged = product.masterData.current;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
if (
|
|
63
|
+
if (
|
|
64
|
+
isDeepStrictEqual(product.masterData.current, product.masterData.staged)
|
|
65
|
+
) {
|
|
64
66
|
product.masterData.hasStagedChanges = false;
|
|
65
67
|
} else {
|
|
66
68
|
product.masterData.hasStagedChanges = true;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1
2
|
import type {
|
|
2
3
|
ShippingMethodChangeTaxCategoryAction,
|
|
3
4
|
ShippingMethodRemoveShippingRateAction,
|
|
@@ -20,7 +21,6 @@ import type {
|
|
|
20
21
|
ShippingMethodUpdateAction,
|
|
21
22
|
ZoneReference,
|
|
22
23
|
} from "@commercetools/platform-sdk";
|
|
23
|
-
import deepEqual from "deep-equal";
|
|
24
24
|
import type { Writable } from "~src/types";
|
|
25
25
|
import type { RepositoryContext, UpdateHandlerInterface } from "../abstract";
|
|
26
26
|
import { AbstractUpdateHandler } from "../abstract";
|
|
@@ -117,7 +117,7 @@ export class ShippingMethodUpdateHandler
|
|
|
117
117
|
resource.zoneRates.forEach((zoneRate) => {
|
|
118
118
|
if (zoneRate.zone.id === zone.id) {
|
|
119
119
|
zoneRate.shippingRates = zoneRate.shippingRates.filter(
|
|
120
|
-
(otherRate) => !
|
|
120
|
+
(otherRate) => !isDeepStrictEqual(rate, otherRate),
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1
2
|
import type {
|
|
2
3
|
FieldDefinition,
|
|
3
4
|
InvalidOperationError,
|
|
@@ -11,7 +12,6 @@ import type {
|
|
|
11
12
|
TypeSetDescriptionAction,
|
|
12
13
|
TypeUpdateAction,
|
|
13
14
|
} from "@commercetools/platform-sdk";
|
|
14
|
-
import isEqual from "lodash.isequal";
|
|
15
15
|
import { CommercetoolsError } from "~src/exceptions";
|
|
16
16
|
import type { Writable } from "~src/types";
|
|
17
17
|
import type { RepositoryContext } from "../abstract";
|
|
@@ -114,7 +114,7 @@ export class TypeUpdateHandler
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
if (
|
|
117
|
-
|
|
117
|
+
isDeepStrictEqual(
|
|
118
118
|
fieldNames,
|
|
119
119
|
resource.fieldDefinitions.map((item) => item.name),
|
|
120
120
|
)
|