@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,113 @@
|
|
|
1
|
+
import type { BusinessUnitDraft } from "@commercetools/platform-sdk";
|
|
2
|
+
import supertest from "supertest";
|
|
3
|
+
import { describe, expect, test } from "vitest";
|
|
4
|
+
import { CommercetoolsMock } from "../index";
|
|
5
|
+
|
|
6
|
+
const ctMock = new CommercetoolsMock();
|
|
7
|
+
|
|
8
|
+
describe("MyBusinessUnit", () => {
|
|
9
|
+
test("Get my business units", async () => {
|
|
10
|
+
// First create a business unit
|
|
11
|
+
const draft: BusinessUnitDraft = {
|
|
12
|
+
key: "my-business-unit",
|
|
13
|
+
unitType: "Company",
|
|
14
|
+
name: "My Business Unit",
|
|
15
|
+
contactEmail: "contact@example.com",
|
|
16
|
+
};
|
|
17
|
+
const createResponse = await supertest(ctMock.app)
|
|
18
|
+
.post("/dummy/business-units")
|
|
19
|
+
.send(draft);
|
|
20
|
+
|
|
21
|
+
expect(createResponse.status).toBe(201);
|
|
22
|
+
|
|
23
|
+
const response = await supertest(ctMock.app).get(
|
|
24
|
+
"/dummy/me/business-units/",
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(response.status).toBe(200);
|
|
28
|
+
expect(response.body.count).toBeGreaterThanOrEqual(0);
|
|
29
|
+
expect(response.body.results).toBeDefined();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("Get my business unit by ID", async () => {
|
|
33
|
+
// First create a business unit
|
|
34
|
+
const draft: BusinessUnitDraft = {
|
|
35
|
+
key: "my-business-unit",
|
|
36
|
+
unitType: "Company",
|
|
37
|
+
name: "My Business Unit",
|
|
38
|
+
contactEmail: "contact@example.com",
|
|
39
|
+
};
|
|
40
|
+
const createResponse = await supertest(ctMock.app)
|
|
41
|
+
.post("/dummy/business-units")
|
|
42
|
+
.send(draft);
|
|
43
|
+
|
|
44
|
+
expect(createResponse.status).toBe(201);
|
|
45
|
+
|
|
46
|
+
const response = await supertest(ctMock.app).get(
|
|
47
|
+
`/dummy/me/business-units/${createResponse.body.id}`,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(response.status).toBe(200);
|
|
51
|
+
expect(response.body).toEqual(createResponse.body);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("Delete my business unit", async () => {
|
|
55
|
+
// First create a business unit
|
|
56
|
+
const draft: BusinessUnitDraft = {
|
|
57
|
+
key: "my-business-unit",
|
|
58
|
+
unitType: "Company",
|
|
59
|
+
name: "My Business Unit",
|
|
60
|
+
contactEmail: "contact@example.com",
|
|
61
|
+
};
|
|
62
|
+
const createResponse = await supertest(ctMock.app)
|
|
63
|
+
.post("/dummy/business-units")
|
|
64
|
+
.send(draft);
|
|
65
|
+
|
|
66
|
+
expect(createResponse.status).toBe(201);
|
|
67
|
+
|
|
68
|
+
// Now delete the business unit
|
|
69
|
+
const deleteResponse = await supertest(ctMock.app).delete(
|
|
70
|
+
`/dummy/me/business-units/${createResponse.body.id}`,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(deleteResponse.status).toBe(200);
|
|
74
|
+
expect(deleteResponse.body).toEqual(createResponse.body);
|
|
75
|
+
|
|
76
|
+
// Verify that the business unit is deleted
|
|
77
|
+
const newResponse = await supertest(ctMock.app).get(
|
|
78
|
+
`/dummy/me/business-units/${createResponse.body.id}`,
|
|
79
|
+
);
|
|
80
|
+
expect(newResponse.status).toBe(404);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("Update my business unit", async () => {
|
|
84
|
+
// First create a business unit
|
|
85
|
+
const draft: BusinessUnitDraft = {
|
|
86
|
+
key: "my-business-unit",
|
|
87
|
+
unitType: "Company",
|
|
88
|
+
name: "My Business Unit",
|
|
89
|
+
contactEmail: "contact@example.com",
|
|
90
|
+
};
|
|
91
|
+
const createResponse = await supertest(ctMock.app)
|
|
92
|
+
.post("/dummy/business-units")
|
|
93
|
+
.send(draft);
|
|
94
|
+
|
|
95
|
+
expect(createResponse.status).toBe(201);
|
|
96
|
+
|
|
97
|
+
const updateResponse = await supertest(ctMock.app)
|
|
98
|
+
.post(`/dummy/me/business-units/${createResponse.body.id}`)
|
|
99
|
+
.send({
|
|
100
|
+
id: createResponse.body.id,
|
|
101
|
+
version: createResponse.body.version,
|
|
102
|
+
actions: [
|
|
103
|
+
{
|
|
104
|
+
action: "changeName",
|
|
105
|
+
name: "Updated Business Unit Name",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(updateResponse.status).toBe(200);
|
|
111
|
+
expect(updateResponse.body.name).toBe("Updated Business Unit Name");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -22,6 +22,12 @@ export class MyBusinessUnitService extends AbstractService {
|
|
|
22
22
|
this.extraRoutes(router);
|
|
23
23
|
|
|
24
24
|
router.get("/business-units/", this.get.bind(this));
|
|
25
|
+
router.get("/business-units/:id", this.getWithId.bind(this));
|
|
26
|
+
|
|
27
|
+
router.delete("/business-units/:id", this.deleteWithId.bind(this));
|
|
28
|
+
|
|
29
|
+
router.post("/business-units/", this.post.bind(this));
|
|
30
|
+
router.post("/business-units/:id", this.postWithId.bind(this));
|
|
25
31
|
|
|
26
32
|
parent.use(`/${basePath}`, router);
|
|
27
33
|
}
|
|
@@ -293,4 +293,28 @@ describe("/me", () => {
|
|
|
293
293
|
expect(response.body.version).toBe(3);
|
|
294
294
|
expect(response.body.custom.fields.foobar).toBe(true);
|
|
295
295
|
});
|
|
296
|
+
|
|
297
|
+
test("deleteMe", async () => {
|
|
298
|
+
const response = await supertest(ctMock.app).delete("/dummy/me");
|
|
299
|
+
expect(response.status).toBe(200);
|
|
300
|
+
expect(response.body.id).toBeDefined();
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("signIn with invalid credentials", async () => {
|
|
304
|
+
const response = await supertest(ctMock.app).post("/dummy/me/login").send({
|
|
305
|
+
email: "nonexistent@example.com",
|
|
306
|
+
password: "wrongpassword",
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
expect(response.status).toBe(400);
|
|
310
|
+
expect(response.body).toEqual({
|
|
311
|
+
message: "Account with the given credentials not found.",
|
|
312
|
+
errors: [
|
|
313
|
+
{
|
|
314
|
+
code: "InvalidCredentials",
|
|
315
|
+
message: "Account with the given credentials not found.",
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
});
|
|
319
|
+
});
|
|
296
320
|
});
|
|
@@ -273,6 +273,24 @@ describe("Order payment tests", () => {
|
|
|
273
273
|
expect(maybePayment).toBeDefined();
|
|
274
274
|
expect(maybePayment.paymentStatus.state.obj).toBeDefined();
|
|
275
275
|
});
|
|
276
|
+
|
|
277
|
+
test("get by orderNumber - not found", async () => {
|
|
278
|
+
const response = await supertest(ctMock.app).get(
|
|
279
|
+
"/dummy/orders/order-number=nonexistent",
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
expect(response.status).toBe(404);
|
|
283
|
+
expect(response.body).toEqual({
|
|
284
|
+
statusCode: 404,
|
|
285
|
+
message: "The Resource with key 'nonexistent' was not found.",
|
|
286
|
+
errors: [
|
|
287
|
+
{
|
|
288
|
+
code: "ResourceNotFound",
|
|
289
|
+
message: "The Resource with key 'nonexistent' was not found.",
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
});
|
|
293
|
+
});
|
|
276
294
|
});
|
|
277
295
|
|
|
278
296
|
describe("Order Update Actions", () => {
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { ProductDiscountDraft } from "@commercetools/platform-sdk";
|
|
2
|
+
import supertest from "supertest";
|
|
3
|
+
import { describe, expect, test } from "vitest";
|
|
4
|
+
import { CommercetoolsMock } from "../index";
|
|
5
|
+
|
|
6
|
+
const ctMock = new CommercetoolsMock();
|
|
7
|
+
|
|
8
|
+
describe("ProductDiscount", () => {
|
|
9
|
+
test("Create product discount", async () => {
|
|
10
|
+
const draft: ProductDiscountDraft = {
|
|
11
|
+
key: "summer-sale",
|
|
12
|
+
name: {
|
|
13
|
+
en: "Summer Sale",
|
|
14
|
+
},
|
|
15
|
+
description: {
|
|
16
|
+
en: "20% off all products",
|
|
17
|
+
},
|
|
18
|
+
value: {
|
|
19
|
+
type: "relative",
|
|
20
|
+
permyriad: 2000,
|
|
21
|
+
},
|
|
22
|
+
predicate: "1=1",
|
|
23
|
+
sortOrder: "0.1",
|
|
24
|
+
isActive: true,
|
|
25
|
+
};
|
|
26
|
+
const response = await supertest(ctMock.app)
|
|
27
|
+
.post("/dummy/product-discounts")
|
|
28
|
+
.send(draft);
|
|
29
|
+
|
|
30
|
+
expect(response.status).toBe(201);
|
|
31
|
+
|
|
32
|
+
expect(response.body).toEqual({
|
|
33
|
+
createdAt: expect.anything(),
|
|
34
|
+
description: {
|
|
35
|
+
en: "20% off all products",
|
|
36
|
+
},
|
|
37
|
+
id: expect.anything(),
|
|
38
|
+
isActive: true,
|
|
39
|
+
key: "summer-sale",
|
|
40
|
+
lastModifiedAt: expect.anything(),
|
|
41
|
+
name: {
|
|
42
|
+
en: "Summer Sale",
|
|
43
|
+
},
|
|
44
|
+
predicate: "1=1",
|
|
45
|
+
references: [],
|
|
46
|
+
sortOrder: "0.1",
|
|
47
|
+
validFrom: undefined,
|
|
48
|
+
validUntil: undefined,
|
|
49
|
+
value: {
|
|
50
|
+
permyriad: 2000,
|
|
51
|
+
type: "relative",
|
|
52
|
+
},
|
|
53
|
+
version: 1,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("Get product discount", async () => {
|
|
58
|
+
const draft: ProductDiscountDraft = {
|
|
59
|
+
key: "test-discount",
|
|
60
|
+
name: {
|
|
61
|
+
en: "Test Discount",
|
|
62
|
+
},
|
|
63
|
+
value: {
|
|
64
|
+
type: "absolute",
|
|
65
|
+
money: [
|
|
66
|
+
{
|
|
67
|
+
currencyCode: "EUR",
|
|
68
|
+
centAmount: 1000,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
predicate: "1=1",
|
|
73
|
+
sortOrder: "0.2",
|
|
74
|
+
isActive: true,
|
|
75
|
+
};
|
|
76
|
+
const createResponse = await supertest(ctMock.app)
|
|
77
|
+
.post("/dummy/product-discounts")
|
|
78
|
+
.send(draft);
|
|
79
|
+
|
|
80
|
+
expect(createResponse.status).toBe(201);
|
|
81
|
+
|
|
82
|
+
const response = await supertest(ctMock.app).get(
|
|
83
|
+
`/dummy/product-discounts/${createResponse.body.id}`,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(response.status).toBe(200);
|
|
87
|
+
expect(response.body).toEqual(createResponse.body);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("Get product discount by key", async () => {
|
|
91
|
+
const draft: ProductDiscountDraft = {
|
|
92
|
+
key: "key-discount",
|
|
93
|
+
name: {
|
|
94
|
+
en: "Key Discount",
|
|
95
|
+
},
|
|
96
|
+
value: {
|
|
97
|
+
type: "relative",
|
|
98
|
+
permyriad: 1500,
|
|
99
|
+
},
|
|
100
|
+
predicate: "1=1",
|
|
101
|
+
sortOrder: "0.3",
|
|
102
|
+
isActive: false,
|
|
103
|
+
};
|
|
104
|
+
const createResponse = await supertest(ctMock.app)
|
|
105
|
+
.post("/dummy/product-discounts")
|
|
106
|
+
.send(draft);
|
|
107
|
+
|
|
108
|
+
expect(createResponse.status).toBe(201);
|
|
109
|
+
|
|
110
|
+
const response = await supertest(ctMock.app).get(
|
|
111
|
+
"/dummy/product-discounts/key=key-discount",
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(response.status).toBe(200);
|
|
115
|
+
expect(response.body).toEqual(createResponse.body);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("Query product discounts", async () => {
|
|
119
|
+
const draft: ProductDiscountDraft = {
|
|
120
|
+
key: "query-discount",
|
|
121
|
+
name: {
|
|
122
|
+
en: "Query Discount",
|
|
123
|
+
},
|
|
124
|
+
value: {
|
|
125
|
+
type: "relative",
|
|
126
|
+
permyriad: 500,
|
|
127
|
+
},
|
|
128
|
+
predicate: "1=1",
|
|
129
|
+
sortOrder: "0.4",
|
|
130
|
+
isActive: true,
|
|
131
|
+
};
|
|
132
|
+
const createResponse = await supertest(ctMock.app)
|
|
133
|
+
.post("/dummy/product-discounts")
|
|
134
|
+
.send(draft);
|
|
135
|
+
|
|
136
|
+
expect(createResponse.status).toBe(201);
|
|
137
|
+
|
|
138
|
+
const response = await supertest(ctMock.app).get(
|
|
139
|
+
"/dummy/product-discounts",
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(response.status).toBe(200);
|
|
143
|
+
expect(response.body.count).toBeGreaterThan(0);
|
|
144
|
+
expect(response.body.results).toContainEqual(createResponse.body);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -48,4 +48,21 @@ describe("Project", () => {
|
|
|
48
48
|
const response = await supertest(ctMock.app).post("/dummy/");
|
|
49
49
|
expect(response.statusCode).toBe(400);
|
|
50
50
|
});
|
|
51
|
+
|
|
52
|
+
test("Post successful update", async () => {
|
|
53
|
+
const response = await supertest(ctMock.app)
|
|
54
|
+
.post("/dummy/")
|
|
55
|
+
.send({
|
|
56
|
+
version: 1,
|
|
57
|
+
actions: [
|
|
58
|
+
{
|
|
59
|
+
action: "changeName",
|
|
60
|
+
name: "Updated Project Name",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
expect(response.status).toBe(200);
|
|
65
|
+
expect(response.body.name).toBe("Updated Project Name");
|
|
66
|
+
expect(response.body.version).toBe(2);
|
|
67
|
+
});
|
|
51
68
|
});
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import type { Product, Review, State } from "@commercetools/platform-sdk";
|
|
2
|
+
import supertest from "supertest";
|
|
3
|
+
import { beforeEach, describe, expect, test } from "vitest";
|
|
4
|
+
import { CommercetoolsMock } from "~src/index";
|
|
5
|
+
|
|
6
|
+
describe("Review Update Actions", () => {
|
|
7
|
+
let ctMock: CommercetoolsMock;
|
|
8
|
+
let review: Review;
|
|
9
|
+
let product: Product;
|
|
10
|
+
let state: State;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
ctMock = new CommercetoolsMock();
|
|
14
|
+
|
|
15
|
+
// Create a product to target
|
|
16
|
+
const productResponse = await supertest(ctMock.app)
|
|
17
|
+
.post("/dummy/products")
|
|
18
|
+
.send({
|
|
19
|
+
name: { en: "Test Product" },
|
|
20
|
+
slug: { en: "test-product" },
|
|
21
|
+
productType: {
|
|
22
|
+
typeId: "product-type",
|
|
23
|
+
key: "dummy-product-type",
|
|
24
|
+
},
|
|
25
|
+
masterVariant: {
|
|
26
|
+
sku: "test-sku-1",
|
|
27
|
+
prices: [
|
|
28
|
+
{
|
|
29
|
+
value: {
|
|
30
|
+
currencyCode: "EUR",
|
|
31
|
+
centAmount: 1000,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
expect(productResponse.status).toBe(201);
|
|
38
|
+
product = productResponse.body;
|
|
39
|
+
|
|
40
|
+
// Create a state
|
|
41
|
+
const stateResponse = await supertest(ctMock.app)
|
|
42
|
+
.post("/dummy/states")
|
|
43
|
+
.send({
|
|
44
|
+
key: "review-state",
|
|
45
|
+
type: "ReviewState",
|
|
46
|
+
name: { en: "Review State" },
|
|
47
|
+
initial: true,
|
|
48
|
+
});
|
|
49
|
+
expect(stateResponse.status).toBe(201);
|
|
50
|
+
state = stateResponse.body;
|
|
51
|
+
|
|
52
|
+
// Create a review
|
|
53
|
+
const reviewResponse = await supertest(ctMock.app)
|
|
54
|
+
.post("/dummy/reviews")
|
|
55
|
+
.send({
|
|
56
|
+
key: "test-review",
|
|
57
|
+
authorName: "John Doe",
|
|
58
|
+
title: "Great product!",
|
|
59
|
+
text: "I really love this product.",
|
|
60
|
+
rating: 5,
|
|
61
|
+
target: {
|
|
62
|
+
typeId: "product",
|
|
63
|
+
id: product.id,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
expect(reviewResponse.status).toBe(201);
|
|
67
|
+
review = reviewResponse.body;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("setAuthorName", async () => {
|
|
71
|
+
const response = await supertest(ctMock.app)
|
|
72
|
+
.post(`/dummy/reviews/${review.id}`)
|
|
73
|
+
.send({
|
|
74
|
+
version: 1,
|
|
75
|
+
actions: [
|
|
76
|
+
{
|
|
77
|
+
action: "setAuthorName",
|
|
78
|
+
authorName: "Jane Smith",
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(response.status).toBe(200);
|
|
84
|
+
expect(response.body.authorName).toBe("Jane Smith");
|
|
85
|
+
expect(response.body.version).toBe(2);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("setTitle", async () => {
|
|
89
|
+
const response = await supertest(ctMock.app)
|
|
90
|
+
.post(`/dummy/reviews/${review.id}`)
|
|
91
|
+
.send({
|
|
92
|
+
version: 1,
|
|
93
|
+
actions: [
|
|
94
|
+
{
|
|
95
|
+
action: "setTitle",
|
|
96
|
+
title: "Amazing product!",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(response.status).toBe(200);
|
|
102
|
+
expect(response.body.title).toBe("Amazing product!");
|
|
103
|
+
expect(response.body.version).toBe(2);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("setText", async () => {
|
|
107
|
+
const response = await supertest(ctMock.app)
|
|
108
|
+
.post(`/dummy/reviews/${review.id}`)
|
|
109
|
+
.send({
|
|
110
|
+
version: 1,
|
|
111
|
+
actions: [
|
|
112
|
+
{
|
|
113
|
+
action: "setText",
|
|
114
|
+
text: "This product exceeded my expectations!",
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(response.status).toBe(200);
|
|
120
|
+
expect(response.body.text).toBe("This product exceeded my expectations!");
|
|
121
|
+
expect(response.body.version).toBe(2);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("setRating", async () => {
|
|
125
|
+
const response = await supertest(ctMock.app)
|
|
126
|
+
.post(`/dummy/reviews/${review.id}`)
|
|
127
|
+
.send({
|
|
128
|
+
version: 1,
|
|
129
|
+
actions: [
|
|
130
|
+
{
|
|
131
|
+
action: "setRating",
|
|
132
|
+
rating: 4,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(response.status).toBe(200);
|
|
138
|
+
expect(response.body.rating).toBe(4);
|
|
139
|
+
expect(response.body.version).toBe(2);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("setLocale", async () => {
|
|
143
|
+
const response = await supertest(ctMock.app)
|
|
144
|
+
.post(`/dummy/reviews/${review.id}`)
|
|
145
|
+
.send({
|
|
146
|
+
version: 1,
|
|
147
|
+
actions: [
|
|
148
|
+
{
|
|
149
|
+
action: "setLocale",
|
|
150
|
+
locale: "de-DE",
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(response.status).toBe(200);
|
|
156
|
+
expect(response.body.locale).toBe("de-DE");
|
|
157
|
+
expect(response.body.version).toBe(2);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("setKey", async () => {
|
|
161
|
+
const response = await supertest(ctMock.app)
|
|
162
|
+
.post(`/dummy/reviews/${review.id}`)
|
|
163
|
+
.send({
|
|
164
|
+
version: 1,
|
|
165
|
+
actions: [
|
|
166
|
+
{
|
|
167
|
+
action: "setKey",
|
|
168
|
+
key: "updated-review-key",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(response.status).toBe(200);
|
|
174
|
+
expect(response.body.key).toBe("updated-review-key");
|
|
175
|
+
expect(response.body.version).toBe(2);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("transitionState", async () => {
|
|
179
|
+
const response = await supertest(ctMock.app)
|
|
180
|
+
.post(`/dummy/reviews/${review.id}`)
|
|
181
|
+
.send({
|
|
182
|
+
version: 1,
|
|
183
|
+
actions: [
|
|
184
|
+
{
|
|
185
|
+
action: "transitionState",
|
|
186
|
+
state: {
|
|
187
|
+
typeId: "state",
|
|
188
|
+
id: state.id,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(response.status).toBe(200);
|
|
195
|
+
expect(response.body.state).toMatchObject({
|
|
196
|
+
typeId: "state",
|
|
197
|
+
id: state.id,
|
|
198
|
+
});
|
|
199
|
+
expect(response.body.version).toBe(2);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("multiple actions in one update", async () => {
|
|
203
|
+
const response = await supertest(ctMock.app)
|
|
204
|
+
.post(`/dummy/reviews/${review.id}`)
|
|
205
|
+
.send({
|
|
206
|
+
version: 1,
|
|
207
|
+
actions: [
|
|
208
|
+
{
|
|
209
|
+
action: "setAuthorName",
|
|
210
|
+
authorName: "Updated Author",
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
action: "setRating",
|
|
214
|
+
rating: 3,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
action: "setText",
|
|
218
|
+
text: "Updated review text",
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
expect(response.status).toBe(200);
|
|
224
|
+
expect(response.body.authorName).toBe("Updated Author");
|
|
225
|
+
expect(response.body.rating).toBe(3);
|
|
226
|
+
expect(response.body.text).toBe("Updated review text");
|
|
227
|
+
// Version should be incremented by 3 since each action modifies the resource
|
|
228
|
+
expect(response.body.version).toBe(4);
|
|
229
|
+
});
|
|
230
|
+
});
|