@labdigital/commercetools-mock 2.54.0 → 2.55.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 +107 -77
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +280 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/lib/productSearchFilter.test.ts +1 -0
- package/src/lib/projectionSearchFilter.test.ts +1 -0
- package/src/priceSelector.test.ts +1 -0
- package/src/product-projection-search.ts +2 -0
- package/src/product-search.ts +1 -0
- package/src/repositories/cart/index.test.ts +2 -0
- package/src/repositories/cart/index.ts +1 -0
- package/src/repositories/cart-discount/index.ts +1 -1
- package/src/repositories/customer/index.ts +2 -0
- package/src/repositories/discount-group/actions.ts +50 -0
- package/src/repositories/discount-group/index.ts +29 -0
- package/src/repositories/index.ts +6 -0
- package/src/repositories/order/index.test.ts +126 -125
- package/src/repositories/payment/actions.ts +87 -0
- package/src/repositories/payment/index.ts +1 -1
- package/src/repositories/product/index.ts +1 -0
- package/src/repositories/product-type.ts +1 -0
- package/src/repositories/quote/index.ts +1 -0
- package/src/repositories/quote-request/index.test.ts +1 -0
- package/src/repositories/quote-request/index.ts +1 -0
- package/src/repositories/recurrence-policy/actions.ts +53 -0
- package/src/repositories/recurrence-policy/index.ts +36 -0
- package/src/repositories/recurring-order/actions.ts +157 -0
- package/src/repositories/recurring-order/index.ts +52 -0
- package/src/repositories/review.test.ts +2 -0
- package/src/repositories/shopping-list/actions.ts +1 -0
- package/src/repositories/shopping-list/index.ts +1 -0
- package/src/services/discount-group.test.ts +270 -0
- package/src/services/discount-group.ts +16 -0
- package/src/services/index.ts +12 -0
- package/src/services/my-cart.test.ts +1 -0
- package/src/services/my-payment.test.ts +1 -0
- package/src/services/payment.test.ts +1 -0
- package/src/services/product-projection.test.ts +4 -0
- package/src/services/product-type.test.ts +1 -0
- package/src/services/product.test.ts +1 -0
- package/src/services/recurrence-policy.test.ts +316 -0
- package/src/services/recurrence-policy.ts +16 -0
- package/src/services/recurring-order.test.ts +424 -0
- package/src/services/recurring-order.ts +16 -0
- package/src/services/shopping-list.test.ts +3 -0
- package/src/storage/in-memory.ts +6 -0
- package/src/types.ts +6 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RecurrencePolicy,
|
|
3
|
+
RecurrencePolicySetDescriptionAction,
|
|
4
|
+
RecurrencePolicySetKeyAction,
|
|
5
|
+
RecurrencePolicySetNameAction,
|
|
6
|
+
RecurrencePolicySetScheduleAction,
|
|
7
|
+
RecurrencePolicyUpdateAction,
|
|
8
|
+
} from "@commercetools/platform-sdk";
|
|
9
|
+
import type { Writable } from "~src/types";
|
|
10
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
11
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
12
|
+
|
|
13
|
+
export class RecurrencePolicyUpdateHandler
|
|
14
|
+
extends AbstractUpdateHandler
|
|
15
|
+
implements
|
|
16
|
+
Partial<
|
|
17
|
+
UpdateHandlerInterface<RecurrencePolicy, RecurrencePolicyUpdateAction>
|
|
18
|
+
>
|
|
19
|
+
{
|
|
20
|
+
setKey(
|
|
21
|
+
context: RepositoryContext,
|
|
22
|
+
resource: Writable<RecurrencePolicy>,
|
|
23
|
+
{ key }: RecurrencePolicySetKeyAction,
|
|
24
|
+
) {
|
|
25
|
+
if (key) {
|
|
26
|
+
resource.key = key;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setDescription(
|
|
31
|
+
context: RepositoryContext,
|
|
32
|
+
resource: Writable<RecurrencePolicy>,
|
|
33
|
+
{ description }: RecurrencePolicySetDescriptionAction,
|
|
34
|
+
) {
|
|
35
|
+
resource.description = description;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setName(
|
|
39
|
+
context: RepositoryContext,
|
|
40
|
+
resource: Writable<RecurrencePolicy>,
|
|
41
|
+
{ name }: RecurrencePolicySetNameAction,
|
|
42
|
+
) {
|
|
43
|
+
resource.name = name;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setSchedule(
|
|
47
|
+
context: RepositoryContext,
|
|
48
|
+
resource: Writable<RecurrencePolicy>,
|
|
49
|
+
{ schedule }: RecurrencePolicySetScheduleAction,
|
|
50
|
+
) {
|
|
51
|
+
resource.schedule = schedule;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import type {
|
|
3
|
+
RecurrencePolicy,
|
|
4
|
+
RecurrencePolicyDraft,
|
|
5
|
+
RecurringOrder,
|
|
6
|
+
RecurringOrderDraft,
|
|
7
|
+
} from "@commercetools/platform-sdk";
|
|
8
|
+
import type { Config } from "~src/config";
|
|
9
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
10
|
+
import {
|
|
11
|
+
AbstractResourceRepository,
|
|
12
|
+
type RepositoryContext,
|
|
13
|
+
} from "../abstract";
|
|
14
|
+
import { OrderRepository } from "../order";
|
|
15
|
+
import { RecurrencePolicyUpdateHandler } from "./actions";
|
|
16
|
+
|
|
17
|
+
export class RecurrencePolicyRepository extends AbstractResourceRepository<"recurrence-policy"> {
|
|
18
|
+
constructor(config: Config) {
|
|
19
|
+
super("recurrence-policy", config);
|
|
20
|
+
this.actions = new RecurrencePolicyUpdateHandler(config.storage);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
create(
|
|
24
|
+
context: RepositoryContext,
|
|
25
|
+
draft: RecurrencePolicyDraft,
|
|
26
|
+
): RecurrencePolicy {
|
|
27
|
+
const resource: RecurrencePolicy = {
|
|
28
|
+
...getBaseResourceProperties(),
|
|
29
|
+
key: draft.key,
|
|
30
|
+
name: draft.name,
|
|
31
|
+
description: draft.description,
|
|
32
|
+
schedule: draft.schedule,
|
|
33
|
+
};
|
|
34
|
+
return this.saveNew(context, resource);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RecurringOrder,
|
|
3
|
+
RecurringOrderSetCustomFieldAction,
|
|
4
|
+
RecurringOrderSetCustomTypeAction,
|
|
5
|
+
RecurringOrderSetExpiresAtAction,
|
|
6
|
+
RecurringOrderSetKeyAction,
|
|
7
|
+
RecurringOrderSetOrderSkipConfigurationAction,
|
|
8
|
+
RecurringOrderSetScheduleAction,
|
|
9
|
+
RecurringOrderSetStartsAtAction,
|
|
10
|
+
RecurringOrderSetStateAction,
|
|
11
|
+
RecurringOrderTransitionStateAction,
|
|
12
|
+
RecurringOrderUpdateAction,
|
|
13
|
+
} from "@commercetools/platform-sdk";
|
|
14
|
+
import type { Writable } from "~src/types";
|
|
15
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
16
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
17
|
+
|
|
18
|
+
export class RecurringOrderUpdateHandler
|
|
19
|
+
extends AbstractUpdateHandler
|
|
20
|
+
implements
|
|
21
|
+
Partial<UpdateHandlerInterface<RecurringOrder, RecurringOrderUpdateAction>>
|
|
22
|
+
{
|
|
23
|
+
setCustomField(
|
|
24
|
+
context: RepositoryContext,
|
|
25
|
+
resource: Writable<RecurringOrder>,
|
|
26
|
+
{ name, value }: RecurringOrderSetCustomFieldAction,
|
|
27
|
+
) {
|
|
28
|
+
if (!resource.custom) {
|
|
29
|
+
throw new Error("Resource has no custom field");
|
|
30
|
+
}
|
|
31
|
+
if (value === null) {
|
|
32
|
+
delete resource.custom.fields[name];
|
|
33
|
+
} else {
|
|
34
|
+
resource.custom.fields[name] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setCustomType(
|
|
39
|
+
context: RepositoryContext,
|
|
40
|
+
resource: Writable<RecurringOrder>,
|
|
41
|
+
{ type, fields }: RecurringOrderSetCustomTypeAction,
|
|
42
|
+
) {
|
|
43
|
+
if (!type) {
|
|
44
|
+
resource.custom = undefined;
|
|
45
|
+
} else {
|
|
46
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
47
|
+
context.projectKey,
|
|
48
|
+
type,
|
|
49
|
+
);
|
|
50
|
+
if (!resolvedType) {
|
|
51
|
+
throw new Error(`Type ${type} not found`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
resource.custom = {
|
|
55
|
+
type: {
|
|
56
|
+
typeId: "type",
|
|
57
|
+
id: resolvedType.id,
|
|
58
|
+
},
|
|
59
|
+
fields: fields || {},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setExpiresAt(
|
|
65
|
+
context: RepositoryContext,
|
|
66
|
+
resource: Writable<RecurringOrder>,
|
|
67
|
+
{ expiresAt }: RecurringOrderSetExpiresAtAction,
|
|
68
|
+
) {
|
|
69
|
+
resource.expiresAt = expiresAt;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setKey(
|
|
73
|
+
context: RepositoryContext,
|
|
74
|
+
resource: Writable<RecurringOrder>,
|
|
75
|
+
{ key }: RecurringOrderSetKeyAction,
|
|
76
|
+
) {
|
|
77
|
+
resource.key = key;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setOrderSkipConfiguration(
|
|
81
|
+
context: RepositoryContext,
|
|
82
|
+
resource: Writable<RecurringOrder>,
|
|
83
|
+
{
|
|
84
|
+
skipConfiguration,
|
|
85
|
+
updatedExpiresAt,
|
|
86
|
+
}: RecurringOrderSetOrderSkipConfigurationAction,
|
|
87
|
+
) {
|
|
88
|
+
if (skipConfiguration) {
|
|
89
|
+
resource.skipConfiguration = {
|
|
90
|
+
type: skipConfiguration.type,
|
|
91
|
+
totalToSkip: skipConfiguration.totalToSkip,
|
|
92
|
+
skipped: 0,
|
|
93
|
+
lastSkippedAt: undefined,
|
|
94
|
+
};
|
|
95
|
+
} else {
|
|
96
|
+
resource.skipConfiguration = undefined;
|
|
97
|
+
}
|
|
98
|
+
if (updatedExpiresAt !== undefined) {
|
|
99
|
+
resource.expiresAt = updatedExpiresAt;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
setSchedule(
|
|
104
|
+
context: RepositoryContext,
|
|
105
|
+
resource: Writable<RecurringOrder>,
|
|
106
|
+
{ recurrencePolicy }: RecurringOrderSetScheduleAction,
|
|
107
|
+
) {
|
|
108
|
+
resource.schedule = {
|
|
109
|
+
...resource.schedule,
|
|
110
|
+
...recurrencePolicy,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setStartsAt(
|
|
115
|
+
context: RepositoryContext,
|
|
116
|
+
resource: Writable<RecurringOrder>,
|
|
117
|
+
{ startsAt }: RecurringOrderSetStartsAtAction,
|
|
118
|
+
) {
|
|
119
|
+
resource.startsAt = startsAt;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setRecurringOrderState(
|
|
123
|
+
context: RepositoryContext,
|
|
124
|
+
resource: Writable<RecurringOrder>,
|
|
125
|
+
{ recurringOrderState }: RecurringOrderSetStateAction,
|
|
126
|
+
) {
|
|
127
|
+
// Map the state draft to the actual state
|
|
128
|
+
switch (recurringOrderState.type) {
|
|
129
|
+
case "active":
|
|
130
|
+
resource.recurringOrderState = "Active";
|
|
131
|
+
if (recurringOrderState.resumesAt) {
|
|
132
|
+
resource.resumesAt = recurringOrderState.resumesAt;
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
case "canceled":
|
|
136
|
+
resource.recurringOrderState = "Canceled";
|
|
137
|
+
break;
|
|
138
|
+
case "expired":
|
|
139
|
+
resource.recurringOrderState = "Expired";
|
|
140
|
+
break;
|
|
141
|
+
case "paused":
|
|
142
|
+
resource.recurringOrderState = "Paused";
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
transitionState(
|
|
148
|
+
context: RepositoryContext,
|
|
149
|
+
resource: Writable<RecurringOrder>,
|
|
150
|
+
{ state, force }: RecurringOrderTransitionStateAction,
|
|
151
|
+
) {
|
|
152
|
+
resource.state = {
|
|
153
|
+
typeId: "state",
|
|
154
|
+
id: state.id!,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import type {
|
|
3
|
+
RecurringOrder,
|
|
4
|
+
RecurringOrderDraft,
|
|
5
|
+
} from "@commercetools/platform-sdk";
|
|
6
|
+
import type { Config } from "~src/config";
|
|
7
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
8
|
+
import {
|
|
9
|
+
AbstractResourceRepository,
|
|
10
|
+
type RepositoryContext,
|
|
11
|
+
} from "../abstract";
|
|
12
|
+
import { OrderRepository } from "../order";
|
|
13
|
+
import { RecurringOrderUpdateHandler } from "./actions";
|
|
14
|
+
|
|
15
|
+
export class RecurringOrderRepository extends AbstractResourceRepository<"recurring-order"> {
|
|
16
|
+
constructor(config: Config) {
|
|
17
|
+
super("recurring-order", config);
|
|
18
|
+
this.actions = new RecurringOrderUpdateHandler(config.storage);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
create(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
draft: RecurringOrderDraft,
|
|
24
|
+
): RecurringOrder {
|
|
25
|
+
assert(draft.cart, "draft.cart is missing");
|
|
26
|
+
|
|
27
|
+
const orderRepo = new OrderRepository(this.config);
|
|
28
|
+
|
|
29
|
+
const initialOrder = orderRepo.createFromCart(context, {
|
|
30
|
+
id: draft.cart.id!,
|
|
31
|
+
typeId: "cart",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const resource: RecurringOrder = {
|
|
35
|
+
...getBaseResourceProperties(),
|
|
36
|
+
key: draft.key,
|
|
37
|
+
cart: {
|
|
38
|
+
typeId: "cart",
|
|
39
|
+
id: draft.cart.id!,
|
|
40
|
+
},
|
|
41
|
+
originOrder: {
|
|
42
|
+
typeId: "order",
|
|
43
|
+
id: initialOrder.id,
|
|
44
|
+
},
|
|
45
|
+
startsAt: draft.startsAt,
|
|
46
|
+
expiresAt: draft.expiresAt,
|
|
47
|
+
recurringOrderState: "Active",
|
|
48
|
+
schedule: { type: "standard", intervalUnit: "month", value: 1 },
|
|
49
|
+
};
|
|
50
|
+
return this.saveNew(context, resource);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -36,6 +36,7 @@ describe("Review Repository", () => {
|
|
|
36
36
|
current: {
|
|
37
37
|
name: { "en-US": "Test Product" },
|
|
38
38
|
slug: { "en-US": "test-product" },
|
|
39
|
+
attributes: [],
|
|
39
40
|
categories: [],
|
|
40
41
|
masterVariant: {
|
|
41
42
|
id: 1,
|
|
@@ -49,6 +50,7 @@ describe("Review Repository", () => {
|
|
|
49
50
|
staged: {
|
|
50
51
|
name: { "en-US": "Test Product" },
|
|
51
52
|
slug: { "en-US": "test-product" },
|
|
53
|
+
attributes: [],
|
|
52
54
|
categories: [],
|
|
53
55
|
masterVariant: {
|
|
54
56
|
id: 1,
|
|
@@ -75,6 +75,7 @@ export class ShoppingListRepository extends AbstractResourceRepository<"shopping
|
|
|
75
75
|
productId: draftLineItem.productId ?? "",
|
|
76
76
|
name: {},
|
|
77
77
|
variantId,
|
|
78
|
+
published: true,
|
|
78
79
|
quantity: draftLineItem.quantity ?? 1,
|
|
79
80
|
productType: { typeId: "product-type", id: "" },
|
|
80
81
|
custom: createCustomFields(
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import type { DiscountGroupDraft } 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("DiscountGroup", () => {
|
|
9
|
+
test("Create discount group", async () => {
|
|
10
|
+
const draft: DiscountGroupDraft = {
|
|
11
|
+
key: "premium-discount-group",
|
|
12
|
+
name: {
|
|
13
|
+
"en-GB": "Premium Discount Group",
|
|
14
|
+
},
|
|
15
|
+
description: {
|
|
16
|
+
"en-GB": "A discount group for premium customers",
|
|
17
|
+
},
|
|
18
|
+
sortOrder: "0.5",
|
|
19
|
+
};
|
|
20
|
+
const response = await supertest(ctMock.app)
|
|
21
|
+
.post("/dummy/discount-groups")
|
|
22
|
+
.send(draft);
|
|
23
|
+
|
|
24
|
+
expect(response.status).toBe(201);
|
|
25
|
+
|
|
26
|
+
expect(response.body).toEqual({
|
|
27
|
+
createdAt: expect.anything(),
|
|
28
|
+
id: expect.anything(),
|
|
29
|
+
key: "premium-discount-group",
|
|
30
|
+
lastModifiedAt: expect.anything(),
|
|
31
|
+
name: {
|
|
32
|
+
"en-GB": "Premium Discount Group",
|
|
33
|
+
},
|
|
34
|
+
description: {
|
|
35
|
+
"en-GB": "A discount group for premium customers",
|
|
36
|
+
},
|
|
37
|
+
sortOrder: "0.5",
|
|
38
|
+
version: 1,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("Get discount group", async () => {
|
|
43
|
+
const draft: DiscountGroupDraft = {
|
|
44
|
+
key: "test-discount-group",
|
|
45
|
+
name: {
|
|
46
|
+
"en-GB": "Test Discount Group",
|
|
47
|
+
},
|
|
48
|
+
sortOrder: "0.1",
|
|
49
|
+
};
|
|
50
|
+
const createResponse = await supertest(ctMock.app)
|
|
51
|
+
.post("/dummy/discount-groups")
|
|
52
|
+
.send(draft);
|
|
53
|
+
|
|
54
|
+
expect(createResponse.status).toBe(201);
|
|
55
|
+
|
|
56
|
+
const response = await supertest(ctMock.app).get(
|
|
57
|
+
`/dummy/discount-groups/${createResponse.body.id}`,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
expect(response.status).toBe(200);
|
|
61
|
+
expect(response.body).toEqual(createResponse.body);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("Get discount group by key", async () => {
|
|
65
|
+
const draft: DiscountGroupDraft = {
|
|
66
|
+
key: "key-discount-group",
|
|
67
|
+
name: {
|
|
68
|
+
"en-GB": "Key Discount Group",
|
|
69
|
+
},
|
|
70
|
+
sortOrder: "0.2",
|
|
71
|
+
};
|
|
72
|
+
const createResponse = await supertest(ctMock.app)
|
|
73
|
+
.post("/dummy/discount-groups")
|
|
74
|
+
.send(draft);
|
|
75
|
+
|
|
76
|
+
expect(createResponse.status).toBe(201);
|
|
77
|
+
|
|
78
|
+
const response = await supertest(ctMock.app).get(
|
|
79
|
+
"/dummy/discount-groups/key=key-discount-group",
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(response.status).toBe(200);
|
|
83
|
+
expect(response.body).toEqual(createResponse.body);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("Query discount groups", async () => {
|
|
87
|
+
const draft: DiscountGroupDraft = {
|
|
88
|
+
key: "query-discount-group",
|
|
89
|
+
name: {
|
|
90
|
+
"en-GB": "Query Discount Group",
|
|
91
|
+
},
|
|
92
|
+
sortOrder: "0.3",
|
|
93
|
+
};
|
|
94
|
+
const createResponse = await supertest(ctMock.app)
|
|
95
|
+
.post("/dummy/discount-groups")
|
|
96
|
+
.send(draft);
|
|
97
|
+
|
|
98
|
+
expect(createResponse.status).toBe(201);
|
|
99
|
+
|
|
100
|
+
const response = await supertest(ctMock.app).get("/dummy/discount-groups");
|
|
101
|
+
|
|
102
|
+
expect(response.status).toBe(200);
|
|
103
|
+
expect(response.body.count).toBeGreaterThan(0);
|
|
104
|
+
expect(response.body.results).toContainEqual(createResponse.body);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("Update discount group - setName", async () => {
|
|
108
|
+
const draft: DiscountGroupDraft = {
|
|
109
|
+
key: "update-name-group",
|
|
110
|
+
name: {
|
|
111
|
+
"en-GB": "Original Name",
|
|
112
|
+
},
|
|
113
|
+
sortOrder: "0.4",
|
|
114
|
+
};
|
|
115
|
+
const createResponse = await supertest(ctMock.app)
|
|
116
|
+
.post("/dummy/discount-groups")
|
|
117
|
+
.send(draft);
|
|
118
|
+
|
|
119
|
+
expect(createResponse.status).toBe(201);
|
|
120
|
+
|
|
121
|
+
const updateResponse = await supertest(ctMock.app)
|
|
122
|
+
.post(`/dummy/discount-groups/${createResponse.body.id}`)
|
|
123
|
+
.send({
|
|
124
|
+
version: createResponse.body.version,
|
|
125
|
+
actions: [
|
|
126
|
+
{
|
|
127
|
+
action: "setName",
|
|
128
|
+
name: {
|
|
129
|
+
"en-GB": "Updated Name",
|
|
130
|
+
de: "Aktualisierter Name",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(updateResponse.status).toBe(200);
|
|
137
|
+
expect(updateResponse.body.name).toEqual({
|
|
138
|
+
"en-GB": "Updated Name",
|
|
139
|
+
de: "Aktualisierter Name",
|
|
140
|
+
});
|
|
141
|
+
expect(updateResponse.body.version).toBe(2);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("Update discount group - setDescription", async () => {
|
|
145
|
+
const draft: DiscountGroupDraft = {
|
|
146
|
+
key: "update-description-group",
|
|
147
|
+
name: {
|
|
148
|
+
"en-GB": "Test Group",
|
|
149
|
+
},
|
|
150
|
+
sortOrder: "0.5",
|
|
151
|
+
};
|
|
152
|
+
const createResponse = await supertest(ctMock.app)
|
|
153
|
+
.post("/dummy/discount-groups")
|
|
154
|
+
.send(draft);
|
|
155
|
+
|
|
156
|
+
expect(createResponse.status).toBe(201);
|
|
157
|
+
|
|
158
|
+
const updateResponse = await supertest(ctMock.app)
|
|
159
|
+
.post(`/dummy/discount-groups/${createResponse.body.id}`)
|
|
160
|
+
.send({
|
|
161
|
+
version: createResponse.body.version,
|
|
162
|
+
actions: [
|
|
163
|
+
{
|
|
164
|
+
action: "setDescription",
|
|
165
|
+
description: {
|
|
166
|
+
"en-GB": "New description",
|
|
167
|
+
de: "Neue Beschreibung",
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(updateResponse.status).toBe(200);
|
|
174
|
+
expect(updateResponse.body.description).toEqual({
|
|
175
|
+
"en-GB": "New description",
|
|
176
|
+
de: "Neue Beschreibung",
|
|
177
|
+
});
|
|
178
|
+
expect(updateResponse.body.version).toBe(2);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("Update discount group - setKey", async () => {
|
|
182
|
+
const draft: DiscountGroupDraft = {
|
|
183
|
+
key: "original-key",
|
|
184
|
+
name: {
|
|
185
|
+
"en-GB": "Test Group",
|
|
186
|
+
},
|
|
187
|
+
sortOrder: "0.6",
|
|
188
|
+
};
|
|
189
|
+
const createResponse = await supertest(ctMock.app)
|
|
190
|
+
.post("/dummy/discount-groups")
|
|
191
|
+
.send(draft);
|
|
192
|
+
|
|
193
|
+
expect(createResponse.status).toBe(201);
|
|
194
|
+
|
|
195
|
+
const updateResponse = await supertest(ctMock.app)
|
|
196
|
+
.post(`/dummy/discount-groups/${createResponse.body.id}`)
|
|
197
|
+
.send({
|
|
198
|
+
version: createResponse.body.version,
|
|
199
|
+
actions: [
|
|
200
|
+
{
|
|
201
|
+
action: "setKey",
|
|
202
|
+
key: "updated-key",
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
expect(updateResponse.status).toBe(200);
|
|
208
|
+
expect(updateResponse.body.key).toBe("updated-key");
|
|
209
|
+
expect(updateResponse.body.version).toBe(2);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("Update discount group - setSortOrder", async () => {
|
|
213
|
+
const draft: DiscountGroupDraft = {
|
|
214
|
+
key: "sort-order-group",
|
|
215
|
+
name: {
|
|
216
|
+
"en-GB": "Sort Order Group",
|
|
217
|
+
},
|
|
218
|
+
sortOrder: "0.1",
|
|
219
|
+
};
|
|
220
|
+
const createResponse = await supertest(ctMock.app)
|
|
221
|
+
.post("/dummy/discount-groups")
|
|
222
|
+
.send(draft);
|
|
223
|
+
|
|
224
|
+
expect(createResponse.status).toBe(201);
|
|
225
|
+
|
|
226
|
+
const updateResponse = await supertest(ctMock.app)
|
|
227
|
+
.post(`/dummy/discount-groups/${createResponse.body.id}`)
|
|
228
|
+
.send({
|
|
229
|
+
version: createResponse.body.version,
|
|
230
|
+
actions: [
|
|
231
|
+
{
|
|
232
|
+
action: "setSortOrder",
|
|
233
|
+
sortOrder: "0.9",
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
expect(updateResponse.status).toBe(200);
|
|
239
|
+
expect(updateResponse.body.sortOrder).toBe("0.9");
|
|
240
|
+
expect(updateResponse.body.version).toBe(2);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test("Delete discount group", async () => {
|
|
244
|
+
const draft: DiscountGroupDraft = {
|
|
245
|
+
key: "delete-group",
|
|
246
|
+
name: {
|
|
247
|
+
"en-GB": "Delete Group",
|
|
248
|
+
},
|
|
249
|
+
sortOrder: "0.7",
|
|
250
|
+
};
|
|
251
|
+
const createResponse = await supertest(ctMock.app)
|
|
252
|
+
.post("/dummy/discount-groups")
|
|
253
|
+
.send(draft);
|
|
254
|
+
|
|
255
|
+
expect(createResponse.status).toBe(201);
|
|
256
|
+
|
|
257
|
+
const deleteResponse = await supertest(ctMock.app)
|
|
258
|
+
.delete(`/dummy/discount-groups/${createResponse.body.id}`)
|
|
259
|
+
.query({ version: createResponse.body.version });
|
|
260
|
+
|
|
261
|
+
expect(deleteResponse.status).toBe(200);
|
|
262
|
+
expect(deleteResponse.body).toEqual(createResponse.body);
|
|
263
|
+
|
|
264
|
+
const getResponse = await supertest(ctMock.app).get(
|
|
265
|
+
`/dummy/discount-groups/${createResponse.body.id}`,
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
expect(getResponse.status).toBe(404);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Router } from "express";
|
|
2
|
+
import type { DiscountGroupRepository } from "../repositories/discount-group/index";
|
|
3
|
+
import AbstractService from "./abstract";
|
|
4
|
+
|
|
5
|
+
export class DiscountGroupService extends AbstractService {
|
|
6
|
+
public repository: DiscountGroupRepository;
|
|
7
|
+
|
|
8
|
+
constructor(parent: Router, repository: DiscountGroupRepository) {
|
|
9
|
+
super(parent);
|
|
10
|
+
this.repository = repository;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getBasePath() {
|
|
14
|
+
return "discount-groups";
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { CustomObjectService } from "./custom-object";
|
|
|
11
11
|
import { CustomerService } from "./customer";
|
|
12
12
|
import { CustomerGroupService } from "./customer-group";
|
|
13
13
|
import { DiscountCodeService } from "./discount-code";
|
|
14
|
+
import { DiscountGroupService } from "./discount-group";
|
|
14
15
|
import { ExtensionServices } from "./extension";
|
|
15
16
|
import { InventoryEntryService } from "./inventory-entry";
|
|
16
17
|
import { MyBusinessUnitService } from "./my-business-unit";
|
|
@@ -29,6 +30,8 @@ import { ProductTypeService } from "./product-type";
|
|
|
29
30
|
import { QuoteService } from "./quote";
|
|
30
31
|
import { QuoteRequestService } from "./quote-request";
|
|
31
32
|
import { StagedQuoteService } from "./quote-staged";
|
|
33
|
+
import { RecurrencePolicyService } from "./recurrence-policy";
|
|
34
|
+
import { RecurringOrderService } from "./recurring-order";
|
|
32
35
|
import { ReviewService } from "./reviews";
|
|
33
36
|
import { ShippingMethodService } from "./shipping-method";
|
|
34
37
|
import { ShoppingListService } from "./shopping-list";
|
|
@@ -54,6 +57,7 @@ export const createServices = (
|
|
|
54
57
|
channel: new ChannelService(router, repos.channel),
|
|
55
58
|
"customer-group": new CustomerGroupService(router, repos["customer-group"]),
|
|
56
59
|
"discount-code": new DiscountCodeService(router, repos["discount-code"]),
|
|
60
|
+
"discount-group": new DiscountGroupService(router, repos["discount-group"]),
|
|
57
61
|
extension: new ExtensionServices(router, repos.extension),
|
|
58
62
|
"inventory-entry": new InventoryEntryService(
|
|
59
63
|
router,
|
|
@@ -98,6 +102,14 @@ export const createServices = (
|
|
|
98
102
|
),
|
|
99
103
|
quotes: new QuoteService(router, repos.quote),
|
|
100
104
|
"quote-request": new QuoteRequestService(router, repos["quote-request"]),
|
|
105
|
+
"recurrence-policy": new RecurrencePolicyService(
|
|
106
|
+
router,
|
|
107
|
+
repos["recurrence-policy"],
|
|
108
|
+
),
|
|
109
|
+
"recurring-order": new RecurringOrderService(
|
|
110
|
+
router,
|
|
111
|
+
repos["recurring-order"],
|
|
112
|
+
),
|
|
101
113
|
reviews: new ReviewService(router, repos.review),
|
|
102
114
|
"shopping-list": new ShoppingListService(router, repos["shopping-list"]),
|
|
103
115
|
"staged-quote": new StagedQuoteService(router, repos["staged-quote"]),
|