@labdigital/commercetools-mock 2.42.1 → 2.43.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 +2514 -2501
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +179 -170
- package/dist/index.d.ts +179 -170
- package/dist/index.js +2523 -2510
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/config.ts +6 -0
- package/src/ctMock.ts +25 -14
- package/src/index.test.ts +20 -16
- package/src/oauth/server.test.ts +3 -1
- package/src/product-projection-search.ts +3 -2
- package/src/product-search.ts +3 -2
- package/src/projectAPI.ts +18 -6
- package/src/repositories/abstract.ts +8 -4
- package/src/repositories/associate-role.ts +3 -3
- package/src/repositories/attribute-group.ts +3 -3
- package/src/repositories/business-unit.ts +3 -3
- package/src/repositories/cart/index.test.ts +3 -1
- package/src/repositories/cart/index.ts +3 -3
- package/src/repositories/cart-discount/index.ts +4 -6
- package/src/repositories/category/index.test.ts +3 -1
- package/src/repositories/category/index.ts +3 -3
- package/src/repositories/channel.ts +3 -3
- package/src/repositories/custom-object.ts +3 -3
- package/src/repositories/customer/index.test.ts +3 -1
- package/src/repositories/customer/index.ts +4 -4
- package/src/repositories/customer-group.ts +4 -4
- package/src/repositories/discount-code/index.ts +4 -4
- package/src/repositories/extension.ts +4 -4
- package/src/repositories/index.ts +45 -45
- package/src/repositories/inventory-entry/index.ts +4 -4
- package/src/repositories/order/index.test.ts +6 -1
- package/src/repositories/order/index.ts +4 -4
- package/src/repositories/order-edit.ts +3 -3
- package/src/repositories/payment/index.ts +3 -3
- package/src/repositories/product/index.ts +10 -6
- package/src/repositories/product-discount.ts +3 -3
- package/src/repositories/product-projection.ts +4 -4
- package/src/repositories/product-selection.ts +3 -3
- package/src/repositories/product-tailoring.ts +3 -3
- package/src/repositories/product-type.ts +4 -4
- package/src/repositories/project.ts +4 -4
- package/src/repositories/quote-request.ts +3 -3
- package/src/repositories/quote.ts +3 -3
- package/src/repositories/review.ts +3 -3
- package/src/repositories/shipping-method/index.ts +4 -4
- package/src/repositories/shopping-list/index.ts +4 -4
- package/src/repositories/staged-quote.ts +3 -3
- package/src/repositories/standalone-price.ts +3 -3
- package/src/repositories/state.ts +4 -4
- package/src/repositories/store.ts +3 -2
- package/src/repositories/subscription.ts +4 -4
- package/src/repositories/tax-category/index.ts +3 -3
- package/src/repositories/type/index.ts +4 -4
- package/src/repositories/zone.ts +4 -4
- package/src/services/project.test.ts +1 -13
- package/src/services/store.test.ts +1 -13
- package/src/deprecation.ts +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.43.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Michael van Tellingen",
|
|
6
6
|
"type": "module",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/uuid": "^9.0.8",
|
|
51
51
|
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
|
52
52
|
"@typescript-eslint/parser": "^7.0.2",
|
|
53
|
-
"@vitest/coverage-v8": "
|
|
53
|
+
"@vitest/coverage-v8": "3.0.2",
|
|
54
54
|
"esbuild": "^0.20.1",
|
|
55
55
|
"eslint": "^8.57.1",
|
|
56
56
|
"eslint-plugin-sort-class-members": "^1.21.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"tslib": "^2.8.0",
|
|
68
68
|
"tsup": "^8.0.2",
|
|
69
69
|
"typescript": "^5.6.3",
|
|
70
|
-
"vitest": "
|
|
70
|
+
"vitest": "3.0.2"
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|
|
73
73
|
"node": ">=18",
|
package/src/config.ts
ADDED
package/src/ctMock.ts
CHANGED
|
@@ -5,22 +5,20 @@ import morgan from "morgan";
|
|
|
5
5
|
import { http, HttpResponse } from "msw";
|
|
6
6
|
import type { SetupServer, SetupServerApi } from "msw/node";
|
|
7
7
|
import { setupServer } from "msw/node";
|
|
8
|
+
import type { Config } from "./config";
|
|
8
9
|
import { DEFAULT_API_HOSTNAME, DEFAULT_AUTH_HOSTNAME } from "./constants";
|
|
9
10
|
import { CommercetoolsError } from "./exceptions";
|
|
11
|
+
import { mapHeaderType } from "./helpers";
|
|
10
12
|
import { copyHeaders } from "./lib/proxy";
|
|
11
13
|
import { OAuth2Server } from "./oauth/server";
|
|
12
14
|
import { ProjectAPI } from "./projectAPI";
|
|
13
|
-
import type { AbstractStorage } from "./storage";
|
|
14
|
-
import { InMemoryStorage } from "./storage";
|
|
15
|
-
|
|
16
|
-
// Services
|
|
17
|
-
import { warnDeprecation } from "./deprecation";
|
|
18
|
-
import { mapHeaderType } from "./helpers";
|
|
19
15
|
import type { RepositoryMap } from "./repositories";
|
|
20
16
|
import { createRepositories } from "./repositories";
|
|
21
17
|
import type { ProjectRepository } from "./repositories/project";
|
|
22
18
|
import { createServices } from "./services";
|
|
23
19
|
import { ProjectService } from "./services/project";
|
|
20
|
+
import type { AbstractStorage } from "./storage";
|
|
21
|
+
import { InMemoryStorage } from "./storage";
|
|
24
22
|
|
|
25
23
|
export type CommercetoolsMockOptions = {
|
|
26
24
|
validateCredentials: boolean;
|
|
@@ -29,6 +27,7 @@ export type CommercetoolsMockOptions = {
|
|
|
29
27
|
apiHost: RegExp | string;
|
|
30
28
|
authHost: RegExp | string;
|
|
31
29
|
silent: boolean;
|
|
30
|
+
strict: boolean;
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
type AppOptions = { silent?: boolean };
|
|
@@ -39,7 +38,8 @@ const DEFAULT_OPTIONS: CommercetoolsMockOptions = {
|
|
|
39
38
|
defaultProjectKey: undefined,
|
|
40
39
|
apiHost: DEFAULT_API_HOSTNAME,
|
|
41
40
|
authHost: DEFAULT_AUTH_HOSTNAME,
|
|
42
|
-
silent:
|
|
41
|
+
silent: true,
|
|
42
|
+
strict: false,
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
const _globalListeners: SetupServer[] = [];
|
|
@@ -74,8 +74,9 @@ export class CommercetoolsMock {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
start() {
|
|
77
|
-
|
|
78
|
-
"The start method is deprecated, use .registerHandlers() to bind to an msw server instead",
|
|
77
|
+
process.emitWarning(
|
|
78
|
+
"The start() method is deprecated, use .registerHandlers() to bind to an msw server instead",
|
|
79
|
+
"DeprecationWarning",
|
|
79
80
|
);
|
|
80
81
|
|
|
81
82
|
// Order is important here when the hostnames match
|
|
@@ -84,8 +85,9 @@ export class CommercetoolsMock {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
stop() {
|
|
87
|
-
|
|
88
|
-
"The stop method is deprecated, use .registerHandlers() to bind to an msw server instead",
|
|
88
|
+
process.emitWarning(
|
|
89
|
+
"The stop() method is deprecated, use .registerHandlers() to bind to an msw server instead",
|
|
90
|
+
"DeprecationWarning",
|
|
89
91
|
);
|
|
90
92
|
this._mswServer?.close();
|
|
91
93
|
this._mswServer = undefined;
|
|
@@ -104,10 +106,15 @@ export class CommercetoolsMock {
|
|
|
104
106
|
throw new Error("repositories not initialized yet");
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
const config: Config = {
|
|
110
|
+
strict: this.options.strict,
|
|
111
|
+
storage: this._storage,
|
|
112
|
+
};
|
|
113
|
+
|
|
107
114
|
return new ProjectAPI(
|
|
108
115
|
projectKey || this.options.defaultProjectKey!,
|
|
109
116
|
this._repositories,
|
|
110
|
-
|
|
117
|
+
config,
|
|
111
118
|
);
|
|
112
119
|
}
|
|
113
120
|
|
|
@@ -123,7 +130,11 @@ export class CommercetoolsMock {
|
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
private createApp(options?: AppOptions): express.Express {
|
|
126
|
-
|
|
133
|
+
const config: Config = {
|
|
134
|
+
strict: this.options.strict,
|
|
135
|
+
storage: this._storage,
|
|
136
|
+
};
|
|
137
|
+
this._repositories = createRepositories(config);
|
|
127
138
|
this._oauth2.setCustomerRepository(this._repositories.customer);
|
|
128
139
|
|
|
129
140
|
const app = express();
|
|
@@ -292,7 +303,7 @@ export class CommercetoolsMock {
|
|
|
292
303
|
if (this._mswServer !== undefined) {
|
|
293
304
|
throw new Error("Server already started");
|
|
294
305
|
} else {
|
|
295
|
-
|
|
306
|
+
process.emitWarning("Server wasn't stopped properly, clearing");
|
|
296
307
|
_globalListeners.forEach((listener) => listener.close());
|
|
297
308
|
}
|
|
298
309
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { type InvalidTokenError } from "@commercetools/platform-sdk";
|
|
2
2
|
import got from "got";
|
|
3
|
-
import {
|
|
3
|
+
import { setupServer } from "msw/node";
|
|
4
|
+
import { afterEach, beforeAll, expect, test } from "vitest";
|
|
4
5
|
import { CommercetoolsMock } from "./index";
|
|
5
6
|
|
|
7
|
+
const mswServer = setupServer();
|
|
8
|
+
|
|
9
|
+
beforeAll(() => {
|
|
10
|
+
mswServer.listen({ onUnhandledRequest: "error" });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
mswServer.resetHandlers();
|
|
15
|
+
});
|
|
16
|
+
|
|
6
17
|
test("node:fetch client", async () => {
|
|
7
18
|
const ctMock = new CommercetoolsMock({
|
|
8
19
|
enableAuthentication: true,
|
|
@@ -10,7 +21,7 @@ test("node:fetch client", async () => {
|
|
|
10
21
|
apiHost: "https://localhost",
|
|
11
22
|
authHost: "https://localhost:8080",
|
|
12
23
|
});
|
|
13
|
-
ctMock.
|
|
24
|
+
ctMock.registerHandlers(mswServer);
|
|
14
25
|
|
|
15
26
|
const authHeader = "Basic " + Buffer.from("foo:bar").toString("base64");
|
|
16
27
|
let response = await fetch("https://localhost:8080/oauth/token", {
|
|
@@ -44,7 +55,6 @@ test("node:fetch client", async () => {
|
|
|
44
55
|
limit: 20,
|
|
45
56
|
results: [],
|
|
46
57
|
});
|
|
47
|
-
ctMock.stop();
|
|
48
58
|
});
|
|
49
59
|
|
|
50
60
|
test("got client", async () => {
|
|
@@ -54,7 +64,7 @@ test("got client", async () => {
|
|
|
54
64
|
apiHost: "https://localhost",
|
|
55
65
|
authHost: "https://localhost:8080",
|
|
56
66
|
});
|
|
57
|
-
ctMock.
|
|
67
|
+
ctMock.registerHandlers(mswServer);
|
|
58
68
|
|
|
59
69
|
let response = await got.post<{ access_token: string }>(
|
|
60
70
|
"https://localhost:8080/oauth/token",
|
|
@@ -86,7 +96,6 @@ test("got client", async () => {
|
|
|
86
96
|
limit: 20,
|
|
87
97
|
results: [],
|
|
88
98
|
});
|
|
89
|
-
ctMock.stop();
|
|
90
99
|
});
|
|
91
100
|
|
|
92
101
|
test("Options.validateCredentials: true (error)", async () => {
|
|
@@ -94,7 +103,7 @@ test("Options.validateCredentials: true (error)", async () => {
|
|
|
94
103
|
enableAuthentication: true,
|
|
95
104
|
validateCredentials: true,
|
|
96
105
|
});
|
|
97
|
-
ctMock.
|
|
106
|
+
ctMock.registerHandlers(mswServer);
|
|
98
107
|
|
|
99
108
|
const response = await got.get<InvalidTokenError>(
|
|
100
109
|
"https://api.europe-west1.gcp.commercetools.com/my-project/orders",
|
|
@@ -108,7 +117,6 @@ test("Options.validateCredentials: true (error)", async () => {
|
|
|
108
117
|
);
|
|
109
118
|
expect(response.statusCode).toBe(401);
|
|
110
119
|
expect(response.body.message).toBe("invalid_token");
|
|
111
|
-
ctMock.stop();
|
|
112
120
|
});
|
|
113
121
|
|
|
114
122
|
test("Options.validateCredentials: false", async () => {
|
|
@@ -116,7 +124,7 @@ test("Options.validateCredentials: false", async () => {
|
|
|
116
124
|
enableAuthentication: true,
|
|
117
125
|
validateCredentials: false,
|
|
118
126
|
});
|
|
119
|
-
ctMock.
|
|
127
|
+
ctMock.registerHandlers(mswServer);
|
|
120
128
|
|
|
121
129
|
const response = await got.get(
|
|
122
130
|
"https://api.europe-west1.gcp.commercetools.com/my-project/orders",
|
|
@@ -135,7 +143,6 @@ test("Options.validateCredentials: false", async () => {
|
|
|
135
143
|
limit: 20,
|
|
136
144
|
results: [],
|
|
137
145
|
});
|
|
138
|
-
ctMock.stop();
|
|
139
146
|
});
|
|
140
147
|
|
|
141
148
|
test("Options.enableAuthentication: false", async () => {
|
|
@@ -143,7 +150,7 @@ test("Options.enableAuthentication: false", async () => {
|
|
|
143
150
|
enableAuthentication: false,
|
|
144
151
|
validateCredentials: false,
|
|
145
152
|
});
|
|
146
|
-
ctMock.
|
|
153
|
+
ctMock.registerHandlers(mswServer);
|
|
147
154
|
|
|
148
155
|
const response = await got.get(
|
|
149
156
|
"https://api.europe-west1.gcp.commercetools.com/my-project/orders",
|
|
@@ -159,7 +166,6 @@ test("Options.enableAuthentication: false", async () => {
|
|
|
159
166
|
limit: 20,
|
|
160
167
|
results: [],
|
|
161
168
|
});
|
|
162
|
-
ctMock.stop();
|
|
163
169
|
});
|
|
164
170
|
|
|
165
171
|
test("Options.apiHost: is overridden is set", async () => {
|
|
@@ -168,7 +174,7 @@ test("Options.apiHost: is overridden is set", async () => {
|
|
|
168
174
|
validateCredentials: false,
|
|
169
175
|
apiHost: "http://api.localhost",
|
|
170
176
|
});
|
|
171
|
-
ctMock.
|
|
177
|
+
ctMock.registerHandlers(mswServer);
|
|
172
178
|
|
|
173
179
|
const response = await got.get("http://api.localhost/my-project/orders", {
|
|
174
180
|
responseType: "json",
|
|
@@ -181,7 +187,6 @@ test("Options.apiHost: is overridden is set", async () => {
|
|
|
181
187
|
limit: 20,
|
|
182
188
|
results: [],
|
|
183
189
|
});
|
|
184
|
-
ctMock.stop();
|
|
185
190
|
});
|
|
186
191
|
|
|
187
192
|
test("Options.authHost: is set", async () => {
|
|
@@ -190,7 +195,7 @@ test("Options.authHost: is set", async () => {
|
|
|
190
195
|
validateCredentials: true,
|
|
191
196
|
authHost: "http://auth.localhost",
|
|
192
197
|
});
|
|
193
|
-
ctMock.
|
|
198
|
+
ctMock.registerHandlers(mswServer);
|
|
194
199
|
|
|
195
200
|
const response = await got.post<{ access_token: string }>(
|
|
196
201
|
"http://auth.localhost/oauth/token",
|
|
@@ -216,7 +221,7 @@ test("apiHost mock proxy: querystring", async () => {
|
|
|
216
221
|
validateCredentials: false,
|
|
217
222
|
apiHost: "http://api.localhost",
|
|
218
223
|
});
|
|
219
|
-
ctMock.
|
|
224
|
+
ctMock.registerHandlers(mswServer);
|
|
220
225
|
|
|
221
226
|
const response = await got.get("http://api.localhost/my-project/orders", {
|
|
222
227
|
responseType: "json",
|
|
@@ -234,5 +239,4 @@ test("apiHost mock proxy: querystring", async () => {
|
|
|
234
239
|
limit: 20,
|
|
235
240
|
results: [],
|
|
236
241
|
});
|
|
237
|
-
ctMock.stop();
|
|
238
242
|
});
|
package/src/oauth/server.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import supertest from "supertest";
|
|
3
3
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
4
|
+
import type { Config } from "~src/config";
|
|
4
5
|
import { getBaseResourceProperties } from "../helpers";
|
|
5
6
|
import { hashPassword } from "../lib/password";
|
|
6
7
|
import { CustomerRepository } from "../repositories/customer";
|
|
@@ -21,7 +22,8 @@ describe("OAuth2Server", () => {
|
|
|
21
22
|
app.use(server.createRouter());
|
|
22
23
|
|
|
23
24
|
storage = new InMemoryStorage();
|
|
24
|
-
|
|
25
|
+
const config: Config = { storage, strict: false };
|
|
26
|
+
customerRepository = new CustomerRepository(config);
|
|
25
27
|
server.setCustomerRepository(customerRepository);
|
|
26
28
|
});
|
|
27
29
|
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
RangeFacetResult,
|
|
10
10
|
TermFacetResult,
|
|
11
11
|
} from "@commercetools/platform-sdk";
|
|
12
|
+
import type { Config } from "./config";
|
|
12
13
|
import { CommercetoolsError } from "./exceptions";
|
|
13
14
|
import { nestedLookup } from "./helpers";
|
|
14
15
|
import type {
|
|
@@ -51,8 +52,8 @@ export type ProductProjectionSearchParams = {
|
|
|
51
52
|
export class ProductProjectionSearch {
|
|
52
53
|
protected _storage: AbstractStorage;
|
|
53
54
|
|
|
54
|
-
constructor(
|
|
55
|
-
this._storage = storage;
|
|
55
|
+
constructor(config: Config) {
|
|
56
|
+
this._storage = config.storage;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
search(
|
package/src/product-search.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
ProductSearchRequest,
|
|
7
7
|
ProductSearchResult,
|
|
8
8
|
} from "@commercetools/platform-sdk";
|
|
9
|
+
import type { Config } from "./config";
|
|
9
10
|
import { CommercetoolsError } from "./exceptions";
|
|
10
11
|
import { parseSearchQuery } from "./lib/productSearchFilter";
|
|
11
12
|
import { validateSearchQuery } from "./lib/searchQueryTypeChecker";
|
|
@@ -15,8 +16,8 @@ import type { AbstractStorage } from "./storage";
|
|
|
15
16
|
export class ProductSearch {
|
|
16
17
|
protected _storage: AbstractStorage;
|
|
17
18
|
|
|
18
|
-
constructor(
|
|
19
|
-
this._storage = storage;
|
|
19
|
+
constructor(config: Config) {
|
|
20
|
+
this._storage = config.storage;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
search(
|
package/src/projectAPI.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Config } from "./config";
|
|
1
2
|
import { getBaseResourceProperties } from "./helpers";
|
|
2
3
|
import type { RepositoryMap } from "./repositories";
|
|
3
4
|
import type { GetParams } from "./repositories/abstract";
|
|
@@ -11,19 +12,30 @@ export class ProjectAPI {
|
|
|
11
12
|
|
|
12
13
|
private _repositories: RepositoryMap;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
storage: AbstractStorage,
|
|
18
|
-
) {
|
|
15
|
+
private config: Config;
|
|
16
|
+
|
|
17
|
+
constructor(projectKey: string, repositories: RepositoryMap, config: Config) {
|
|
19
18
|
this.projectKey = projectKey;
|
|
20
|
-
this.
|
|
19
|
+
this.config = config;
|
|
20
|
+
this._storage = config.storage;
|
|
21
21
|
this._repositories = repositories;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
add<T extends keyof RepositoryMap & keyof ResourceMap>(
|
|
25
25
|
typeId: T,
|
|
26
26
|
resource: ResourceMap[T],
|
|
27
|
+
) {
|
|
28
|
+
process.emitWarning(
|
|
29
|
+
"ctMock.add() is deprecated, create resources via regular create endpoints " +
|
|
30
|
+
"or if you are really sure, use unsafeAdd() (but be aware of potential state issues)",
|
|
31
|
+
"DeprecationWarning",
|
|
32
|
+
);
|
|
33
|
+
this.unsafeAdd(typeId, resource);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
unsafeAdd<T extends keyof RepositoryMap & keyof ResourceMap>(
|
|
37
|
+
typeId: T,
|
|
38
|
+
resource: ResourceMap[T],
|
|
27
39
|
) {
|
|
28
40
|
const repository = this._repositories[typeId];
|
|
29
41
|
if (repository) {
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
UpdateAction,
|
|
8
8
|
} from "@commercetools/platform-sdk";
|
|
9
9
|
import deepEqual from "deep-equal";
|
|
10
|
+
import type { Config } from "~src/config";
|
|
10
11
|
import { CommercetoolsError } from "~src/exceptions";
|
|
11
12
|
import { cloneObject } from "../helpers";
|
|
12
13
|
import type { AbstractStorage } from "../storage";
|
|
@@ -40,10 +41,13 @@ export type RepositoryContext = {
|
|
|
40
41
|
export abstract class AbstractRepository<R extends BaseResource | Project> {
|
|
41
42
|
protected _storage: AbstractStorage;
|
|
42
43
|
|
|
44
|
+
protected config: Config;
|
|
45
|
+
|
|
43
46
|
protected actions: AbstractUpdateHandler | undefined;
|
|
44
47
|
|
|
45
|
-
constructor(
|
|
46
|
-
this.
|
|
48
|
+
constructor(config: Config) {
|
|
49
|
+
this.config = config;
|
|
50
|
+
this._storage = config.storage;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
abstract saveNew({ projectKey }: RepositoryContext, resource: R): void;
|
|
@@ -92,8 +96,8 @@ export abstract class AbstractResourceRepository<
|
|
|
92
96
|
> extends AbstractRepository<ResourceMap[T]> {
|
|
93
97
|
protected _typeId: T;
|
|
94
98
|
|
|
95
|
-
constructor(typeId: T,
|
|
96
|
-
super(
|
|
99
|
+
constructor(typeId: T, config: Config) {
|
|
100
|
+
super(config);
|
|
97
101
|
this._typeId = typeId;
|
|
98
102
|
}
|
|
99
103
|
|
|
@@ -10,8 +10,8 @@ import type {
|
|
|
10
10
|
AssociateRoleSetPermissionsAction,
|
|
11
11
|
AssociateRoleUpdateAction,
|
|
12
12
|
} from "@commercetools/platform-sdk";
|
|
13
|
+
import type { Config } from "~src/config";
|
|
13
14
|
import { getBaseResourceProperties } from "../helpers";
|
|
14
|
-
import type { AbstractStorage } from "../storage/abstract";
|
|
15
15
|
import type { Writable } from "../types";
|
|
16
16
|
import type { UpdateHandlerInterface } from "./abstract";
|
|
17
17
|
import {
|
|
@@ -22,8 +22,8 @@ import {
|
|
|
22
22
|
import { createCustomFields } from "./helpers";
|
|
23
23
|
|
|
24
24
|
export class AssociateRoleRepository extends AbstractResourceRepository<"associate-role"> {
|
|
25
|
-
constructor(
|
|
26
|
-
super("associate-role",
|
|
25
|
+
constructor(config: Config) {
|
|
26
|
+
super("associate-role", config);
|
|
27
27
|
this.actions = new AssociateRoleUpdateHandler(this._storage);
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
AttributeGroupSetKeyAction,
|
|
8
8
|
AttributeGroupUpdateAction,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
|
+
import type { Config } from "~src/config";
|
|
10
11
|
import { getBaseResourceProperties } from "../helpers";
|
|
11
|
-
import type { AbstractStorage } from "../storage/abstract";
|
|
12
12
|
import type { Writable } from "../types";
|
|
13
13
|
import type { UpdateHandlerInterface } from "./abstract";
|
|
14
14
|
import {
|
|
@@ -18,8 +18,8 @@ import {
|
|
|
18
18
|
} from "./abstract";
|
|
19
19
|
|
|
20
20
|
export class AttributeGroupRepository extends AbstractResourceRepository<"attribute-group"> {
|
|
21
|
-
constructor(
|
|
22
|
-
super("attribute-group",
|
|
21
|
+
constructor(config: Config) {
|
|
22
|
+
super("attribute-group", config);
|
|
23
23
|
this.actions = new AttributeGroupUpdateHandler(this._storage);
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
type Company,
|
|
24
24
|
type Division,
|
|
25
25
|
} from "@commercetools/platform-sdk";
|
|
26
|
-
import type {
|
|
26
|
+
import type { Config } from "~src/config";
|
|
27
27
|
import { generateRandomString, getBaseResourceProperties } from "../helpers";
|
|
28
28
|
import type { Writable } from "../types";
|
|
29
29
|
import type { UpdateHandlerInterface } from "./abstract";
|
|
@@ -41,8 +41,8 @@ import {
|
|
|
41
41
|
} from "./helpers";
|
|
42
42
|
|
|
43
43
|
export class BusinessUnitRepository extends AbstractResourceRepository<"business-unit"> {
|
|
44
|
-
constructor(
|
|
45
|
-
super("business-unit",
|
|
44
|
+
constructor(config: Config) {
|
|
45
|
+
super("business-unit", config);
|
|
46
46
|
this.actions = new BusinessUnitUpdateHandler(this._storage);
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { CartDraft, LineItem } from "@commercetools/platform-sdk";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
+
import type { Config } from "~src/config";
|
|
3
4
|
import { InMemoryStorage } from "~src/storage";
|
|
4
5
|
import { CartRepository } from "./index";
|
|
5
6
|
|
|
6
7
|
describe("Cart repository", () => {
|
|
7
8
|
const storage = new InMemoryStorage();
|
|
8
|
-
const
|
|
9
|
+
const config: Config = { storage, strict: false };
|
|
10
|
+
const repository = new CartRepository(config);
|
|
9
11
|
|
|
10
12
|
test("create cart in store", async () => {
|
|
11
13
|
storage.add("dummy", "product", {
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
type ProductPagedQueryResponse,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
10
|
import { v4 as uuidv4 } from "uuid";
|
|
11
|
+
import type { Config } from "~src/config";
|
|
11
12
|
import { CommercetoolsError } from "~src/exceptions";
|
|
12
13
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
13
|
-
import type { AbstractStorage } from "~src/storage/abstract";
|
|
14
14
|
import type { Writable } from "~src/types";
|
|
15
15
|
import {
|
|
16
16
|
AbstractResourceRepository,
|
|
@@ -21,8 +21,8 @@ import { CartUpdateHandler } from "./actions";
|
|
|
21
21
|
import { calculateCartTotalPrice, selectPrice } from "./helpers";
|
|
22
22
|
|
|
23
23
|
export class CartRepository extends AbstractResourceRepository<"cart"> {
|
|
24
|
-
constructor(
|
|
25
|
-
super("cart",
|
|
24
|
+
constructor(config: Config) {
|
|
25
|
+
super("cart", config);
|
|
26
26
|
this.actions = new CartUpdateHandler(this._storage);
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
CartDiscountValueGiftLineItem,
|
|
8
8
|
CartDiscountValueRelative,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
|
+
import type { Config } from "~src/config";
|
|
10
11
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
11
|
-
import type { AbstractStorage } from "~src/storage/abstract";
|
|
12
12
|
import {
|
|
13
13
|
AbstractResourceRepository,
|
|
14
14
|
type RepositoryContext,
|
|
@@ -21,9 +21,9 @@ import {
|
|
|
21
21
|
import { CartDiscountUpdateHandler } from "./actions";
|
|
22
22
|
|
|
23
23
|
export class CartDiscountRepository extends AbstractResourceRepository<"cart-discount"> {
|
|
24
|
-
constructor(
|
|
25
|
-
super("cart-discount",
|
|
26
|
-
this.actions = new CartDiscountUpdateHandler(storage);
|
|
24
|
+
constructor(config: Config) {
|
|
25
|
+
super("cart-discount", config);
|
|
26
|
+
this.actions = new CartDiscountUpdateHandler(config.storage);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
create(context: RepositoryContext, draft: CartDiscountDraft): CartDiscount {
|
|
@@ -80,7 +80,5 @@ export class CartDiscountRepository extends AbstractResourceRepository<"cart-dis
|
|
|
80
80
|
} as CartDiscountValueRelative;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
return value;
|
|
85
83
|
}
|
|
86
84
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
+
import type { Config } from "~src/config";
|
|
2
3
|
import { InMemoryStorage } from "~src/storage";
|
|
3
4
|
import { CategoryRepository } from "./index";
|
|
4
5
|
|
|
5
6
|
describe("Order repository", () => {
|
|
6
7
|
const storage = new InMemoryStorage();
|
|
7
|
-
const
|
|
8
|
+
const config: Config = { storage, strict: false };
|
|
9
|
+
const repository = new CategoryRepository(config);
|
|
8
10
|
|
|
9
11
|
test("valid ancestors", async () => {
|
|
10
12
|
const root = repository.create(
|
|
@@ -4,9 +4,9 @@ import type {
|
|
|
4
4
|
CategoryReference,
|
|
5
5
|
} from "@commercetools/platform-sdk";
|
|
6
6
|
import { v4 as uuidv4 } from "uuid";
|
|
7
|
+
import type { Config } from "~src/config";
|
|
7
8
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
8
9
|
import { parseExpandClause } from "~src/lib/expandParser";
|
|
9
|
-
import type { AbstractStorage } from "~src/storage/abstract";
|
|
10
10
|
import type { Writable } from "~src/types";
|
|
11
11
|
import type { GetParams } from "../abstract";
|
|
12
12
|
import {
|
|
@@ -17,8 +17,8 @@ import { createCustomFields } from "../helpers";
|
|
|
17
17
|
import { CategoryUpdateHandler } from "./actions";
|
|
18
18
|
|
|
19
19
|
export class CategoryRepository extends AbstractResourceRepository<"category"> {
|
|
20
|
-
constructor(
|
|
21
|
-
super("category",
|
|
20
|
+
constructor(config: Config) {
|
|
21
|
+
super("category", config);
|
|
22
22
|
this.actions = new CategoryUpdateHandler(this._storage);
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -10,8 +10,8 @@ import type {
|
|
|
10
10
|
ChannelSetGeoLocationAction,
|
|
11
11
|
ChannelUpdateAction,
|
|
12
12
|
} from "@commercetools/platform-sdk";
|
|
13
|
+
import type { Config } from "~src/config";
|
|
13
14
|
import { getBaseResourceProperties } from "../helpers";
|
|
14
|
-
import type { AbstractStorage } from "../storage/abstract";
|
|
15
15
|
import type { Writable } from "../types";
|
|
16
16
|
import type { UpdateHandlerInterface } from "./abstract";
|
|
17
17
|
import {
|
|
@@ -22,8 +22,8 @@ import {
|
|
|
22
22
|
import { createAddress, createCustomFields } from "./helpers";
|
|
23
23
|
|
|
24
24
|
export class ChannelRepository extends AbstractResourceRepository<"channel"> {
|
|
25
|
-
constructor(
|
|
26
|
-
super("channel",
|
|
25
|
+
constructor(config: Config) {
|
|
26
|
+
super("channel", config);
|
|
27
27
|
this.actions = new ChannelUpdateHandler(this._storage);
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -3,8 +3,8 @@ import type {
|
|
|
3
3
|
CustomObjectDraft,
|
|
4
4
|
InvalidOperationError,
|
|
5
5
|
} from "@commercetools/platform-sdk";
|
|
6
|
+
import type { Config } from "~src/config";
|
|
6
7
|
import { CommercetoolsError } from "~src/exceptions";
|
|
7
|
-
import type { AbstractStorage } from "~src/storage";
|
|
8
8
|
import { cloneObject, getBaseResourceProperties } from "../helpers";
|
|
9
9
|
import type { Writable } from "../types";
|
|
10
10
|
import type { QueryParams } from "./abstract";
|
|
@@ -12,8 +12,8 @@ import { AbstractResourceRepository, type RepositoryContext } from "./abstract";
|
|
|
12
12
|
import { checkConcurrentModification } from "./errors";
|
|
13
13
|
|
|
14
14
|
export class CustomObjectRepository extends AbstractResourceRepository<"key-value-document"> {
|
|
15
|
-
constructor(
|
|
16
|
-
super("key-value-document",
|
|
15
|
+
constructor(config: Config) {
|
|
16
|
+
super("key-value-document", config);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
create(
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Store } from "@commercetools/platform-sdk";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
+
import type { Config } from "~src/config";
|
|
3
4
|
import { InMemoryStorage } from "~src/storage";
|
|
4
5
|
import { CustomerRepository } from "./index";
|
|
5
6
|
|
|
6
7
|
describe("Customer repository", () => {
|
|
7
8
|
const storage = new InMemoryStorage();
|
|
8
|
-
const
|
|
9
|
+
const config: Config = { storage, strict: false };
|
|
10
|
+
const repository = new CustomerRepository(config);
|
|
9
11
|
|
|
10
12
|
test("query by lowercaseEmail", async () => {
|
|
11
13
|
const customer = repository.create(
|