@labdigital/commercetools-mock 2.51.0 → 2.53.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 +34 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +140 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/product-review-statistics.test.ts +349 -0
- package/src/lib/productSearchFilter.test.ts +77 -0
- package/src/lib/review-statistics.ts +58 -0
- package/src/product-projection-search.ts +17 -2
- package/src/product-search-availability.test.ts +242 -0
- package/src/product-search.ts +22 -4
- package/src/repositories/as-associate.test.ts +126 -0
- package/src/repositories/attribute-group.test.ts +221 -0
- package/src/repositories/business-unit.test.ts +425 -0
- package/src/repositories/business-unit.ts +57 -1
- package/src/repositories/channel.test.ts +374 -0
- package/src/repositories/customer-group.test.ts +262 -0
- package/src/repositories/extension.test.ts +306 -0
- package/src/repositories/index.test.ts +17 -0
- package/src/repositories/product/index.ts +22 -1
- package/src/repositories/product-projection.ts +8 -2
- package/src/repositories/review.test.ts +636 -0
- package/src/repositories/review.ts +145 -4
- package/src/repositories/subscription.test.ts +207 -0
- package/src/repositories/zone.test.ts +278 -0
- package/src/services/as-associate-cart.test.ts +58 -0
- package/src/services/as-associate.test.ts +34 -0
- package/src/services/attribute-group.test.ts +114 -0
- package/src/services/channel.test.ts +90 -0
- package/src/services/customer-group.test.ts +85 -0
- package/src/services/discount-code.test.ts +120 -0
- package/src/services/extension.test.ts +130 -0
- package/src/services/my-business-unit.test.ts +113 -0
- package/src/services/my-business-unit.ts +6 -0
- package/src/services/my-customer.test.ts +24 -0
- package/src/services/order.test.ts +18 -0
- package/src/services/product-discount.test.ts +146 -0
- package/src/services/project.test.ts +17 -0
- package/src/services/reviews.test.ts +230 -0
- package/src/services/subscription.test.ts +151 -0
- package/src/services/type.test.ts +127 -0
- package/src/services/zone.test.ts +117 -0
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ReviewDraft,
|
|
3
|
+
ReviewSetAuthorNameAction,
|
|
4
|
+
ReviewSetCustomFieldAction,
|
|
5
|
+
ReviewSetCustomTypeAction,
|
|
6
|
+
ReviewSetCustomerAction,
|
|
7
|
+
ReviewSetKeyAction,
|
|
8
|
+
ReviewSetLocaleAction,
|
|
9
|
+
ReviewSetRatingAction,
|
|
10
|
+
ReviewSetTargetAction,
|
|
11
|
+
ReviewSetTextAction,
|
|
12
|
+
ReviewSetTitleAction,
|
|
13
|
+
ReviewTransitionStateAction,
|
|
14
|
+
} from "@commercetools/platform-sdk";
|
|
15
|
+
import { describe, expect, test } from "vitest";
|
|
16
|
+
import type { Config } from "~src/config";
|
|
17
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
18
|
+
import { InMemoryStorage } from "~src/storage";
|
|
19
|
+
import { ReviewRepository } from "./review";
|
|
20
|
+
|
|
21
|
+
describe("Review Repository", () => {
|
|
22
|
+
const storage = new InMemoryStorage();
|
|
23
|
+
const config: Config = { storage, strict: false };
|
|
24
|
+
const repository = new ReviewRepository(config);
|
|
25
|
+
|
|
26
|
+
// Add required dependencies for testing
|
|
27
|
+
storage.add("dummy", "product", {
|
|
28
|
+
...getBaseResourceProperties(),
|
|
29
|
+
id: "product-123",
|
|
30
|
+
key: "test-product",
|
|
31
|
+
productType: {
|
|
32
|
+
typeId: "product-type",
|
|
33
|
+
id: "product-type-123",
|
|
34
|
+
},
|
|
35
|
+
masterData: {
|
|
36
|
+
current: {
|
|
37
|
+
name: { "en-US": "Test Product" },
|
|
38
|
+
slug: { "en-US": "test-product" },
|
|
39
|
+
categories: [],
|
|
40
|
+
masterVariant: {
|
|
41
|
+
id: 1,
|
|
42
|
+
sku: "test-sku",
|
|
43
|
+
prices: [],
|
|
44
|
+
},
|
|
45
|
+
variants: [],
|
|
46
|
+
searchKeywords: {},
|
|
47
|
+
},
|
|
48
|
+
published: true,
|
|
49
|
+
staged: {
|
|
50
|
+
name: { "en-US": "Test Product" },
|
|
51
|
+
slug: { "en-US": "test-product" },
|
|
52
|
+
categories: [],
|
|
53
|
+
masterVariant: {
|
|
54
|
+
id: 1,
|
|
55
|
+
sku: "test-sku",
|
|
56
|
+
prices: [],
|
|
57
|
+
},
|
|
58
|
+
variants: [],
|
|
59
|
+
searchKeywords: {},
|
|
60
|
+
},
|
|
61
|
+
hasStagedChanges: false,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
storage.add("dummy", "channel", {
|
|
66
|
+
...getBaseResourceProperties(),
|
|
67
|
+
id: "channel-123",
|
|
68
|
+
key: "test-channel",
|
|
69
|
+
name: { "en-US": "Test Channel" },
|
|
70
|
+
roles: ["ProductDistribution"],
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
storage.add("dummy", "customer", {
|
|
74
|
+
...getBaseResourceProperties(),
|
|
75
|
+
id: "customer-123",
|
|
76
|
+
email: "test@example.com",
|
|
77
|
+
firstName: "John",
|
|
78
|
+
lastName: "Doe",
|
|
79
|
+
password: "hashed-password",
|
|
80
|
+
addresses: [],
|
|
81
|
+
defaultShippingAddressId: "",
|
|
82
|
+
defaultBillingAddressId: "",
|
|
83
|
+
customerNumber: "",
|
|
84
|
+
externalId: "",
|
|
85
|
+
key: "",
|
|
86
|
+
stores: [],
|
|
87
|
+
authenticationMode: "Password" as const,
|
|
88
|
+
isEmailVerified: false,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
storage.add("dummy", "state", {
|
|
92
|
+
...getBaseResourceProperties(),
|
|
93
|
+
id: "state-123",
|
|
94
|
+
key: "approved",
|
|
95
|
+
type: "ReviewState",
|
|
96
|
+
name: { "en-US": "Approved" },
|
|
97
|
+
roles: ["ReviewIncludedInStatistics"],
|
|
98
|
+
transitions: [],
|
|
99
|
+
initial: false,
|
|
100
|
+
builtIn: false,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
storage.add("dummy", "type", {
|
|
104
|
+
...getBaseResourceProperties(),
|
|
105
|
+
id: "type-123",
|
|
106
|
+
key: "review-type",
|
|
107
|
+
name: { "en-US": "Review Type" },
|
|
108
|
+
resourceTypeIds: ["review"],
|
|
109
|
+
fieldDefinitions: [
|
|
110
|
+
{
|
|
111
|
+
name: "helpfulVotes",
|
|
112
|
+
label: { "en-US": "Helpful Votes" },
|
|
113
|
+
required: false,
|
|
114
|
+
type: { name: "Number" },
|
|
115
|
+
inputHint: "SingleLine",
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("create review with product target", () => {
|
|
121
|
+
const draft: ReviewDraft = {
|
|
122
|
+
key: "product-review-1",
|
|
123
|
+
authorName: "John Doe",
|
|
124
|
+
title: "Great product!",
|
|
125
|
+
text: "I really like this product. Highly recommended.",
|
|
126
|
+
rating: 5,
|
|
127
|
+
target: {
|
|
128
|
+
typeId: "product",
|
|
129
|
+
id: "product-123",
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const ctx = { projectKey: "dummy" };
|
|
134
|
+
const result = repository.create(ctx, draft);
|
|
135
|
+
|
|
136
|
+
expect(result.id).toBeDefined();
|
|
137
|
+
expect(result.version).toBe(1);
|
|
138
|
+
expect(result.key).toBe(draft.key);
|
|
139
|
+
expect(result.authorName).toBe(draft.authorName);
|
|
140
|
+
expect(result.title).toBe(draft.title);
|
|
141
|
+
expect(result.text).toBe(draft.text);
|
|
142
|
+
expect(result.rating).toBe(draft.rating);
|
|
143
|
+
expect(result.target?.typeId).toBe("product");
|
|
144
|
+
expect(result.target?.id).toBe("product-123");
|
|
145
|
+
expect(result.includedInStatistics).toBe(true);
|
|
146
|
+
|
|
147
|
+
// Test that the review is stored
|
|
148
|
+
const items = repository.query(ctx);
|
|
149
|
+
expect(items.count).toBe(1);
|
|
150
|
+
expect(items.results[0].id).toBe(result.id);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("create review with channel target", () => {
|
|
154
|
+
const draft: ReviewDraft = {
|
|
155
|
+
key: "channel-review-1",
|
|
156
|
+
authorName: "Jane Smith",
|
|
157
|
+
title: "Good service",
|
|
158
|
+
text: "The service was good overall.",
|
|
159
|
+
rating: 4,
|
|
160
|
+
target: {
|
|
161
|
+
typeId: "channel",
|
|
162
|
+
id: "channel-123",
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const ctx = { projectKey: "dummy" };
|
|
167
|
+
const result = repository.create(ctx, draft);
|
|
168
|
+
|
|
169
|
+
expect(result.id).toBeDefined();
|
|
170
|
+
expect(result.target?.typeId).toBe("channel");
|
|
171
|
+
expect(result.target?.id).toBe("channel-123");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("create review with all optional fields", () => {
|
|
175
|
+
const draft: ReviewDraft = {
|
|
176
|
+
key: "full-review",
|
|
177
|
+
authorName: "Alice Johnson",
|
|
178
|
+
title: "Complete review",
|
|
179
|
+
text: "This is a complete review with all fields.",
|
|
180
|
+
rating: 3,
|
|
181
|
+
locale: "en-US",
|
|
182
|
+
uniquenessValue: "unique-123",
|
|
183
|
+
target: {
|
|
184
|
+
typeId: "product",
|
|
185
|
+
id: "product-123",
|
|
186
|
+
},
|
|
187
|
+
state: {
|
|
188
|
+
typeId: "state",
|
|
189
|
+
id: "state-123",
|
|
190
|
+
},
|
|
191
|
+
custom: {
|
|
192
|
+
type: {
|
|
193
|
+
typeId: "type",
|
|
194
|
+
id: "type-123",
|
|
195
|
+
},
|
|
196
|
+
fields: {
|
|
197
|
+
helpfulVotes: 10,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const ctx = { projectKey: "dummy" };
|
|
203
|
+
const result = repository.create(ctx, draft);
|
|
204
|
+
|
|
205
|
+
expect(result.id).toBeDefined();
|
|
206
|
+
expect(result.locale).toBe(draft.locale);
|
|
207
|
+
expect(result.uniquenessValue).toBe(draft.uniquenessValue);
|
|
208
|
+
expect(result.state?.id).toBe("state-123");
|
|
209
|
+
expect(result.custom?.fields.helpfulVotes).toBe(10);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("create review fails without target", () => {
|
|
213
|
+
const draft: ReviewDraft = {
|
|
214
|
+
authorName: "Bob Wilson",
|
|
215
|
+
title: "No target review",
|
|
216
|
+
text: "This review has no target.",
|
|
217
|
+
rating: 2,
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const ctx = { projectKey: "dummy" };
|
|
221
|
+
|
|
222
|
+
expect(() => {
|
|
223
|
+
repository.create(ctx, draft);
|
|
224
|
+
}).toThrow("Missing target");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("update review - setAuthorName", () => {
|
|
228
|
+
const draft: ReviewDraft = {
|
|
229
|
+
authorName: "Original Author",
|
|
230
|
+
title: "Test Review",
|
|
231
|
+
rating: 4,
|
|
232
|
+
target: {
|
|
233
|
+
typeId: "product",
|
|
234
|
+
id: "product-123",
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const ctx = { projectKey: "dummy" };
|
|
239
|
+
const review = repository.create(ctx, draft);
|
|
240
|
+
|
|
241
|
+
const result = repository.processUpdateActions(
|
|
242
|
+
ctx,
|
|
243
|
+
review,
|
|
244
|
+
review.version,
|
|
245
|
+
[
|
|
246
|
+
{
|
|
247
|
+
action: "setAuthorName",
|
|
248
|
+
authorName: "Updated Author",
|
|
249
|
+
} as ReviewSetAuthorNameAction,
|
|
250
|
+
],
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
expect(result.authorName).toBe("Updated Author");
|
|
254
|
+
expect(result.version).toBe(review.version + 1);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("update review - setTitle", () => {
|
|
258
|
+
const draft: ReviewDraft = {
|
|
259
|
+
authorName: "Test Author",
|
|
260
|
+
title: "Original Title",
|
|
261
|
+
rating: 4,
|
|
262
|
+
target: {
|
|
263
|
+
typeId: "product",
|
|
264
|
+
id: "product-123",
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const ctx = { projectKey: "dummy" };
|
|
269
|
+
const review = repository.create(ctx, draft);
|
|
270
|
+
|
|
271
|
+
const result = repository.processUpdateActions(
|
|
272
|
+
ctx,
|
|
273
|
+
review,
|
|
274
|
+
review.version,
|
|
275
|
+
[
|
|
276
|
+
{
|
|
277
|
+
action: "setTitle",
|
|
278
|
+
title: "Updated Title",
|
|
279
|
+
} as ReviewSetTitleAction,
|
|
280
|
+
],
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
expect(result.title).toBe("Updated Title");
|
|
284
|
+
expect(result.version).toBe(review.version + 1);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test("update review - setText", () => {
|
|
288
|
+
const draft: ReviewDraft = {
|
|
289
|
+
authorName: "Test Author",
|
|
290
|
+
title: "Test Review",
|
|
291
|
+
text: "Original text",
|
|
292
|
+
rating: 4,
|
|
293
|
+
target: {
|
|
294
|
+
typeId: "product",
|
|
295
|
+
id: "product-123",
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const ctx = { projectKey: "dummy" };
|
|
300
|
+
const review = repository.create(ctx, draft);
|
|
301
|
+
|
|
302
|
+
const result = repository.processUpdateActions(
|
|
303
|
+
ctx,
|
|
304
|
+
review,
|
|
305
|
+
review.version,
|
|
306
|
+
[
|
|
307
|
+
{
|
|
308
|
+
action: "setText",
|
|
309
|
+
text: "Updated text content",
|
|
310
|
+
} as ReviewSetTextAction,
|
|
311
|
+
],
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
expect(result.text).toBe("Updated text content");
|
|
315
|
+
expect(result.version).toBe(review.version + 1);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("update review - setRating", () => {
|
|
319
|
+
const draft: ReviewDraft = {
|
|
320
|
+
authorName: "Test Author",
|
|
321
|
+
title: "Test Review",
|
|
322
|
+
rating: 3,
|
|
323
|
+
target: {
|
|
324
|
+
typeId: "product",
|
|
325
|
+
id: "product-123",
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const ctx = { projectKey: "dummy" };
|
|
330
|
+
const review = repository.create(ctx, draft);
|
|
331
|
+
|
|
332
|
+
const result = repository.processUpdateActions(
|
|
333
|
+
ctx,
|
|
334
|
+
review,
|
|
335
|
+
review.version,
|
|
336
|
+
[
|
|
337
|
+
{
|
|
338
|
+
action: "setRating",
|
|
339
|
+
rating: 5,
|
|
340
|
+
} as ReviewSetRatingAction,
|
|
341
|
+
],
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
expect(result.rating).toBe(5);
|
|
345
|
+
expect(result.version).toBe(review.version + 1);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test("update review - setLocale", () => {
|
|
349
|
+
const draft: ReviewDraft = {
|
|
350
|
+
authorName: "Test Author",
|
|
351
|
+
title: "Test Review",
|
|
352
|
+
rating: 4,
|
|
353
|
+
target: {
|
|
354
|
+
typeId: "product",
|
|
355
|
+
id: "product-123",
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const ctx = { projectKey: "dummy" };
|
|
360
|
+
const review = repository.create(ctx, draft);
|
|
361
|
+
|
|
362
|
+
const result = repository.processUpdateActions(
|
|
363
|
+
ctx,
|
|
364
|
+
review,
|
|
365
|
+
review.version,
|
|
366
|
+
[
|
|
367
|
+
{
|
|
368
|
+
action: "setLocale",
|
|
369
|
+
locale: "de-DE",
|
|
370
|
+
} as ReviewSetLocaleAction,
|
|
371
|
+
],
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
expect(result.locale).toBe("de-DE");
|
|
375
|
+
expect(result.version).toBe(review.version + 1);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("update review - setKey", () => {
|
|
379
|
+
const draft: ReviewDraft = {
|
|
380
|
+
key: "original-key",
|
|
381
|
+
authorName: "Test Author",
|
|
382
|
+
title: "Test Review",
|
|
383
|
+
rating: 4,
|
|
384
|
+
target: {
|
|
385
|
+
typeId: "product",
|
|
386
|
+
id: "product-123",
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const ctx = { projectKey: "dummy" };
|
|
391
|
+
const review = repository.create(ctx, draft);
|
|
392
|
+
|
|
393
|
+
const result = repository.processUpdateActions(
|
|
394
|
+
ctx,
|
|
395
|
+
review,
|
|
396
|
+
review.version,
|
|
397
|
+
[
|
|
398
|
+
{
|
|
399
|
+
action: "setKey",
|
|
400
|
+
key: "updated-key",
|
|
401
|
+
} as ReviewSetKeyAction,
|
|
402
|
+
],
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
expect(result.key).toBe("updated-key");
|
|
406
|
+
expect(result.version).toBe(review.version + 1);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test("update review - setCustomer", () => {
|
|
410
|
+
const draft: ReviewDraft = {
|
|
411
|
+
authorName: "Test Author",
|
|
412
|
+
title: "Test Review",
|
|
413
|
+
rating: 4,
|
|
414
|
+
target: {
|
|
415
|
+
typeId: "product",
|
|
416
|
+
id: "product-123",
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const ctx = { projectKey: "dummy" };
|
|
421
|
+
const review = repository.create(ctx, draft);
|
|
422
|
+
|
|
423
|
+
const result = repository.processUpdateActions(
|
|
424
|
+
ctx,
|
|
425
|
+
review,
|
|
426
|
+
review.version,
|
|
427
|
+
[
|
|
428
|
+
{
|
|
429
|
+
action: "setCustomer",
|
|
430
|
+
customer: {
|
|
431
|
+
typeId: "customer",
|
|
432
|
+
id: "customer-123",
|
|
433
|
+
},
|
|
434
|
+
} as ReviewSetCustomerAction,
|
|
435
|
+
],
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
expect(result.customer?.id).toBe("customer-123");
|
|
439
|
+
expect(result.version).toBe(review.version + 1);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
test("update review - setTarget", () => {
|
|
443
|
+
const draft: ReviewDraft = {
|
|
444
|
+
authorName: "Test Author",
|
|
445
|
+
title: "Test Review",
|
|
446
|
+
rating: 4,
|
|
447
|
+
target: {
|
|
448
|
+
typeId: "product",
|
|
449
|
+
id: "product-123",
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
const ctx = { projectKey: "dummy" };
|
|
454
|
+
const review = repository.create(ctx, draft);
|
|
455
|
+
|
|
456
|
+
const result = repository.processUpdateActions(
|
|
457
|
+
ctx,
|
|
458
|
+
review,
|
|
459
|
+
review.version,
|
|
460
|
+
[
|
|
461
|
+
{
|
|
462
|
+
action: "setTarget",
|
|
463
|
+
target: {
|
|
464
|
+
typeId: "channel",
|
|
465
|
+
id: "channel-123",
|
|
466
|
+
},
|
|
467
|
+
} as ReviewSetTargetAction,
|
|
468
|
+
],
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
expect(result.target?.typeId).toBe("channel");
|
|
472
|
+
expect(result.target?.id).toBe("channel-123");
|
|
473
|
+
expect(result.version).toBe(review.version + 1);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
test("update review - transitionState", () => {
|
|
477
|
+
const draft: ReviewDraft = {
|
|
478
|
+
authorName: "Test Author",
|
|
479
|
+
title: "Test Review",
|
|
480
|
+
rating: 4,
|
|
481
|
+
target: {
|
|
482
|
+
typeId: "product",
|
|
483
|
+
id: "product-123",
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const ctx = { projectKey: "dummy" };
|
|
488
|
+
const review = repository.create(ctx, draft);
|
|
489
|
+
|
|
490
|
+
const result = repository.processUpdateActions(
|
|
491
|
+
ctx,
|
|
492
|
+
review,
|
|
493
|
+
review.version,
|
|
494
|
+
[
|
|
495
|
+
{
|
|
496
|
+
action: "transitionState",
|
|
497
|
+
state: {
|
|
498
|
+
typeId: "state",
|
|
499
|
+
id: "state-123",
|
|
500
|
+
},
|
|
501
|
+
} as ReviewTransitionStateAction,
|
|
502
|
+
],
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
expect(result.state?.id).toBe("state-123");
|
|
506
|
+
expect(result.version).toBe(review.version + 1);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
test("update review - setCustomType", () => {
|
|
510
|
+
const draft: ReviewDraft = {
|
|
511
|
+
authorName: "Test Author",
|
|
512
|
+
title: "Test Review",
|
|
513
|
+
rating: 4,
|
|
514
|
+
target: {
|
|
515
|
+
typeId: "product",
|
|
516
|
+
id: "product-123",
|
|
517
|
+
},
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
const ctx = { projectKey: "dummy" };
|
|
521
|
+
const review = repository.create(ctx, draft);
|
|
522
|
+
|
|
523
|
+
// Set custom type
|
|
524
|
+
const result = repository.processUpdateActions(
|
|
525
|
+
ctx,
|
|
526
|
+
review,
|
|
527
|
+
review.version,
|
|
528
|
+
[
|
|
529
|
+
{
|
|
530
|
+
action: "setCustomType",
|
|
531
|
+
type: {
|
|
532
|
+
typeId: "type",
|
|
533
|
+
id: "type-123",
|
|
534
|
+
},
|
|
535
|
+
fields: {
|
|
536
|
+
helpfulVotes: 5,
|
|
537
|
+
},
|
|
538
|
+
} as ReviewSetCustomTypeAction,
|
|
539
|
+
],
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
expect(result.custom).toBeDefined();
|
|
543
|
+
expect(result.custom?.fields.helpfulVotes).toBe(5);
|
|
544
|
+
expect(result.version).toBe(review.version + 1);
|
|
545
|
+
|
|
546
|
+
// Remove custom type
|
|
547
|
+
const result2 = repository.processUpdateActions(
|
|
548
|
+
ctx,
|
|
549
|
+
result,
|
|
550
|
+
result.version,
|
|
551
|
+
[
|
|
552
|
+
{
|
|
553
|
+
action: "setCustomType",
|
|
554
|
+
} as ReviewSetCustomTypeAction,
|
|
555
|
+
],
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
expect(result2.custom).toBeUndefined();
|
|
559
|
+
expect(result2.version).toBe(result.version + 1);
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
test("update review - setCustomField", () => {
|
|
563
|
+
const draft: ReviewDraft = {
|
|
564
|
+
authorName: "Test Author",
|
|
565
|
+
title: "Test Review",
|
|
566
|
+
rating: 4,
|
|
567
|
+
target: {
|
|
568
|
+
typeId: "product",
|
|
569
|
+
id: "product-123",
|
|
570
|
+
},
|
|
571
|
+
custom: {
|
|
572
|
+
type: {
|
|
573
|
+
typeId: "type",
|
|
574
|
+
id: "type-123",
|
|
575
|
+
},
|
|
576
|
+
fields: {
|
|
577
|
+
helpfulVotes: 3,
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
const ctx = { projectKey: "dummy" };
|
|
583
|
+
const review = repository.create(ctx, draft);
|
|
584
|
+
|
|
585
|
+
const result = repository.processUpdateActions(
|
|
586
|
+
ctx,
|
|
587
|
+
review,
|
|
588
|
+
review.version,
|
|
589
|
+
[
|
|
590
|
+
{
|
|
591
|
+
action: "setCustomField",
|
|
592
|
+
name: "helpfulVotes",
|
|
593
|
+
value: 10,
|
|
594
|
+
} as ReviewSetCustomFieldAction,
|
|
595
|
+
],
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
expect(result.custom?.fields.helpfulVotes).toBe(10);
|
|
599
|
+
expect(result.version).toBe(review.version + 1);
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
test("get and delete review", () => {
|
|
603
|
+
const draft: ReviewDraft = {
|
|
604
|
+
key: "delete-test",
|
|
605
|
+
authorName: "Test Author",
|
|
606
|
+
title: "Delete Test Review",
|
|
607
|
+
rating: 3,
|
|
608
|
+
target: {
|
|
609
|
+
typeId: "product",
|
|
610
|
+
id: "product-123",
|
|
611
|
+
},
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
const ctx = { projectKey: "dummy" };
|
|
615
|
+
const review = repository.create(ctx, draft);
|
|
616
|
+
|
|
617
|
+
// Test get
|
|
618
|
+
const retrieved = repository.get(ctx, review.id);
|
|
619
|
+
expect(retrieved).toBeDefined();
|
|
620
|
+
expect(retrieved?.id).toBe(review.id);
|
|
621
|
+
|
|
622
|
+
// Test getByKey
|
|
623
|
+
const retrievedByKey = repository.getByKey(ctx, review.key!);
|
|
624
|
+
expect(retrievedByKey).toBeDefined();
|
|
625
|
+
expect(retrievedByKey?.key).toBe(review.key);
|
|
626
|
+
|
|
627
|
+
// Test delete
|
|
628
|
+
const deleted = repository.delete(ctx, review.id);
|
|
629
|
+
expect(deleted).toBeDefined();
|
|
630
|
+
expect(deleted?.id).toBe(review.id);
|
|
631
|
+
|
|
632
|
+
// Verify it's deleted
|
|
633
|
+
const notFound = repository.get(ctx, review.id);
|
|
634
|
+
expect(notFound).toBeNull();
|
|
635
|
+
});
|
|
636
|
+
});
|