@payloadcms/plugin-ecommerce 4.0.0-canary.34 → 4.0.0-canary.36
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/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/package.json +8 -8
- package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js +0 -358
- package/dist/collections/carts/operations/defaultCartItemMatcher.spec.js.map +0 -1
- package/dist/collections/orders/createOrdersCollection.spec.js +0 -20
- package/dist/collections/orders/createOrdersCollection.spec.js.map +0 -1
- package/dist/endpoints/confirmOrder.spec.js +0 -509
- package/dist/endpoints/confirmOrder.spec.js.map +0 -1
- package/dist/fields/statusField.spec.js +0 -9
- package/dist/fields/statusField.spec.js.map +0 -1
- package/dist/payments/adapters/stripe/confirmOrder.spec.js +0 -255
- package/dist/payments/adapters/stripe/confirmOrder.spec.js.map +0 -1
- package/dist/payments/adapters/stripe/validateSettlement.spec.js +0 -434
- package/dist/payments/adapters/stripe/validateSettlement.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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-ecommerce",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.36",
|
|
4
4
|
"description": "Ecommerce plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"qs-esm": "8.0.1",
|
|
77
|
-
"@payloadcms/translations": "4.0.0-canary.
|
|
78
|
-
"@payloadcms/ui": "4.0.0-canary.
|
|
77
|
+
"@payloadcms/translations": "4.0.0-canary.36",
|
|
78
|
+
"@payloadcms/ui": "4.0.0-canary.36"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@types/json-schema": "7.0.15",
|
|
@@ -83,14 +83,14 @@
|
|
|
83
83
|
"@types/react-dom": "19.2.3",
|
|
84
84
|
"stripe": "18.3.0",
|
|
85
85
|
"@payloadcms/eslint-config": "3.28.0",
|
|
86
|
-
"@payloadcms/next": "4.0.0-canary.
|
|
87
|
-
"
|
|
88
|
-
"
|
|
86
|
+
"@payloadcms/next": "4.0.0-canary.36",
|
|
87
|
+
"@payloadcms/translations": "4.0.0-canary.36",
|
|
88
|
+
"payload": "4.0.0-canary.36"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"react": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
92
92
|
"react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1",
|
|
93
|
-
"payload": "4.0.0-canary.
|
|
93
|
+
"payload": "4.0.0-canary.36"
|
|
94
94
|
},
|
|
95
95
|
"publishConfig": {
|
|
96
96
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
103
103
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
104
104
|
"clean": "rimraf -g {dist,*.tsbuildinfo}",
|
|
105
|
-
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
105
|
+
"copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
106
106
|
"lint": "eslint .",
|
|
107
107
|
"lint:fix": "eslint . --fix"
|
|
108
108
|
}
|
|
@@ -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,MA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AC3BF,SAAS;gBACTQ,YAAY;YACd;YAEA,wDAAwD;YACxDb,OAAOE,uBAAuB;gBAAEC;gBAAcI;YAAQ,IAAIC,IAAI,CAAC;QACjE;IACF;AACF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expect, expectTypeOf, it, vi } from 'vitest';
|
|
2
|
-
import { createOrdersCollection } from './createOrdersCollection.js';
|
|
3
|
-
describe('createOrdersCollection', ()=>{
|
|
4
|
-
it('should not add a second payment reference to orders', ()=>{
|
|
5
|
-
const adminOnlyFieldAccess = vi.fn();
|
|
6
|
-
const collection = createOrdersCollection({
|
|
7
|
-
access: {
|
|
8
|
-
adminOnlyFieldAccess,
|
|
9
|
-
isAdmin: vi.fn(),
|
|
10
|
-
isDocumentOwner: vi.fn()
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
expect(collection.fields.some((field)=>'name' in field && field.name === 'paymentReference')).toBe(false);
|
|
14
|
-
});
|
|
15
|
-
it('should require adapters to return the public transaction ID', ()=>{
|
|
16
|
-
expectTypeOf().toMatchTypeOf();
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=createOrdersCollection.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/orders/createOrdersCollection.spec.ts"],"sourcesContent":["import { describe, expect, expectTypeOf, it, vi } from 'vitest'\n\nimport type { PaymentAdapter } from '../../types/index.js'\n\nimport { createOrdersCollection } from './createOrdersCollection.js'\n\ndescribe('createOrdersCollection', () => {\n it('should not add a second payment reference to orders', () => {\n const adminOnlyFieldAccess = vi.fn()\n const collection = createOrdersCollection({\n access: {\n adminOnlyFieldAccess,\n isAdmin: vi.fn(),\n isDocumentOwner: vi.fn(),\n },\n })\n expect(\n collection.fields.some((field) => 'name' in field && field.name === 'paymentReference'),\n ).toBe(false)\n })\n\n it('should require adapters to return the public transaction ID', () => {\n type ConfirmationResult = Awaited<ReturnType<PaymentAdapter['confirmOrder']>>\n\n expectTypeOf<ConfirmationResult>().toMatchTypeOf<{\n message: string\n orderID: string | number\n transactionID: string | number\n }>()\n })\n})\n"],"names":["describe","expect","expectTypeOf","it","vi","createOrdersCollection","adminOnlyFieldAccess","fn","collection","access","isAdmin","isDocumentOwner","fields","some","field","name","toBe","toMatchTypeOf"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,YAAY,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAI/D,SAASC,sBAAsB,QAAQ,8BAA6B;AAEpEL,SAAS,0BAA0B;IACjCG,GAAG,uDAAuD;QACxD,MAAMG,uBAAuBF,GAAGG,EAAE;QAClC,MAAMC,aAAaH,uBAAuB;YACxCI,QAAQ;gBACNH;gBACAI,SAASN,GAAGG,EAAE;gBACdI,iBAAiBP,GAAGG,EAAE;YACxB;QACF;QACAN,OACEO,WAAWI,MAAM,CAACC,IAAI,CAAC,CAACC,QAAU,UAAUA,SAASA,MAAMC,IAAI,KAAK,qBACpEC,IAAI,CAAC;IACT;IAEAb,GAAG,+DAA+D;QAGhED,eAAmCe,aAAa;IAKlD;AACF"}
|