@labdigital/commercetools-mock 2.13.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +112 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +112 -37
- package/dist/index.js.map +1 -1
- package/package.json +31 -31
- package/src/repositories/cart.ts +2 -2
- package/src/repositories/customer.ts +72 -0
- package/src/repositories/order.ts +1 -1
- package/src/repositories/payment.ts +92 -47
- package/src/repositories/product.ts +5 -5
- package/src/repositories/review.ts +2 -2
- package/src/repositories/shopping-list.ts +1 -1
- package/src/services/customer.test.ts +154 -0
- package/src/services/customer.ts +1 -1
- package/src/services/my-customer.test.ts +32 -2
- package/src/services/my-customer.ts +32 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
3
|
"author": "Michael van Tellingen",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.14.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -35,45 +35,45 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"basic-auth": "^2.0.1",
|
|
37
37
|
"body-parser": "^1.20.2",
|
|
38
|
-
"deep-equal": "^2.2.
|
|
38
|
+
"deep-equal": "^2.2.3",
|
|
39
39
|
"express": "^4.18.2",
|
|
40
40
|
"light-my-request": "^5.11.0",
|
|
41
41
|
"lodash.isequal": "^4.5.0",
|
|
42
42
|
"morgan": "^1.10.0",
|
|
43
|
-
"msw": "^2.
|
|
44
|
-
"uuid": "^9.0.
|
|
43
|
+
"msw": "^2.1.2",
|
|
44
|
+
"uuid": "^9.0.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@changesets/changelog-github": "^0.
|
|
48
|
-
"@changesets/cli": "^2.
|
|
49
|
-
"@commercetools/platform-sdk": "
|
|
50
|
-
"@types/basic-auth": "^1.1.
|
|
51
|
-
"@types/body-parser": "^1.19.
|
|
52
|
-
"@types/deep-equal": "^1.0.
|
|
53
|
-
"@types/express": "^4.17.
|
|
54
|
-
"@types/express-serve-static-core": "^4.17.
|
|
55
|
-
"@types/lodash.isequal": "^4.5.
|
|
56
|
-
"@types/morgan": "^1.9.
|
|
57
|
-
"@types/node": "
|
|
58
|
-
"@types/qs": "^6.9.
|
|
59
|
-
"@types/supertest": "^
|
|
60
|
-
"@types/uuid": "^9.0.
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
62
|
-
"@typescript-eslint/parser": "^6.
|
|
63
|
-
"@vitest/coverage-v8": "^
|
|
64
|
-
"esbuild": "^0.
|
|
65
|
-
"eslint": "^8.
|
|
47
|
+
"@changesets/changelog-github": "^0.5.0",
|
|
48
|
+
"@changesets/cli": "^2.27.1",
|
|
49
|
+
"@commercetools/platform-sdk": "7.2.0-alpha.2",
|
|
50
|
+
"@types/basic-auth": "^1.1.7",
|
|
51
|
+
"@types/body-parser": "^1.19.5",
|
|
52
|
+
"@types/deep-equal": "^1.0.4",
|
|
53
|
+
"@types/express": "^4.17.21",
|
|
54
|
+
"@types/express-serve-static-core": "^4.17.41",
|
|
55
|
+
"@types/lodash.isequal": "^4.5.8",
|
|
56
|
+
"@types/morgan": "^1.9.9",
|
|
57
|
+
"@types/node": "^20.11.5",
|
|
58
|
+
"@types/qs": "^6.9.11",
|
|
59
|
+
"@types/supertest": "^6.0.2",
|
|
60
|
+
"@types/uuid": "^9.0.7",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
62
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
63
|
+
"@vitest/coverage-v8": "^1.2.1",
|
|
64
|
+
"esbuild": "^0.19.11",
|
|
65
|
+
"eslint": "^8.56.0",
|
|
66
66
|
"eslint-plugin-unused-imports": "^3.0.0",
|
|
67
|
-
"got": "^
|
|
67
|
+
"got": "^14.0.0",
|
|
68
68
|
"husky": "^8.0.3",
|
|
69
|
-
"prettier": "^3.
|
|
70
|
-
"supertest": "^6.3.
|
|
69
|
+
"prettier": "^3.2.4",
|
|
70
|
+
"supertest": "^6.3.4",
|
|
71
71
|
"timekeeper": "^2.3.1",
|
|
72
|
-
"ts-node": "^10.9.
|
|
73
|
-
"tslib": "^2.6.
|
|
74
|
-
"tsup": "^
|
|
75
|
-
"typescript": "^5.
|
|
76
|
-
"vitest": "^
|
|
72
|
+
"ts-node": "^10.9.2",
|
|
73
|
+
"tslib": "^2.6.2",
|
|
74
|
+
"tsup": "^8.0.1",
|
|
75
|
+
"typescript": "^5.3.3",
|
|
76
|
+
"vitest": "^1.2.1"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"start": "tsup src/server.ts --watch --onSuccess 'node dist/server.js'",
|
package/src/repositories/cart.ts
CHANGED
|
@@ -411,7 +411,7 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
411
411
|
? this._storage.getByResourceIdentifier<'tax-category'>(
|
|
412
412
|
context.projectKey,
|
|
413
413
|
taxCategory
|
|
414
|
-
|
|
414
|
+
)
|
|
415
415
|
: undefined
|
|
416
416
|
|
|
417
417
|
resource.shippingInfo = {
|
|
@@ -425,7 +425,7 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
425
425
|
? {
|
|
426
426
|
typeId: 'tax-category',
|
|
427
427
|
id: tax?.id,
|
|
428
|
-
|
|
428
|
+
}
|
|
429
429
|
: undefined,
|
|
430
430
|
shippingMethodState: 'MatchesCart',
|
|
431
431
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Customer,
|
|
3
|
+
CustomerChangeAddressAction,
|
|
3
4
|
CustomerChangeEmailAction,
|
|
4
5
|
CustomerDraft,
|
|
5
6
|
CustomerSetAuthenticationModeAction,
|
|
7
|
+
CustomerSetCompanyNameAction,
|
|
6
8
|
CustomerSetCustomFieldAction,
|
|
9
|
+
CustomerSetFirstNameAction,
|
|
10
|
+
CustomerSetLastNameAction,
|
|
11
|
+
CustomerSetVatIdAction,
|
|
7
12
|
DuplicateFieldError,
|
|
8
13
|
InvalidInputError,
|
|
9
14
|
InvalidJsonInputError,
|
|
@@ -16,6 +21,7 @@ import {
|
|
|
16
21
|
type RepositoryContext,
|
|
17
22
|
} from './abstract.js'
|
|
18
23
|
import { hashPassword } from '../lib/password.js'
|
|
24
|
+
import { createAddress } from './helpers.js'
|
|
19
25
|
|
|
20
26
|
export class CustomerRepository extends AbstractResourceRepository<'customer'> {
|
|
21
27
|
getTypeId() {
|
|
@@ -97,6 +103,72 @@ export class CustomerRepository extends AbstractResourceRepository<'customer'> {
|
|
|
97
103
|
) => {
|
|
98
104
|
resource.email = email
|
|
99
105
|
},
|
|
106
|
+
setFirstName: (
|
|
107
|
+
_context: RepositoryContext,
|
|
108
|
+
resource: Writable<Customer>,
|
|
109
|
+
{ firstName }: CustomerSetFirstNameAction
|
|
110
|
+
) => {
|
|
111
|
+
resource.firstName = firstName
|
|
112
|
+
},
|
|
113
|
+
setLastName: (
|
|
114
|
+
_context: RepositoryContext,
|
|
115
|
+
resource: Writable<Customer>,
|
|
116
|
+
{ lastName }: CustomerSetLastNameAction
|
|
117
|
+
) => {
|
|
118
|
+
resource.lastName = lastName
|
|
119
|
+
},
|
|
120
|
+
setCompanyName: (
|
|
121
|
+
_context: RepositoryContext,
|
|
122
|
+
resource: Writable<Customer>,
|
|
123
|
+
{ companyName }: CustomerSetCompanyNameAction
|
|
124
|
+
) => {
|
|
125
|
+
resource.companyName = companyName
|
|
126
|
+
},
|
|
127
|
+
setVatId: (
|
|
128
|
+
_context: RepositoryContext,
|
|
129
|
+
resource: Writable<Customer>,
|
|
130
|
+
{ vatId }: CustomerSetVatIdAction
|
|
131
|
+
) => {
|
|
132
|
+
resource.vatId = vatId
|
|
133
|
+
},
|
|
134
|
+
changeAddress: (
|
|
135
|
+
context: RepositoryContext,
|
|
136
|
+
resource: Writable<Customer>,
|
|
137
|
+
{ addressId, addressKey, address }: CustomerChangeAddressAction
|
|
138
|
+
) => {
|
|
139
|
+
const oldAddressIndex = resource.addresses.findIndex((a) => {
|
|
140
|
+
if (a.id != undefined && addressId != undefined && a.id === addressId) {
|
|
141
|
+
return true
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
a.key != undefined && addressKey != undefined && a.key === addressKey
|
|
146
|
+
)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
if (oldAddressIndex === -1) {
|
|
150
|
+
throw new CommercetoolsError<InvalidInputError>(
|
|
151
|
+
{
|
|
152
|
+
code: 'InvalidInput',
|
|
153
|
+
message: `Address with id '${addressId}' or key '${addressKey}' not found.`,
|
|
154
|
+
},
|
|
155
|
+
400
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const newAddress = createAddress(
|
|
160
|
+
address,
|
|
161
|
+
context.projectKey,
|
|
162
|
+
this._storage
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
if (newAddress) {
|
|
166
|
+
resource.addresses[oldAddressIndex] = {
|
|
167
|
+
id: addressId,
|
|
168
|
+
...newAddress,
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
100
172
|
setAuthenticationMode: (
|
|
101
173
|
_context: RepositoryContext,
|
|
102
174
|
resource: Writable<Customer>,
|
|
@@ -5,6 +5,13 @@ import type {
|
|
|
5
5
|
PaymentDraft,
|
|
6
6
|
PaymentSetCustomFieldAction,
|
|
7
7
|
PaymentSetCustomTypeAction,
|
|
8
|
+
PaymentSetInterfaceIdAction,
|
|
9
|
+
PaymentSetKeyAction,
|
|
10
|
+
PaymentSetMethodInfoInterfaceAction,
|
|
11
|
+
PaymentSetMethodInfoMethodAction,
|
|
12
|
+
PaymentSetMethodInfoNameAction,
|
|
13
|
+
PaymentSetStatusInterfaceCodeAction,
|
|
14
|
+
PaymentSetStatusInterfaceTextAction,
|
|
8
15
|
PaymentTransitionStateAction,
|
|
9
16
|
State,
|
|
10
17
|
StateReference,
|
|
@@ -39,9 +46,9 @@ export class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
39
46
|
draft.paymentStatus.state,
|
|
40
47
|
context.projectKey,
|
|
41
48
|
this._storage
|
|
42
|
-
|
|
49
|
+
)
|
|
43
50
|
: undefined,
|
|
44
|
-
|
|
51
|
+
}
|
|
45
52
|
: {},
|
|
46
53
|
transactions: (draft.transactions || []).map((t) =>
|
|
47
54
|
this.transactionFromTransactionDraft(t, context)
|
|
@@ -73,6 +80,50 @@ export class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
73
80
|
})
|
|
74
81
|
|
|
75
82
|
actions = {
|
|
83
|
+
addTransaction: (
|
|
84
|
+
context: RepositoryContext,
|
|
85
|
+
resource: Writable<Payment>,
|
|
86
|
+
{ transaction }: PaymentAddTransactionAction
|
|
87
|
+
) => {
|
|
88
|
+
resource.transactions = [
|
|
89
|
+
...resource.transactions,
|
|
90
|
+
this.transactionFromTransactionDraft(transaction, context),
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
changeTransactionState: (
|
|
94
|
+
_context: RepositoryContext,
|
|
95
|
+
resource: Writable<Payment>,
|
|
96
|
+
{ transactionId, state }: PaymentChangeTransactionStateAction
|
|
97
|
+
) => {
|
|
98
|
+
const index = resource.transactions.findIndex(
|
|
99
|
+
(e: Transaction) => e.id === transactionId
|
|
100
|
+
)
|
|
101
|
+
const updatedTransaction: Transaction = {
|
|
102
|
+
...resource.transactions[index],
|
|
103
|
+
state,
|
|
104
|
+
}
|
|
105
|
+
resource.transactions[index] = updatedTransaction
|
|
106
|
+
},
|
|
107
|
+
transitionState: (
|
|
108
|
+
context: RepositoryContext,
|
|
109
|
+
resource: Writable<Payment>,
|
|
110
|
+
{ state }: PaymentTransitionStateAction
|
|
111
|
+
) => {
|
|
112
|
+
const stateObj = this._storage.getByResourceIdentifier(
|
|
113
|
+
context.projectKey,
|
|
114
|
+
state
|
|
115
|
+
) as State | null
|
|
116
|
+
|
|
117
|
+
if (!stateObj) {
|
|
118
|
+
throw new Error(`State ${state} not found`)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
resource.paymentStatus.state = {
|
|
122
|
+
typeId: 'state',
|
|
123
|
+
id: stateObj.id,
|
|
124
|
+
obj: stateObj,
|
|
125
|
+
}
|
|
126
|
+
},
|
|
76
127
|
setCustomField: (
|
|
77
128
|
context: RepositoryContext,
|
|
78
129
|
resource: Payment,
|
|
@@ -109,66 +160,60 @@ export class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
109
160
|
}
|
|
110
161
|
}
|
|
111
162
|
},
|
|
112
|
-
|
|
113
|
-
|
|
163
|
+
setKey: (
|
|
164
|
+
_context: RepositoryContext,
|
|
114
165
|
resource: Writable<Payment>,
|
|
115
|
-
{
|
|
166
|
+
{ key }: PaymentSetKeyAction
|
|
116
167
|
) => {
|
|
117
|
-
resource.
|
|
118
|
-
...resource.transactions,
|
|
119
|
-
this.transactionFromTransactionDraft(transaction, context),
|
|
120
|
-
]
|
|
168
|
+
resource.key = key
|
|
121
169
|
},
|
|
122
|
-
|
|
170
|
+
setStatusInterfaceCode: (
|
|
123
171
|
_context: RepositoryContext,
|
|
124
172
|
resource: Writable<Payment>,
|
|
125
|
-
{
|
|
173
|
+
{ interfaceCode }: PaymentSetStatusInterfaceCodeAction
|
|
126
174
|
) => {
|
|
127
|
-
|
|
128
|
-
(e: Transaction) => e.id === transactionId
|
|
129
|
-
)
|
|
130
|
-
const updatedTransaction: Transaction = {
|
|
131
|
-
...resource.transactions[index],
|
|
132
|
-
state,
|
|
133
|
-
}
|
|
134
|
-
resource.transactions[index] = updatedTransaction
|
|
175
|
+
resource.paymentStatus.interfaceCode = interfaceCode
|
|
135
176
|
},
|
|
136
|
-
|
|
137
|
-
|
|
177
|
+
setStatusInterfaceText: (
|
|
178
|
+
_context: RepositoryContext,
|
|
138
179
|
resource: Writable<Payment>,
|
|
139
|
-
{
|
|
180
|
+
{ interfaceText }: PaymentSetStatusInterfaceTextAction
|
|
140
181
|
) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
182
|
+
resource.paymentStatus.interfaceText = interfaceText
|
|
183
|
+
},
|
|
184
|
+
setMethodInfoName: (
|
|
185
|
+
_context: RepositoryContext,
|
|
186
|
+
resource: Writable<Payment>,
|
|
187
|
+
{ name }: PaymentSetMethodInfoNameAction
|
|
188
|
+
) => {
|
|
189
|
+
resource.paymentMethodInfo.name = name
|
|
190
|
+
},
|
|
191
|
+
setMethodInfoMethod: (
|
|
192
|
+
_context: RepositoryContext,
|
|
193
|
+
resource: Writable<Payment>,
|
|
194
|
+
{ method }: PaymentSetMethodInfoMethodAction
|
|
195
|
+
) => {
|
|
196
|
+
resource.paymentMethodInfo.method = method
|
|
197
|
+
},
|
|
198
|
+
setMethodInfoInterface: (
|
|
199
|
+
_context: RepositoryContext,
|
|
200
|
+
resource: Writable<Payment>,
|
|
201
|
+
args: PaymentSetMethodInfoInterfaceAction
|
|
202
|
+
) => {
|
|
203
|
+
resource.paymentMethodInfo.paymentInterface = args.interface
|
|
204
|
+
},
|
|
205
|
+
setInterfaceId: (
|
|
206
|
+
_context: RepositoryContext,
|
|
207
|
+
resource: Writable<Payment>,
|
|
208
|
+
{ interfaceId }: PaymentSetInterfaceIdAction
|
|
209
|
+
) => {
|
|
210
|
+
resource.interfaceId = interfaceId
|
|
155
211
|
},
|
|
156
212
|
// addInterfaceInteraction: () => {},
|
|
157
213
|
// changeAmountPlanned: () => {},
|
|
158
214
|
// changeTransactionInteractionId: () => {},
|
|
159
215
|
// changeTransactionTimestamp: () => {},
|
|
160
|
-
// setAmountPaid: () => {},
|
|
161
|
-
// setAmountRefunded: () => {},
|
|
162
216
|
// setAnonymousId: () => {},
|
|
163
|
-
// setAuthorization: () => {},
|
|
164
217
|
// setCustomer: () => {},
|
|
165
|
-
// setExternalId: () => {},
|
|
166
|
-
// setInterfaceId: () => {},
|
|
167
|
-
// setKey: () => {},
|
|
168
|
-
// setMethodInfoInterface: () => {},
|
|
169
|
-
// setMethodInfoMethod: () => {},
|
|
170
|
-
// setMethodInfoName: () => {},
|
|
171
|
-
// setStatusInterfaceCode: () => {},
|
|
172
|
-
// setStatusInterfaceText: () => {},
|
|
173
218
|
}
|
|
174
219
|
}
|
|
@@ -184,7 +184,7 @@ export class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
|
184
184
|
draft.channel,
|
|
185
185
|
context.projectKey,
|
|
186
186
|
this._storage
|
|
187
|
-
|
|
187
|
+
)
|
|
188
188
|
: undefined,
|
|
189
189
|
}
|
|
190
190
|
}
|
|
@@ -587,8 +587,8 @@ export class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
|
587
587
|
) => {
|
|
588
588
|
const changeVariantPrice = (data: Writable<ProductData>) => {
|
|
589
589
|
const allVariants = [data.masterVariant, ...(data.variants ?? [])]
|
|
590
|
-
const priceVariant = allVariants.find(
|
|
591
|
-
|
|
590
|
+
const priceVariant = allVariants.find((variant) =>
|
|
591
|
+
variant.prices?.some((x) => x.id === priceId)
|
|
592
592
|
)
|
|
593
593
|
if (!priceVariant) {
|
|
594
594
|
throw new Error(
|
|
@@ -645,8 +645,8 @@ export class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
|
645
645
|
) => {
|
|
646
646
|
const removeVariantPrice = (data: Writable<ProductData>) => {
|
|
647
647
|
const allVariants = [data.masterVariant, ...(data.variants ?? [])]
|
|
648
|
-
const priceVariant = allVariants.find(
|
|
649
|
-
|
|
648
|
+
const priceVariant = allVariants.find((variant) =>
|
|
649
|
+
variant.prices?.some((x) => x.id === priceId)
|
|
650
650
|
)
|
|
651
651
|
if (!priceVariant) {
|
|
652
652
|
throw new Error(
|
|
@@ -35,12 +35,12 @@ export class ReviewRepository extends AbstractResourceRepository<'review'> {
|
|
|
35
35
|
draft.state,
|
|
36
36
|
context.projectKey,
|
|
37
37
|
this._storage
|
|
38
|
-
|
|
38
|
+
)
|
|
39
39
|
: undefined,
|
|
40
40
|
target: draft.target
|
|
41
41
|
? getReferenceFromResourceIdentifier<
|
|
42
42
|
ProductReference | ChannelReference
|
|
43
|
-
|
|
43
|
+
>(draft.target, context.projectKey, this._storage)
|
|
44
44
|
: undefined,
|
|
45
45
|
includedInStatistics: false,
|
|
46
46
|
custom: createCustomFields(
|
|
@@ -48,7 +48,7 @@ export class ShoppingListRepository extends AbstractResourceRepository<'shopping
|
|
|
48
48
|
draft.customer,
|
|
49
49
|
context.projectKey,
|
|
50
50
|
this._storage
|
|
51
|
-
|
|
51
|
+
)
|
|
52
52
|
: undefined,
|
|
53
53
|
store: draft.store
|
|
54
54
|
? getStoreKeyReference(draft.store, context.projectKey, this._storage)
|
|
@@ -176,4 +176,158 @@ describe('Customer Update Actions', () => {
|
|
|
176
176
|
expect(response.body.version).toBe(2)
|
|
177
177
|
expect(response.body.custom.fields.isValidCouponCode).toBe(false)
|
|
178
178
|
})
|
|
179
|
+
|
|
180
|
+
test('setFirstName', async () => {
|
|
181
|
+
assert(customer, 'customer not created')
|
|
182
|
+
|
|
183
|
+
customer = {
|
|
184
|
+
...customer,
|
|
185
|
+
firstName: 'John',
|
|
186
|
+
}
|
|
187
|
+
ctMock.project('dummy').add('customer', customer)
|
|
188
|
+
|
|
189
|
+
const response = await supertest(ctMock.app)
|
|
190
|
+
.post(`/dummy/customers/${customer.id}`)
|
|
191
|
+
.send({
|
|
192
|
+
version: 1,
|
|
193
|
+
actions: [{ action: 'setFirstName', firstName: 'Mary' }],
|
|
194
|
+
})
|
|
195
|
+
expect(response.status).toBe(200)
|
|
196
|
+
expect(response.body.version).toBe(2)
|
|
197
|
+
expect(response.body.firstName).toBe('Mary')
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
test('setLastName', async () => {
|
|
201
|
+
assert(customer, 'customer not created')
|
|
202
|
+
|
|
203
|
+
customer = {
|
|
204
|
+
...customer,
|
|
205
|
+
lastName: 'Doe',
|
|
206
|
+
}
|
|
207
|
+
ctMock.project('dummy').add('customer', customer)
|
|
208
|
+
|
|
209
|
+
const response = await supertest(ctMock.app)
|
|
210
|
+
.post(`/dummy/customers/${customer.id}`)
|
|
211
|
+
.send({
|
|
212
|
+
version: 1,
|
|
213
|
+
actions: [{ action: 'setLastName', lastName: 'Smith' }],
|
|
214
|
+
})
|
|
215
|
+
expect(response.status).toBe(200)
|
|
216
|
+
expect(response.body.version).toBe(2)
|
|
217
|
+
expect(response.body.lastName).toBe('Smith')
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('setCompanyName', async () => {
|
|
221
|
+
assert(customer, 'customer not created')
|
|
222
|
+
|
|
223
|
+
customer = {
|
|
224
|
+
...customer,
|
|
225
|
+
companyName: 'Acme',
|
|
226
|
+
}
|
|
227
|
+
ctMock.project('dummy').add('customer', customer)
|
|
228
|
+
|
|
229
|
+
const response = await supertest(ctMock.app)
|
|
230
|
+
.post(`/dummy/customers/${customer.id}`)
|
|
231
|
+
.send({
|
|
232
|
+
version: 1,
|
|
233
|
+
actions: [{ action: 'setCompanyName', companyName: 'Acme Inc.' }],
|
|
234
|
+
})
|
|
235
|
+
expect(response.status).toBe(200)
|
|
236
|
+
expect(response.body.version).toBe(2)
|
|
237
|
+
expect(response.body.companyName).toBe('Acme Inc.')
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
test('setVatId', async () => {
|
|
241
|
+
assert(customer, 'customer not created')
|
|
242
|
+
|
|
243
|
+
customer = {
|
|
244
|
+
...customer,
|
|
245
|
+
vatId: '123456789',
|
|
246
|
+
}
|
|
247
|
+
ctMock.project('dummy').add('customer', customer)
|
|
248
|
+
|
|
249
|
+
const response = await supertest(ctMock.app)
|
|
250
|
+
.post(`/dummy/customers/${customer.id}`)
|
|
251
|
+
.send({
|
|
252
|
+
version: 1,
|
|
253
|
+
actions: [{ action: 'setVatId', vatId: 'ABCD' }],
|
|
254
|
+
})
|
|
255
|
+
expect(response.status).toBe(200)
|
|
256
|
+
expect(response.body.version).toBe(2)
|
|
257
|
+
expect(response.body.vatId).toBe('ABCD')
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
test('changeAddress', async () => {
|
|
261
|
+
assert(customer, 'customer not created')
|
|
262
|
+
|
|
263
|
+
customer = {
|
|
264
|
+
...customer,
|
|
265
|
+
addresses: [
|
|
266
|
+
{
|
|
267
|
+
...getBaseResourceProperties(),
|
|
268
|
+
id: 'other-address-uid',
|
|
269
|
+
firstName: 'Foo',
|
|
270
|
+
lastName: 'Bar',
|
|
271
|
+
streetName: 'Baz Street',
|
|
272
|
+
streetNumber: '99',
|
|
273
|
+
postalCode: '12ab',
|
|
274
|
+
country: 'NL',
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
...getBaseResourceProperties(),
|
|
278
|
+
id: 'address-uuid',
|
|
279
|
+
firstName: 'John',
|
|
280
|
+
lastName: 'Doe',
|
|
281
|
+
streetName: 'Main Street',
|
|
282
|
+
streetNumber: '1',
|
|
283
|
+
postalCode: '12345',
|
|
284
|
+
country: 'DE',
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
defaultBillingAddressId: 'address-uuid',
|
|
288
|
+
}
|
|
289
|
+
ctMock.project('dummy').add('customer', customer)
|
|
290
|
+
|
|
291
|
+
const response = await supertest(ctMock.app)
|
|
292
|
+
.post(`/dummy/customers/${customer.id}`)
|
|
293
|
+
.send({
|
|
294
|
+
version: 1,
|
|
295
|
+
actions: [
|
|
296
|
+
{
|
|
297
|
+
action: 'changeAddress',
|
|
298
|
+
addressId: 'address-uuid',
|
|
299
|
+
address: {
|
|
300
|
+
firstName: 'Marie',
|
|
301
|
+
lastName: 'Johnson',
|
|
302
|
+
streetName: 'Last Street',
|
|
303
|
+
streetNumber: '2',
|
|
304
|
+
postalCode: 'ABCS',
|
|
305
|
+
country: 'US',
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
})
|
|
310
|
+
expect(response.status).toBe(200)
|
|
311
|
+
expect(response.body.version).toBe(2)
|
|
312
|
+
expect(response.body.addresses).toMatchObject([
|
|
313
|
+
{
|
|
314
|
+
id: 'other-address-uid',
|
|
315
|
+
firstName: 'Foo',
|
|
316
|
+
lastName: 'Bar',
|
|
317
|
+
streetName: 'Baz Street',
|
|
318
|
+
streetNumber: '99',
|
|
319
|
+
postalCode: '12ab',
|
|
320
|
+
country: 'NL',
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
id: 'address-uuid',
|
|
324
|
+
firstName: 'Marie',
|
|
325
|
+
lastName: 'Johnson',
|
|
326
|
+
streetName: 'Last Street',
|
|
327
|
+
streetNumber: '2',
|
|
328
|
+
postalCode: 'ABCS',
|
|
329
|
+
country: 'US',
|
|
330
|
+
},
|
|
331
|
+
])
|
|
332
|
+
})
|
|
179
333
|
})
|
package/src/services/customer.ts
CHANGED
|
@@ -25,7 +25,7 @@ export class CustomerService extends AbstractService {
|
|
|
25
25
|
// @ts-ignore
|
|
26
26
|
const ttlMinutes: number = request.params.ttlMinutes
|
|
27
27
|
? // @ts-ignore
|
|
28
|
-
|
|
28
|
+
+request.params.ttlMinutes
|
|
29
29
|
: 34560
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
31
|
const { version, ...rest } = getBaseResourceProperties()
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
CustomerChangePassword,
|
|
3
|
+
MyCustomerDraft,
|
|
4
|
+
} from '@commercetools/platform-sdk'
|
|
2
5
|
import supertest from 'supertest'
|
|
3
6
|
import { afterEach, beforeEach, describe, expect, test } from 'vitest'
|
|
4
|
-
import { CommercetoolsMock } from '../index.js'
|
|
7
|
+
import { CommercetoolsMock, getBaseResourceProperties } from '../index.js'
|
|
8
|
+
import { hashPassword } from '../lib/password.js'
|
|
5
9
|
|
|
6
10
|
const ctMock = new CommercetoolsMock()
|
|
7
11
|
|
|
@@ -120,6 +124,32 @@ describe('/me', () => {
|
|
|
120
124
|
expect(newResponse.status).toBe(404)
|
|
121
125
|
})
|
|
122
126
|
|
|
127
|
+
test('Change my password', async () => {
|
|
128
|
+
const customer = {
|
|
129
|
+
...getBaseResourceProperties(),
|
|
130
|
+
id: 'customer-uuid',
|
|
131
|
+
email: 'user@example.com',
|
|
132
|
+
password: hashPassword('p4ssw0rd'),
|
|
133
|
+
addresses: [],
|
|
134
|
+
isEmailVerified: true,
|
|
135
|
+
authenticationMode: 'Password', //default in Commercetools
|
|
136
|
+
version: 1,
|
|
137
|
+
}
|
|
138
|
+
ctMock.project('dummy').add('customer', customer)
|
|
139
|
+
|
|
140
|
+
const draft: CustomerChangePassword = {
|
|
141
|
+
id: customer.id,
|
|
142
|
+
version: customer.version,
|
|
143
|
+
newPassword: 'newP4ssw0rd',
|
|
144
|
+
currentPassword: 'p4ssw0rd',
|
|
145
|
+
}
|
|
146
|
+
const response = await supertest(ctMock.app)
|
|
147
|
+
.post('/dummy/me/password')
|
|
148
|
+
.send(draft)
|
|
149
|
+
|
|
150
|
+
expect(response.status).toBe(200)
|
|
151
|
+
})
|
|
152
|
+
|
|
123
153
|
test('setCustomField', async () => {
|
|
124
154
|
const response = await supertest(ctMock.app)
|
|
125
155
|
.post(`/dummy/me`)
|