@labdigital/commercetools-mock 2.33.1 → 2.34.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.cjs +19515 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19539 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
- package/src/ctMock.ts +19 -23
- package/src/index.test.ts +14 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.34.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Michael van Tellingen",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"body-parser": "^1.20.2",
|
|
24
24
|
"deep-equal": "^2.2.3",
|
|
25
25
|
"express": "^4.19.2",
|
|
26
|
-
"light-my-request": "^5.11.1",
|
|
27
26
|
"lodash.isequal": "^4.5.0",
|
|
28
27
|
"morgan": "^1.10.0",
|
|
29
28
|
"msw": "^2.2.1",
|
package/src/ctMock.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import express, { NextFunction, Request, Response } from "express";
|
|
2
|
-
import inject from "light-my-request";
|
|
3
2
|
import morgan from "morgan";
|
|
4
3
|
import { http, HttpResponse } from "msw";
|
|
5
4
|
import { setupServer, SetupServer, SetupServerApi } from "msw/node";
|
|
5
|
+
import supertest from "supertest";
|
|
6
6
|
import { DEFAULT_API_HOSTNAME, DEFAULT_AUTH_HOSTNAME } from "./constants";
|
|
7
7
|
import { CommercetoolsError } from "./exceptions";
|
|
8
8
|
import { copyHeaders } from "./lib/proxy";
|
|
@@ -193,12 +193,12 @@ export class CommercetoolsMock {
|
|
|
193
193
|
const url = new URL(request.url);
|
|
194
194
|
const headers = copyHeaders(request.headers);
|
|
195
195
|
|
|
196
|
-
const res = await
|
|
196
|
+
const res = await supertest(app)
|
|
197
197
|
.post(url.pathname + "?" + url.searchParams.toString())
|
|
198
|
-
.
|
|
199
|
-
.
|
|
200
|
-
|
|
201
|
-
return new HttpResponse(res.body, {
|
|
198
|
+
.send(body)
|
|
199
|
+
.set(headers);
|
|
200
|
+
|
|
201
|
+
return new HttpResponse(JSON.stringify(res.body), {
|
|
202
202
|
status: res.statusCode,
|
|
203
203
|
headers: mapHeaderType(res.headers),
|
|
204
204
|
});
|
|
@@ -208,11 +208,10 @@ export class CommercetoolsMock {
|
|
|
208
208
|
const url = new URL(request.url);
|
|
209
209
|
const headers = copyHeaders(request.headers);
|
|
210
210
|
|
|
211
|
-
const res = await
|
|
211
|
+
const res = await supertest(app)
|
|
212
212
|
.get(url.pathname + "?" + url.searchParams.toString())
|
|
213
|
-
.
|
|
214
|
-
.
|
|
215
|
-
.end();
|
|
213
|
+
.send(body)
|
|
214
|
+
.set(headers);
|
|
216
215
|
|
|
217
216
|
if (res.statusCode === 200) {
|
|
218
217
|
const parsedBody = JSON.parse(res.body);
|
|
@@ -239,12 +238,11 @@ export class CommercetoolsMock {
|
|
|
239
238
|
const url = new URL(request.url);
|
|
240
239
|
const headers = copyHeaders(request.headers);
|
|
241
240
|
|
|
242
|
-
const res = await
|
|
241
|
+
const res = await supertest(app)
|
|
243
242
|
.get(url.pathname + "?" + url.searchParams.toString())
|
|
244
|
-
.
|
|
245
|
-
.
|
|
246
|
-
|
|
247
|
-
return new HttpResponse(res.body, {
|
|
243
|
+
.send(body)
|
|
244
|
+
.set(headers);
|
|
245
|
+
return new HttpResponse(JSON.stringify(res.body), {
|
|
248
246
|
status: res.statusCode,
|
|
249
247
|
headers: mapHeaderType(res.headers),
|
|
250
248
|
});
|
|
@@ -254,11 +252,10 @@ export class CommercetoolsMock {
|
|
|
254
252
|
const url = new URL(request.url);
|
|
255
253
|
const headers = copyHeaders(request.headers);
|
|
256
254
|
|
|
257
|
-
const res = await
|
|
255
|
+
const res = await supertest(app)
|
|
258
256
|
.post(url.pathname + "?" + url.searchParams.toString())
|
|
259
|
-
.
|
|
260
|
-
.
|
|
261
|
-
.end();
|
|
257
|
+
.send(body)
|
|
258
|
+
.set(headers);
|
|
262
259
|
return new HttpResponse(res.body, {
|
|
263
260
|
status: res.statusCode,
|
|
264
261
|
headers: mapHeaderType(res.headers),
|
|
@@ -269,11 +266,10 @@ export class CommercetoolsMock {
|
|
|
269
266
|
const url = new URL(request.url);
|
|
270
267
|
const headers = copyHeaders(request.headers);
|
|
271
268
|
|
|
272
|
-
const res = await
|
|
269
|
+
const res = await supertest(app)
|
|
273
270
|
.delete(url.pathname + "?" + url.searchParams.toString())
|
|
274
|
-
.
|
|
275
|
-
.
|
|
276
|
-
.end();
|
|
271
|
+
.send(body)
|
|
272
|
+
.set(headers);
|
|
277
273
|
return new HttpResponse(res.body, {
|
|
278
274
|
status: res.statusCode,
|
|
279
275
|
headers: mapHeaderType(res.headers),
|
package/src/index.test.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { type InvalidTokenError } from "@commercetools/platform-sdk";
|
|
2
2
|
import got from "got";
|
|
3
|
-
import { expect, test } from "vitest";
|
|
3
|
+
import { afterEach, expect, test } from "vitest";
|
|
4
4
|
import { CommercetoolsMock } from "./index";
|
|
5
5
|
|
|
6
|
+
let ctMock: CommercetoolsMock;
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
ctMock.stop();
|
|
10
|
+
});
|
|
11
|
+
|
|
6
12
|
test("node:fetch client", async () => {
|
|
7
|
-
|
|
13
|
+
ctMock = new CommercetoolsMock({
|
|
8
14
|
enableAuthentication: true,
|
|
9
15
|
validateCredentials: true,
|
|
10
16
|
apiHost: "https://localhost",
|
|
@@ -44,11 +50,10 @@ test("node:fetch client", async () => {
|
|
|
44
50
|
limit: 20,
|
|
45
51
|
results: [],
|
|
46
52
|
});
|
|
47
|
-
ctMock.stop();
|
|
48
53
|
});
|
|
49
54
|
|
|
50
55
|
test("got client", async () => {
|
|
51
|
-
|
|
56
|
+
ctMock = new CommercetoolsMock({
|
|
52
57
|
enableAuthentication: true,
|
|
53
58
|
validateCredentials: true,
|
|
54
59
|
apiHost: "https://localhost",
|
|
@@ -86,11 +91,10 @@ test("got client", async () => {
|
|
|
86
91
|
limit: 20,
|
|
87
92
|
results: [],
|
|
88
93
|
});
|
|
89
|
-
ctMock.stop();
|
|
90
94
|
});
|
|
91
95
|
|
|
92
96
|
test("Options.validateCredentials: true (error)", async () => {
|
|
93
|
-
|
|
97
|
+
ctMock = new CommercetoolsMock({
|
|
94
98
|
enableAuthentication: true,
|
|
95
99
|
validateCredentials: true,
|
|
96
100
|
});
|
|
@@ -108,11 +112,10 @@ test("Options.validateCredentials: true (error)", async () => {
|
|
|
108
112
|
);
|
|
109
113
|
expect(response.statusCode).toBe(401);
|
|
110
114
|
expect(response.body.message).toBe("invalid_token");
|
|
111
|
-
ctMock.stop();
|
|
112
115
|
});
|
|
113
116
|
|
|
114
117
|
test("Options.validateCredentials: false", async () => {
|
|
115
|
-
|
|
118
|
+
ctMock = new CommercetoolsMock({
|
|
116
119
|
enableAuthentication: true,
|
|
117
120
|
validateCredentials: false,
|
|
118
121
|
});
|
|
@@ -135,7 +138,6 @@ test("Options.validateCredentials: false", async () => {
|
|
|
135
138
|
limit: 20,
|
|
136
139
|
results: [],
|
|
137
140
|
});
|
|
138
|
-
ctMock.stop();
|
|
139
141
|
});
|
|
140
142
|
|
|
141
143
|
test("Options.enableAuthentication: false", async () => {
|
|
@@ -159,11 +161,10 @@ test("Options.enableAuthentication: false", async () => {
|
|
|
159
161
|
limit: 20,
|
|
160
162
|
results: [],
|
|
161
163
|
});
|
|
162
|
-
ctMock.stop();
|
|
163
164
|
});
|
|
164
165
|
|
|
165
166
|
test("Options.apiHost: is overridden is set", async () => {
|
|
166
|
-
|
|
167
|
+
ctMock = new CommercetoolsMock({
|
|
167
168
|
enableAuthentication: false,
|
|
168
169
|
validateCredentials: false,
|
|
169
170
|
apiHost: "http://api.localhost",
|
|
@@ -181,11 +182,10 @@ test("Options.apiHost: is overridden is set", async () => {
|
|
|
181
182
|
limit: 20,
|
|
182
183
|
results: [],
|
|
183
184
|
});
|
|
184
|
-
ctMock.stop();
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
test("Options.authHost: is set", async () => {
|
|
188
|
-
|
|
188
|
+
ctMock = new CommercetoolsMock({
|
|
189
189
|
enableAuthentication: true,
|
|
190
190
|
validateCredentials: true,
|
|
191
191
|
authHost: "http://auth.localhost",
|
|
@@ -211,7 +211,7 @@ test("Options.authHost: is set", async () => {
|
|
|
211
211
|
});
|
|
212
212
|
|
|
213
213
|
test("apiHost mock proxy: querystring", async () => {
|
|
214
|
-
|
|
214
|
+
ctMock = new CommercetoolsMock({
|
|
215
215
|
enableAuthentication: false,
|
|
216
216
|
validateCredentials: false,
|
|
217
217
|
apiHost: "http://api.localhost",
|
|
@@ -234,5 +234,4 @@ test("apiHost mock proxy: querystring", async () => {
|
|
|
234
234
|
limit: 20,
|
|
235
235
|
results: [],
|
|
236
236
|
});
|
|
237
|
-
ctMock.stop();
|
|
238
237
|
});
|