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