@payloadcms/plugin-ecommerce 4.0.0-internal.c2b57ce → 4.0.0-internal.c6494b5
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/LICENSE.md +1 -1
- package/README.md +6 -0
- package/dist/collections/addresses/createAddressesCollection.d.ts.map +1 -1
- package/dist/collections/addresses/createAddressesCollection.js +1 -0
- package/dist/collections/addresses/createAddressesCollection.js.map +1 -1
- package/dist/collections/addresses/hooks/beforeChange.d.ts.map +1 -1
- package/dist/collections/addresses/hooks/beforeChange.js +3 -2
- package/dist/collections/addresses/hooks/beforeChange.js.map +1 -1
- package/dist/collections/carts/beforeChange.d.ts.map +1 -1
- package/dist/collections/carts/beforeChange.js +2 -0
- package/dist/collections/carts/beforeChange.js.map +1 -1
- package/dist/collections/carts/createCartsCollection.d.ts.map +1 -1
- package/dist/collections/carts/createCartsCollection.js +1 -0
- package/dist/collections/carts/createCartsCollection.js.map +1 -1
- package/dist/collections/carts/endpoints/addItem.d.ts.map +1 -1
- package/dist/collections/carts/endpoints/clearCart.d.ts.map +1 -1
- package/dist/collections/carts/endpoints/mergeCart.d.ts.map +1 -1
- package/dist/collections/carts/endpoints/removeItem.d.ts.map +1 -1
- package/dist/collections/carts/endpoints/updateItem.d.ts.map +1 -1
- package/dist/collections/carts/hasCartSecretAccess.d.ts.map +1 -1
- package/dist/collections/carts/operations/addItem.d.ts.map +1 -1
- package/dist/collections/carts/operations/clearCart.d.ts.map +1 -1
- package/dist/collections/carts/operations/createRequestWithSecret.d.ts.map +1 -1
- package/dist/collections/carts/operations/mergeCart.d.ts.map +1 -1
- package/dist/collections/carts/operations/removeItem.d.ts.map +1 -1
- package/dist/collections/carts/operations/updateItem.d.ts.map +1 -1
- package/dist/collections/orders/createOrdersCollection.d.ts.map +1 -1
- package/dist/collections/orders/createOrdersCollection.js +1 -0
- package/dist/collections/orders/createOrdersCollection.js.map +1 -1
- package/dist/collections/products/createProductsCollection.d.ts.map +1 -1
- package/dist/collections/products/createProductsCollection.js +1 -0
- package/dist/collections/products/createProductsCollection.js.map +1 -1
- package/dist/collections/transactions/createTransactionsCollection.d.ts.map +1 -1
- package/dist/collections/transactions/createTransactionsCollection.js +1 -0
- package/dist/collections/transactions/createTransactionsCollection.js.map +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.d.ts.map +1 -1
- package/dist/collections/variants/createVariantOptionsCollection.js +1 -0
- package/dist/collections/variants/createVariantOptionsCollection.js.map +1 -1
- package/dist/collections/variants/createVariantTypesCollection.d.ts.map +1 -1
- package/dist/collections/variants/createVariantTypesCollection.js +1 -0
- package/dist/collections/variants/createVariantTypesCollection.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js +2 -0
- package/dist/collections/variants/createVariantsCollection/hooks/beforeChange.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js +1 -0
- package/dist/collections/variants/createVariantsCollection/hooks/validateOptions.js.map +1 -1
- package/dist/collections/variants/createVariantsCollection/index.d.ts.map +1 -1
- package/dist/collections/variants/createVariantsCollection/index.js +1 -0
- package/dist/collections/variants/createVariantsCollection/index.js.map +1 -1
- package/dist/endpoints/confirmOrder.d.ts.map +1 -1
- package/dist/endpoints/confirmOrder.js +306 -44
- package/dist/endpoints/confirmOrder.js.map +1 -1
- package/dist/endpoints/initiatePayment.d.ts.map +1 -1
- package/dist/endpoints/initiatePayment.js +2 -0
- package/dist/endpoints/initiatePayment.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/pricesField.d.ts.map +1 -1
- package/dist/fields/pricesField.js +39 -39
- package/dist/fields/pricesField.js.map +1 -1
- package/dist/fields/statusField.d.ts.map +1 -1
- package/dist/fields/statusField.js +5 -0
- package/dist/fields/statusField.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/confirmOrder.js +108 -75
- package/dist/payments/adapters/stripe/confirmOrder.js.map +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.d.ts.map +1 -1
- package/dist/payments/adapters/stripe/initiatePayment.js +1 -0
- package/dist/payments/adapters/stripe/initiatePayment.js.map +1 -1
- package/dist/payments/adapters/stripe/validateSettlement.d.ts +37 -0
- package/dist/payments/adapters/stripe/validateSettlement.d.ts.map +1 -0
- package/dist/payments/adapters/stripe/validateSettlement.js +157 -0
- package/dist/payments/adapters/stripe/validateSettlement.js.map +1 -0
- package/dist/react/provider/index.d.ts.map +1 -1
- package/dist/react/provider/index.js +75 -34
- package/dist/react/provider/index.js.map +1 -1
- package/dist/react/provider/utilities.d.ts.map +1 -1
- package/dist/translations/languages/ar.d.ts.map +1 -1
- package/dist/translations/languages/az.d.ts.map +1 -1
- package/dist/translations/languages/bg.d.ts.map +1 -1
- package/dist/translations/languages/ca.d.ts.map +1 -1
- package/dist/translations/languages/cs.d.ts.map +1 -1
- package/dist/translations/languages/da.d.ts.map +1 -1
- package/dist/translations/languages/de.d.ts.map +1 -1
- package/dist/translations/languages/en.d.ts.map +1 -1
- package/dist/translations/languages/es.d.ts.map +1 -1
- package/dist/translations/languages/et.d.ts.map +1 -1
- package/dist/translations/languages/fa.d.ts.map +1 -1
- package/dist/translations/languages/fr.d.ts.map +1 -1
- package/dist/translations/languages/he.d.ts.map +1 -1
- package/dist/translations/languages/hr.d.ts.map +1 -1
- package/dist/translations/languages/hu.d.ts.map +1 -1
- package/dist/translations/languages/hy.d.ts.map +1 -1
- package/dist/translations/languages/is.d.ts.map +1 -1
- package/dist/translations/languages/it.d.ts.map +1 -1
- package/dist/translations/languages/ja.d.ts.map +1 -1
- package/dist/translations/languages/ko.d.ts.map +1 -1
- package/dist/translations/languages/lt.d.ts.map +1 -1
- package/dist/translations/languages/my.d.ts.map +1 -1
- package/dist/translations/languages/nb.d.ts.map +1 -1
- package/dist/translations/languages/nl.d.ts.map +1 -1
- package/dist/translations/languages/pl.d.ts.map +1 -1
- package/dist/translations/languages/pt.d.ts.map +1 -1
- package/dist/translations/languages/ro.d.ts.map +1 -1
- package/dist/translations/languages/rs.d.ts.map +1 -1
- package/dist/translations/languages/rsLatin.d.ts.map +1 -1
- package/dist/translations/languages/ru.d.ts.map +1 -1
- package/dist/translations/languages/sk.d.ts.map +1 -1
- package/dist/translations/languages/sl.d.ts.map +1 -1
- package/dist/translations/languages/sv.d.ts.map +1 -1
- package/dist/translations/languages/ta.d.ts.map +1 -1
- package/dist/translations/languages/th.d.ts.map +1 -1
- package/dist/translations/languages/tr.d.ts.map +1 -1
- package/dist/translations/languages/uk.d.ts.map +1 -1
- package/dist/translations/languages/vi.d.ts.map +1 -1
- package/dist/translations/languages/zh.d.ts.map +1 -1
- package/dist/translations/languages/zhTw.d.ts.map +1 -1
- package/dist/types/index.d.ts +33 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/ui/PriceInput/FormattedInput.js +2 -2
- package/dist/ui/PriceInput/FormattedInput.js.map +1 -1
- package/dist/ui/PriceInput/index.css +19 -31
- package/dist/ui/PriceInput/index.d.ts.map +1 -1
- package/dist/ui/PriceInput/index.js.map +1 -1
- package/dist/ui/PriceRowLabel/index.css +2 -2
- package/dist/ui/VariantOptionsSelector/index.css +8 -10
- package/dist/ui/VariantOptionsSelector/index.d.ts.map +1 -1
- package/dist/ui/VariantOptionsSelector/index.js +3 -1
- package/dist/ui/VariantOptionsSelector/index.js.map +1 -1
- package/dist/ui/utilities.d.ts.map +1 -1
- package/dist/utilities/accessComposition.d.ts.map +1 -1
- package/dist/utilities/getCollectionSlugMap.d.ts.map +1 -1
- package/dist/utilities/pushTypeScriptProperties.d.ts.map +1 -1
- package/dist/utilities/pushTypeScriptProperties.js +1 -1
- package/dist/utilities/pushTypeScriptProperties.js.map +1 -1
- package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js +0 -358
- package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js.map +0 -1
- package/dist/payments/adapters/stripe/confirmOrder.spec.js +0 -166
- package/dist/payments/adapters/stripe/confirmOrder.spec.js.map +0 -1
- package/dist/utilities/accessComposition.spec.js +0 -765
- package/dist/utilities/accessComposition.spec.js.map +0 -1
- package/dist/utilities/defaultProductsValidation.spec.js +0 -384
- package/dist/utilities/defaultProductsValidation.spec.js.map +0 -1
- package/dist/utilities/getCollectionSlugMap.spec.js +0 -254
- package/dist/utilities/getCollectionSlugMap.spec.js.map +0 -1
- package/dist/utilities/sanitizePluginConfig.spec.js +0 -516
- package/dist/utilities/sanitizePluginConfig.spec.js.map +0 -1
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { defaultCartItemMatcher } from './defaultCartItemMatcher.js';
|
|
3
|
-
describe('defaultCartItemMatcher', ()=>{
|
|
4
|
-
describe('product matching', ()=>{
|
|
5
|
-
it('should match when product IDs are equal (both strings)', ()=>{
|
|
6
|
-
const existingItem = {
|
|
7
|
-
id: 'item-1',
|
|
8
|
-
product: 'product-123',
|
|
9
|
-
quantity: 1
|
|
10
|
-
};
|
|
11
|
-
const newItem = {
|
|
12
|
-
product: 'product-123'
|
|
13
|
-
};
|
|
14
|
-
expect(defaultCartItemMatcher({
|
|
15
|
-
existingItem,
|
|
16
|
-
newItem
|
|
17
|
-
})).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
it('should not match when product IDs are different', ()=>{
|
|
20
|
-
const existingItem = {
|
|
21
|
-
id: 'item-1',
|
|
22
|
-
product: 'product-123',
|
|
23
|
-
quantity: 1
|
|
24
|
-
};
|
|
25
|
-
const newItem = {
|
|
26
|
-
product: 'product-456'
|
|
27
|
-
};
|
|
28
|
-
expect(defaultCartItemMatcher({
|
|
29
|
-
existingItem,
|
|
30
|
-
newItem
|
|
31
|
-
})).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
it('should match when existing product is populated object', ()=>{
|
|
34
|
-
const existingItem = {
|
|
35
|
-
id: 'item-1',
|
|
36
|
-
product: {
|
|
37
|
-
id: 'product-123',
|
|
38
|
-
name: 'Test Product'
|
|
39
|
-
},
|
|
40
|
-
quantity: 1
|
|
41
|
-
};
|
|
42
|
-
const newItem = {
|
|
43
|
-
product: 'product-123'
|
|
44
|
-
};
|
|
45
|
-
expect(defaultCartItemMatcher({
|
|
46
|
-
existingItem,
|
|
47
|
-
newItem
|
|
48
|
-
})).toBe(true);
|
|
49
|
-
});
|
|
50
|
-
it('should not match when product IDs differ (existing is object)', ()=>{
|
|
51
|
-
const existingItem = {
|
|
52
|
-
id: 'item-1',
|
|
53
|
-
product: {
|
|
54
|
-
id: 'product-123',
|
|
55
|
-
name: 'Test Product'
|
|
56
|
-
},
|
|
57
|
-
quantity: 1
|
|
58
|
-
};
|
|
59
|
-
const newItem = {
|
|
60
|
-
product: 'product-456'
|
|
61
|
-
};
|
|
62
|
-
expect(defaultCartItemMatcher({
|
|
63
|
-
existingItem,
|
|
64
|
-
newItem
|
|
65
|
-
})).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
describe('variant matching', ()=>{
|
|
69
|
-
it('should match when both have same variant ID', ()=>{
|
|
70
|
-
const existingItem = {
|
|
71
|
-
id: 'item-1',
|
|
72
|
-
product: 'product-123',
|
|
73
|
-
variant: 'variant-abc',
|
|
74
|
-
quantity: 1
|
|
75
|
-
};
|
|
76
|
-
const newItem = {
|
|
77
|
-
product: 'product-123',
|
|
78
|
-
variant: 'variant-abc'
|
|
79
|
-
};
|
|
80
|
-
expect(defaultCartItemMatcher({
|
|
81
|
-
existingItem,
|
|
82
|
-
newItem
|
|
83
|
-
})).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
it('should not match when variants are different', ()=>{
|
|
86
|
-
const existingItem = {
|
|
87
|
-
id: 'item-1',
|
|
88
|
-
product: 'product-123',
|
|
89
|
-
variant: 'variant-abc',
|
|
90
|
-
quantity: 1
|
|
91
|
-
};
|
|
92
|
-
const newItem = {
|
|
93
|
-
product: 'product-123',
|
|
94
|
-
variant: 'variant-xyz'
|
|
95
|
-
};
|
|
96
|
-
expect(defaultCartItemMatcher({
|
|
97
|
-
existingItem,
|
|
98
|
-
newItem
|
|
99
|
-
})).toBe(false);
|
|
100
|
-
});
|
|
101
|
-
it('should match when both have no variant', ()=>{
|
|
102
|
-
const existingItem = {
|
|
103
|
-
id: 'item-1',
|
|
104
|
-
product: 'product-123',
|
|
105
|
-
quantity: 1
|
|
106
|
-
};
|
|
107
|
-
const newItem = {
|
|
108
|
-
product: 'product-123'
|
|
109
|
-
};
|
|
110
|
-
expect(defaultCartItemMatcher({
|
|
111
|
-
existingItem,
|
|
112
|
-
newItem
|
|
113
|
-
})).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
it('should not match when existing has variant but new does not', ()=>{
|
|
116
|
-
const existingItem = {
|
|
117
|
-
id: 'item-1',
|
|
118
|
-
product: 'product-123',
|
|
119
|
-
variant: 'variant-abc',
|
|
120
|
-
quantity: 1
|
|
121
|
-
};
|
|
122
|
-
const newItem = {
|
|
123
|
-
product: 'product-123'
|
|
124
|
-
};
|
|
125
|
-
expect(defaultCartItemMatcher({
|
|
126
|
-
existingItem,
|
|
127
|
-
newItem
|
|
128
|
-
})).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
it('should not match when new has variant but existing does not', ()=>{
|
|
131
|
-
const existingItem = {
|
|
132
|
-
id: 'item-1',
|
|
133
|
-
product: 'product-123',
|
|
134
|
-
quantity: 1
|
|
135
|
-
};
|
|
136
|
-
const newItem = {
|
|
137
|
-
product: 'product-123',
|
|
138
|
-
variant: 'variant-abc'
|
|
139
|
-
};
|
|
140
|
-
expect(defaultCartItemMatcher({
|
|
141
|
-
existingItem,
|
|
142
|
-
newItem
|
|
143
|
-
})).toBe(false);
|
|
144
|
-
});
|
|
145
|
-
it('should match when existing variant is populated object', ()=>{
|
|
146
|
-
const existingItem = {
|
|
147
|
-
id: 'item-1',
|
|
148
|
-
product: 'product-123',
|
|
149
|
-
variant: {
|
|
150
|
-
id: 'variant-abc',
|
|
151
|
-
name: 'Large'
|
|
152
|
-
},
|
|
153
|
-
quantity: 1
|
|
154
|
-
};
|
|
155
|
-
const newItem = {
|
|
156
|
-
product: 'product-123',
|
|
157
|
-
variant: 'variant-abc'
|
|
158
|
-
};
|
|
159
|
-
expect(defaultCartItemMatcher({
|
|
160
|
-
existingItem,
|
|
161
|
-
newItem
|
|
162
|
-
})).toBe(true);
|
|
163
|
-
});
|
|
164
|
-
it('should not match when variant IDs differ (existing is object)', ()=>{
|
|
165
|
-
const existingItem = {
|
|
166
|
-
id: 'item-1',
|
|
167
|
-
product: 'product-123',
|
|
168
|
-
variant: {
|
|
169
|
-
id: 'variant-abc',
|
|
170
|
-
name: 'Large'
|
|
171
|
-
},
|
|
172
|
-
quantity: 1
|
|
173
|
-
};
|
|
174
|
-
const newItem = {
|
|
175
|
-
product: 'product-123',
|
|
176
|
-
variant: 'variant-xyz'
|
|
177
|
-
};
|
|
178
|
-
expect(defaultCartItemMatcher({
|
|
179
|
-
existingItem,
|
|
180
|
-
newItem
|
|
181
|
-
})).toBe(false);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
describe('combined product and variant matching', ()=>{
|
|
185
|
-
it('should match when both product and variant match', ()=>{
|
|
186
|
-
const existingItem = {
|
|
187
|
-
id: 'item-1',
|
|
188
|
-
product: 'product-123',
|
|
189
|
-
variant: 'variant-abc',
|
|
190
|
-
quantity: 1
|
|
191
|
-
};
|
|
192
|
-
const newItem = {
|
|
193
|
-
product: 'product-123',
|
|
194
|
-
variant: 'variant-abc'
|
|
195
|
-
};
|
|
196
|
-
expect(defaultCartItemMatcher({
|
|
197
|
-
existingItem,
|
|
198
|
-
newItem
|
|
199
|
-
})).toBe(true);
|
|
200
|
-
});
|
|
201
|
-
it('should not match when product matches but variant does not', ()=>{
|
|
202
|
-
const existingItem = {
|
|
203
|
-
id: 'item-1',
|
|
204
|
-
product: 'product-123',
|
|
205
|
-
variant: 'variant-abc',
|
|
206
|
-
quantity: 1
|
|
207
|
-
};
|
|
208
|
-
const newItem = {
|
|
209
|
-
product: 'product-123',
|
|
210
|
-
variant: 'variant-xyz'
|
|
211
|
-
};
|
|
212
|
-
expect(defaultCartItemMatcher({
|
|
213
|
-
existingItem,
|
|
214
|
-
newItem
|
|
215
|
-
})).toBe(false);
|
|
216
|
-
});
|
|
217
|
-
it('should not match when variant matches but product does not', ()=>{
|
|
218
|
-
const existingItem = {
|
|
219
|
-
id: 'item-1',
|
|
220
|
-
product: 'product-123',
|
|
221
|
-
variant: 'variant-abc',
|
|
222
|
-
quantity: 1
|
|
223
|
-
};
|
|
224
|
-
const newItem = {
|
|
225
|
-
product: 'product-456',
|
|
226
|
-
variant: 'variant-abc'
|
|
227
|
-
};
|
|
228
|
-
expect(defaultCartItemMatcher({
|
|
229
|
-
existingItem,
|
|
230
|
-
newItem
|
|
231
|
-
})).toBe(false);
|
|
232
|
-
});
|
|
233
|
-
it('should not match when neither product nor variant match', ()=>{
|
|
234
|
-
const existingItem = {
|
|
235
|
-
id: 'item-1',
|
|
236
|
-
product: 'product-123',
|
|
237
|
-
variant: 'variant-abc',
|
|
238
|
-
quantity: 1
|
|
239
|
-
};
|
|
240
|
-
const newItem = {
|
|
241
|
-
product: 'product-456',
|
|
242
|
-
variant: 'variant-xyz'
|
|
243
|
-
};
|
|
244
|
-
expect(defaultCartItemMatcher({
|
|
245
|
-
existingItem,
|
|
246
|
-
newItem
|
|
247
|
-
})).toBe(false);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
describe('edge cases', ()=>{
|
|
251
|
-
it('should handle undefined variant in existing item', ()=>{
|
|
252
|
-
const existingItem = {
|
|
253
|
-
id: 'item-1',
|
|
254
|
-
product: 'product-123',
|
|
255
|
-
variant: undefined,
|
|
256
|
-
quantity: 1
|
|
257
|
-
};
|
|
258
|
-
const newItem = {
|
|
259
|
-
product: 'product-123'
|
|
260
|
-
};
|
|
261
|
-
expect(defaultCartItemMatcher({
|
|
262
|
-
existingItem,
|
|
263
|
-
newItem
|
|
264
|
-
})).toBe(true);
|
|
265
|
-
});
|
|
266
|
-
it('should handle undefined variant in new item', ()=>{
|
|
267
|
-
const existingItem = {
|
|
268
|
-
id: 'item-1',
|
|
269
|
-
product: 'product-123',
|
|
270
|
-
quantity: 1
|
|
271
|
-
};
|
|
272
|
-
const newItem = {
|
|
273
|
-
product: 'product-123',
|
|
274
|
-
variant: undefined
|
|
275
|
-
};
|
|
276
|
-
expect(defaultCartItemMatcher({
|
|
277
|
-
existingItem,
|
|
278
|
-
newItem
|
|
279
|
-
})).toBe(true);
|
|
280
|
-
});
|
|
281
|
-
it('should handle numeric product IDs', ()=>{
|
|
282
|
-
const existingItem = {
|
|
283
|
-
id: 'item-1',
|
|
284
|
-
product: 123,
|
|
285
|
-
quantity: 1
|
|
286
|
-
};
|
|
287
|
-
const newItem = {
|
|
288
|
-
product: 123
|
|
289
|
-
};
|
|
290
|
-
expect(defaultCartItemMatcher({
|
|
291
|
-
existingItem,
|
|
292
|
-
newItem
|
|
293
|
-
})).toBe(true);
|
|
294
|
-
});
|
|
295
|
-
it('should handle deeply nested product object', ()=>{
|
|
296
|
-
const existingItem = {
|
|
297
|
-
id: 'item-1',
|
|
298
|
-
product: {
|
|
299
|
-
id: 'product-123',
|
|
300
|
-
name: 'Product',
|
|
301
|
-
category: {
|
|
302
|
-
id: 'cat-1',
|
|
303
|
-
name: 'Category'
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
quantity: 1
|
|
307
|
-
};
|
|
308
|
-
const newItem = {
|
|
309
|
-
product: 'product-123'
|
|
310
|
-
};
|
|
311
|
-
expect(defaultCartItemMatcher({
|
|
312
|
-
existingItem,
|
|
313
|
-
newItem
|
|
314
|
-
})).toBe(true);
|
|
315
|
-
});
|
|
316
|
-
it('should handle both product and variant as populated objects', ()=>{
|
|
317
|
-
const existingItem = {
|
|
318
|
-
id: 'item-1',
|
|
319
|
-
product: {
|
|
320
|
-
id: 'product-123',
|
|
321
|
-
name: 'Product'
|
|
322
|
-
},
|
|
323
|
-
variant: {
|
|
324
|
-
id: 'variant-abc',
|
|
325
|
-
name: 'Large'
|
|
326
|
-
},
|
|
327
|
-
quantity: 1
|
|
328
|
-
};
|
|
329
|
-
const newItem = {
|
|
330
|
-
product: 'product-123',
|
|
331
|
-
variant: 'variant-abc'
|
|
332
|
-
};
|
|
333
|
-
expect(defaultCartItemMatcher({
|
|
334
|
-
existingItem,
|
|
335
|
-
newItem
|
|
336
|
-
})).toBe(true);
|
|
337
|
-
});
|
|
338
|
-
it('should ignore other item properties', ()=>{
|
|
339
|
-
const existingItem = {
|
|
340
|
-
id: 'item-1',
|
|
341
|
-
product: 'product-123',
|
|
342
|
-
quantity: 5,
|
|
343
|
-
customProp: 'value-a'
|
|
344
|
-
};
|
|
345
|
-
const newItem = {
|
|
346
|
-
product: 'product-123',
|
|
347
|
-
customProp: 'value-b'
|
|
348
|
-
};
|
|
349
|
-
// Should match because only product/variant are checked
|
|
350
|
-
expect(defaultCartItemMatcher({
|
|
351
|
-
existingItem,
|
|
352
|
-
newItem
|
|
353
|
-
})).toBe(true);
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
//# sourceMappingURL=defaultCartItemMatcher.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/carts/operations/defaultCartItemMatcher.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport type { CartItemData, NewCartItem } from './types.js'\n\nimport { defaultCartItemMatcher } from './defaultCartItemMatcher.js'\n\ndescribe('defaultCartItemMatcher', () => {\n describe('product matching', () => {\n it('should match when product IDs are equal (both strings)', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should not match when product IDs are different', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-456',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n\n it('should match when existing product is populated object', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: { id: 'product-123', name: 'Test Product' } as any,\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should not match when product IDs differ (existing is object)', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: { id: 'product-123', name: 'Test Product' } as any,\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-456',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n })\n\n describe('variant matching', () => {\n it('should match when both have same variant ID', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: 'variant-abc',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: 'variant-abc',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should not match when variants are different', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: 'variant-abc',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: 'variant-xyz',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n\n it('should match when both have no variant', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should not match when existing has variant but new does not', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: 'variant-abc',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n\n it('should not match when new has variant but existing does not', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: 'variant-abc',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n\n it('should match when existing variant is populated object', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: { id: 'variant-abc', name: 'Large' } as any,\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: 'variant-abc',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should not match when variant IDs differ (existing is object)', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: { id: 'variant-abc', name: 'Large' } as any,\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: 'variant-xyz',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n })\n\n describe('combined product and variant matching', () => {\n it('should match when both product and variant match', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: 'variant-abc',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: 'variant-abc',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should not match when product matches but variant does not', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: 'variant-abc',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: 'variant-xyz',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n\n it('should not match when variant matches but product does not', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: 'variant-abc',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-456',\n variant: 'variant-abc',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n\n it('should not match when neither product nor variant match', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: 'variant-abc',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-456',\n variant: 'variant-xyz',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(false)\n })\n })\n\n describe('edge cases', () => {\n it('should handle undefined variant in existing item', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n variant: undefined,\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should handle undefined variant in new item', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: undefined,\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should handle numeric product IDs', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 123 as any,\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 123 as any,\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should handle deeply nested product object', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: {\n id: 'product-123',\n name: 'Product',\n category: { id: 'cat-1', name: 'Category' },\n } as any,\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should handle both product and variant as populated objects', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: { id: 'product-123', name: 'Product' } as any,\n variant: { id: 'variant-abc', name: 'Large' } as any,\n quantity: 1,\n }\n const newItem: NewCartItem = {\n product: 'product-123',\n variant: 'variant-abc',\n }\n\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n\n it('should ignore other item properties', () => {\n const existingItem: CartItemData = {\n id: 'item-1',\n product: 'product-123',\n quantity: 5,\n customProp: 'value-a',\n } as CartItemData\n const newItem: NewCartItem = {\n product: 'product-123',\n customProp: 'value-b',\n } as NewCartItem\n\n // Should match because only product/variant are checked\n expect(defaultCartItemMatcher({ existingItem, newItem })).toBe(true)\n })\n })\n})\n"],"names":["describe","expect","it","defaultCartItemMatcher","existingItem","id","product","quantity","newItem","toBe","name","variant","undefined","category","customProp"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAI7C,SAASC,sBAAsB,QAAQ,8BAA6B;AAEpEH,SAAS,0BAA0B;IACjCA,SAAS,oBAAoB;QAC3BE,GAAG,0DAA0D;YAC3D,MAAME,eAA6B;gBACjCC,IAAI;gBACJC,SAAS;gBACTC,UAAU;YACZ;YACA,MAAMC,UAAuB;gBAC3BF,SAAS;YACX;YAEAL,OAAOE,uBAAuB;gBAAEC;gBAAcI;YAAQ,IAAIC,IAAI,CAAC;QACjE;QAEAP,GAAG,mDAAmD;YACpD,MAAME,eAA6B;gBACjCC,IAAI;gBACJC,SAAS;gBACTC,UAAU;YACZ;YACA,MAAMC,UAAuB;gBAC3BF,SAAS;YACX;YAEAL,OAAOE,uBAAuB;gBAAEC;gBAAcI;YAAQ,IAAIC,IAAI,CAAC;QACjE;QAEAP,GAAG,0DAA0D;YAC3D,MAAME,eAA6B;gBACjCC,IAAI;gBACJC,SAAS;oBAAED,IAAI;oBAAeK,MAAM;gBAAe;gBACnDH,UAAU;YACZ;YACA,MAAMC,UAAuB;gBAC3BF,SAAS;YACX;YAEAL,OAAOE,uB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ACA,MAAMC,UAAuB;gBAC3BF,SAAS;YACX;YAEAL,OAAOE,uBAAuB;gBAAEC;gBAAcI;YAAQ,IAAIC,IAAI,CAAC;QACjE;QAEAP,GAAG,+DAA+D;YAChE,MAAME,eAA6B;gBACjCC,IAAI;gBACJC,SAAS;oBAAED,IAAI;oBAAeK,MAAM;gBAAU;gBAC9CC,SAAS;oBAAEN,IAAI;oBAAeK,MAAM;gBAAQ;gBAC5CH,UAAU;YACZ;YACA,MAAMC,UAAuB;gBAC3BF,SAAS;gBACTK,SAAS;YACX;YAEAV,OAAOE,uBAAuB;gBAAEC;gBAAcI;YAAQ,IAAIC,IAAI,CAAC;QACjE;QAEAP,GAAG,uCAAuC;YACxC,MAAME,eAA6B;gBACjCC,IAAI;gBACJC,SAAS;gBACTC,UAAU;gBACVO,YAAY;YACd;YACA,MAAMN,UAAuB;gBAC3BF,SAAS;gBACTQ,YAAY;YACd;YAEA,wDAAwD;YACxDb,OAAOE,uBAAuB;gBAAEC;gBAAcI;YAAQ,IAAIC,IAAI,CAAC;QACjE;IACF;AACF"}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
const mockCustomersList = vi.fn();
|
|
3
|
-
const mockCustomersCreate = vi.fn();
|
|
4
|
-
const mockPaymentIntentsRetrieve = vi.fn();
|
|
5
|
-
vi.mock('stripe', ()=>{
|
|
6
|
-
const MockStripe = function() {
|
|
7
|
-
return {
|
|
8
|
-
customers: {
|
|
9
|
-
list: mockCustomersList,
|
|
10
|
-
create: mockCustomersCreate
|
|
11
|
-
},
|
|
12
|
-
paymentIntents: {
|
|
13
|
-
retrieve: mockPaymentIntentsRetrieve
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
return {
|
|
18
|
-
default: MockStripe
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
import { confirmOrder } from './confirmOrder';
|
|
22
|
-
const defaultCartItemsSnapshot = JSON.stringify([
|
|
23
|
-
{
|
|
24
|
-
id: 'item-1',
|
|
25
|
-
quantity: 1
|
|
26
|
-
}
|
|
27
|
-
]);
|
|
28
|
-
const createMockPaymentIntent = (status)=>({
|
|
29
|
-
amount: 1000,
|
|
30
|
-
currency: 'usd',
|
|
31
|
-
metadata: {
|
|
32
|
-
cartID: 'cart-123',
|
|
33
|
-
cartItemsSnapshot: defaultCartItemsSnapshot,
|
|
34
|
-
shippingAddress: JSON.stringify({
|
|
35
|
-
city: 'Test City'
|
|
36
|
-
})
|
|
37
|
-
},
|
|
38
|
-
status
|
|
39
|
-
});
|
|
40
|
-
const createMockPayload = ()=>({
|
|
41
|
-
create: vi.fn().mockResolvedValue({
|
|
42
|
-
id: 'order-123'
|
|
43
|
-
}),
|
|
44
|
-
find: vi.fn().mockResolvedValue({
|
|
45
|
-
docs: [
|
|
46
|
-
{
|
|
47
|
-
id: 'txn-123'
|
|
48
|
-
}
|
|
49
|
-
],
|
|
50
|
-
totalDocs: 1
|
|
51
|
-
}),
|
|
52
|
-
logger: {
|
|
53
|
-
error: vi.fn()
|
|
54
|
-
},
|
|
55
|
-
update: vi.fn().mockResolvedValue({})
|
|
56
|
-
});
|
|
57
|
-
const createMockReq = (payload)=>({
|
|
58
|
-
payload,
|
|
59
|
-
user: {
|
|
60
|
-
id: 'user-123'
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
describe('confirmOrder - payment status check', ()=>{
|
|
64
|
-
const secretKey = 'sk_test_123';
|
|
65
|
-
beforeEach(()=>{
|
|
66
|
-
vi.clearAllMocks();
|
|
67
|
-
mockCustomersList.mockResolvedValue({
|
|
68
|
-
data: [
|
|
69
|
-
{
|
|
70
|
-
id: 'cus-123'
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
});
|
|
74
|
-
mockCustomersCreate.mockResolvedValue({
|
|
75
|
-
id: 'cus-new'
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
it('should throw when paymentIntent status is requires_payment_method', async ()=>{
|
|
79
|
-
mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('requires_payment_method'));
|
|
80
|
-
const mockPayload = createMockPayload();
|
|
81
|
-
const handler = confirmOrder({
|
|
82
|
-
secretKey
|
|
83
|
-
});
|
|
84
|
-
await expect(handler({
|
|
85
|
-
data: {
|
|
86
|
-
customerEmail: 'test@test.com',
|
|
87
|
-
paymentIntentID: 'pi_123'
|
|
88
|
-
},
|
|
89
|
-
req: createMockReq(mockPayload)
|
|
90
|
-
})).rejects.toThrow('Payment not completed.');
|
|
91
|
-
expect(mockPayload.create).not.toHaveBeenCalled();
|
|
92
|
-
});
|
|
93
|
-
it('should throw when paymentIntent status is canceled', async ()=>{
|
|
94
|
-
mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('canceled'));
|
|
95
|
-
const mockPayload = createMockPayload();
|
|
96
|
-
const handler = confirmOrder({
|
|
97
|
-
secretKey
|
|
98
|
-
});
|
|
99
|
-
await expect(handler({
|
|
100
|
-
data: {
|
|
101
|
-
customerEmail: 'test@test.com',
|
|
102
|
-
paymentIntentID: 'pi_123'
|
|
103
|
-
},
|
|
104
|
-
req: createMockReq(mockPayload)
|
|
105
|
-
})).rejects.toThrow('Payment not completed.');
|
|
106
|
-
expect(mockPayload.create).not.toHaveBeenCalled();
|
|
107
|
-
});
|
|
108
|
-
it('should throw when paymentIntent status is processing', async ()=>{
|
|
109
|
-
mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('processing'));
|
|
110
|
-
const mockPayload = createMockPayload();
|
|
111
|
-
const handler = confirmOrder({
|
|
112
|
-
secretKey
|
|
113
|
-
});
|
|
114
|
-
await expect(handler({
|
|
115
|
-
data: {
|
|
116
|
-
customerEmail: 'test@test.com',
|
|
117
|
-
paymentIntentID: 'pi_123'
|
|
118
|
-
},
|
|
119
|
-
req: createMockReq(mockPayload)
|
|
120
|
-
})).rejects.toThrow('Payment not completed.');
|
|
121
|
-
expect(mockPayload.create).not.toHaveBeenCalled();
|
|
122
|
-
});
|
|
123
|
-
it('should not update cart or transaction when payment has not succeeded', async ()=>{
|
|
124
|
-
mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('requires_payment_method'));
|
|
125
|
-
const mockPayload = createMockPayload();
|
|
126
|
-
const handler = confirmOrder({
|
|
127
|
-
secretKey
|
|
128
|
-
});
|
|
129
|
-
await expect(handler({
|
|
130
|
-
data: {
|
|
131
|
-
customerEmail: 'test@test.com',
|
|
132
|
-
paymentIntentID: 'pi_123'
|
|
133
|
-
},
|
|
134
|
-
req: createMockReq(mockPayload)
|
|
135
|
-
})).rejects.toThrow();
|
|
136
|
-
expect(mockPayload.update).not.toHaveBeenCalled();
|
|
137
|
-
});
|
|
138
|
-
it('should create order when paymentIntent status is succeeded', async ()=>{
|
|
139
|
-
mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('succeeded'));
|
|
140
|
-
const mockPayload = createMockPayload();
|
|
141
|
-
const handler = confirmOrder({
|
|
142
|
-
secretKey
|
|
143
|
-
});
|
|
144
|
-
const result = await handler({
|
|
145
|
-
data: {
|
|
146
|
-
customerEmail: 'test@test.com',
|
|
147
|
-
paymentIntentID: 'pi_123'
|
|
148
|
-
},
|
|
149
|
-
req: createMockReq(mockPayload)
|
|
150
|
-
});
|
|
151
|
-
expect(mockPayload.create).toHaveBeenCalledWith(expect.objectContaining({
|
|
152
|
-
collection: 'orders',
|
|
153
|
-
data: expect.objectContaining({
|
|
154
|
-
amount: 1000,
|
|
155
|
-
currency: 'USD',
|
|
156
|
-
status: 'processing'
|
|
157
|
-
})
|
|
158
|
-
}));
|
|
159
|
-
expect(result).toEqual(expect.objectContaining({
|
|
160
|
-
orderID: 'order-123',
|
|
161
|
-
transactionID: 'txn-123'
|
|
162
|
-
}));
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
//# sourceMappingURL=confirmOrder.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/payments/adapters/stripe/confirmOrder.spec.ts"],"sourcesContent":["import { beforeEach, describe, expect, it, vi } from 'vitest'\n\nconst mockCustomersList = vi.fn()\nconst mockCustomersCreate = vi.fn()\nconst mockPaymentIntentsRetrieve = vi.fn()\n\nvi.mock('stripe', () => {\n const MockStripe = function () {\n return {\n customers: {\n list: mockCustomersList,\n create: mockCustomersCreate,\n },\n paymentIntents: {\n retrieve: mockPaymentIntentsRetrieve,\n },\n }\n }\n\n return { default: MockStripe }\n})\n\nimport { confirmOrder } from './confirmOrder'\n\nconst defaultCartItemsSnapshot = JSON.stringify([{ id: 'item-1', quantity: 1 }])\n\nconst createMockPaymentIntent = (status: string) => ({\n amount: 1000,\n currency: 'usd',\n metadata: {\n cartID: 'cart-123',\n cartItemsSnapshot: defaultCartItemsSnapshot,\n shippingAddress: JSON.stringify({ city: 'Test City' }),\n },\n status,\n})\n\nconst createMockPayload = () => ({\n create: vi.fn().mockResolvedValue({ id: 'order-123' }),\n find: vi.fn().mockResolvedValue({\n docs: [{ id: 'txn-123' }],\n totalDocs: 1,\n }),\n logger: { error: vi.fn() },\n update: vi.fn().mockResolvedValue({}),\n})\n\nconst createMockReq = (payload: ReturnType<typeof createMockPayload>) =>\n ({\n payload,\n user: { id: 'user-123' },\n }) as any\n\ndescribe('confirmOrder - payment status check', () => {\n const secretKey = 'sk_test_123'\n\n beforeEach(() => {\n vi.clearAllMocks()\n\n mockCustomersList.mockResolvedValue({ data: [{ id: 'cus-123' }] })\n mockCustomersCreate.mockResolvedValue({ id: 'cus-new' })\n })\n\n it('should throw when paymentIntent status is requires_payment_method', async () => {\n mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('requires_payment_method'))\n\n const mockPayload = createMockPayload()\n const handler = confirmOrder({ secretKey })\n\n await expect(\n handler({\n data: { customerEmail: 'test@test.com', paymentIntentID: 'pi_123' },\n req: createMockReq(mockPayload),\n }),\n ).rejects.toThrow('Payment not completed.')\n\n expect(mockPayload.create).not.toHaveBeenCalled()\n })\n\n it('should throw when paymentIntent status is canceled', async () => {\n mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('canceled'))\n\n const mockPayload = createMockPayload()\n const handler = confirmOrder({ secretKey })\n\n await expect(\n handler({\n data: { customerEmail: 'test@test.com', paymentIntentID: 'pi_123' },\n req: createMockReq(mockPayload),\n }),\n ).rejects.toThrow('Payment not completed.')\n\n expect(mockPayload.create).not.toHaveBeenCalled()\n })\n\n it('should throw when paymentIntent status is processing', async () => {\n mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('processing'))\n\n const mockPayload = createMockPayload()\n const handler = confirmOrder({ secretKey })\n\n await expect(\n handler({\n data: { customerEmail: 'test@test.com', paymentIntentID: 'pi_123' },\n req: createMockReq(mockPayload),\n }),\n ).rejects.toThrow('Payment not completed.')\n\n expect(mockPayload.create).not.toHaveBeenCalled()\n })\n\n it('should not update cart or transaction when payment has not succeeded', async () => {\n mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('requires_payment_method'))\n\n const mockPayload = createMockPayload()\n const handler = confirmOrder({ secretKey })\n\n await expect(\n handler({\n data: { customerEmail: 'test@test.com', paymentIntentID: 'pi_123' },\n req: createMockReq(mockPayload),\n }),\n ).rejects.toThrow()\n\n expect(mockPayload.update).not.toHaveBeenCalled()\n })\n\n it('should create order when paymentIntent status is succeeded', async () => {\n mockPaymentIntentsRetrieve.mockResolvedValue(createMockPaymentIntent('succeeded'))\n\n const mockPayload = createMockPayload()\n const handler = confirmOrder({ secretKey })\n\n const result = await handler({\n data: { customerEmail: 'test@test.com', paymentIntentID: 'pi_123' },\n req: createMockReq(mockPayload),\n })\n\n expect(mockPayload.create).toHaveBeenCalledWith(\n expect.objectContaining({\n collection: 'orders',\n data: expect.objectContaining({\n amount: 1000,\n currency: 'USD',\n status: 'processing',\n }),\n }),\n )\n\n expect(result).toEqual(\n expect.objectContaining({\n orderID: 'order-123',\n transactionID: 'txn-123',\n }),\n )\n })\n})\n"],"names":["beforeEach","describe","expect","it","vi","mockCustomersList","fn","mockCustomersCreate","mockPaymentIntentsRetrieve","mock","MockStripe","customers","list","create","paymentIntents","retrieve","default","confirmOrder","defaultCartItemsSnapshot","JSON","stringify","id","quantity","createMockPaymentIntent","status","amount","currency","metadata","cartID","cartItemsSnapshot","shippingAddress","city","createMockPayload","mockResolvedValue","find","docs","totalDocs","logger","error","update","createMockReq","payload","user","secretKey","clearAllMocks","data","mockPayload","handler","customerEmail","paymentIntentID","req","rejects","toThrow","not","toHaveBeenCalled","result","toHaveBeenCalledWith","objectContaining","collection","toEqual","orderID","transactionID"],"mappings":"AAAA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAE7D,MAAMC,oBAAoBD,GAAGE,EAAE;AAC/B,MAAMC,sBAAsBH,GAAGE,EAAE;AACjC,MAAME,6BAA6BJ,GAAGE,EAAE;AAExCF,GAAGK,IAAI,CAAC,UAAU;IAChB,MAAMC,aAAa;QACjB,OAAO;YACLC,WAAW;gBACTC,MAAMP;gBACNQ,QAAQN;YACV;YACAO,gBAAgB;gBACdC,UAAUP;YACZ;QACF;IACF;IAEA,OAAO;QAAEQ,SAASN;IAAW;AAC/B;AAEA,SAASO,YAAY,QAAQ,iBAAgB;AAE7C,MAAMC,2BAA2BC,KAAKC,SAAS,CAAC;IAAC;QAAEC,IAAI;QAAUC,UAAU;IAAE;CAAE;AAE/E,MAAMC,0BAA0B,CAACC,SAAoB,CAAA;QACnDC,QAAQ;QACRC,UAAU;QACVC,UAAU;YACRC,QAAQ;YACRC,mBAAmBX;YACnBY,iBAAiBX,KAAKC,SAAS,CAAC;gBAAEW,MAAM;YAAY;QACtD;QACAP;IACF,CAAA;AAEA,MAAMQ,oBAAoB,IAAO,CAAA;QAC/BnB,QAAQT,GAAGE,EAAE,GAAG2B,iBAAiB,CAAC;YAAEZ,IAAI;QAAY;QAC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