@labdigital/commercetools-mock 2.16.1 → 2.17.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.cjs +6 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart.ts +12 -0
- package/src/services/cart.test.ts +50 -0
package/package.json
CHANGED
package/src/repositories/cart.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
type CartRemoveDiscountCodeAction,
|
|
28
28
|
type ProductVariant,
|
|
29
29
|
type CartSetCustomShippingMethodAction,
|
|
30
|
+
type CartSetDirectDiscountsAction,
|
|
30
31
|
} from '@commercetools/platform-sdk'
|
|
31
32
|
import { v4 as uuidv4 } from 'uuid'
|
|
32
33
|
import { CommercetoolsError } from '../exceptions.js'
|
|
@@ -455,6 +456,17 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
455
456
|
}
|
|
456
457
|
}
|
|
457
458
|
},
|
|
459
|
+
setDirectDiscounts: (
|
|
460
|
+
context: RepositoryContext,
|
|
461
|
+
resource: Writable<Cart>,
|
|
462
|
+
{ discounts }: CartSetDirectDiscountsAction
|
|
463
|
+
) => {
|
|
464
|
+
// Doesn't apply any discounts logic, just sets the directDiscounts field
|
|
465
|
+
resource.directDiscounts = discounts.map((discount) => ({
|
|
466
|
+
...discount,
|
|
467
|
+
id: uuidv4(),
|
|
468
|
+
}))
|
|
469
|
+
},
|
|
458
470
|
setLocale: (
|
|
459
471
|
context: RepositoryContext,
|
|
460
472
|
resource: Writable<Cart>,
|
|
@@ -440,6 +440,56 @@ describe('Cart Update Actions', () => {
|
|
|
440
440
|
expect(response.body.country).toBe('NL')
|
|
441
441
|
})
|
|
442
442
|
|
|
443
|
+
test('setDirectDiscounts', async () => {
|
|
444
|
+
assert(cart, 'cart not created')
|
|
445
|
+
|
|
446
|
+
const response = await supertest(ctMock.app)
|
|
447
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
448
|
+
.send({
|
|
449
|
+
version: 1,
|
|
450
|
+
actions: [
|
|
451
|
+
{
|
|
452
|
+
action: 'setDirectDiscounts',
|
|
453
|
+
discounts: [
|
|
454
|
+
{
|
|
455
|
+
target: { type: 'totalPrice' },
|
|
456
|
+
value: {
|
|
457
|
+
money: [
|
|
458
|
+
{
|
|
459
|
+
centAmount: 500,
|
|
460
|
+
currencyCode: 'EUR',
|
|
461
|
+
fractionDigits: 2,
|
|
462
|
+
type: 'centPrecision',
|
|
463
|
+
},
|
|
464
|
+
],
|
|
465
|
+
type: 'absolute',
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
},
|
|
470
|
+
],
|
|
471
|
+
})
|
|
472
|
+
expect(response.status).toBe(200)
|
|
473
|
+
expect(response.body.version).toBe(2)
|
|
474
|
+
expect(response.body.directDiscounts).toMatchObject([
|
|
475
|
+
{
|
|
476
|
+
id: expect.any(String),
|
|
477
|
+
target: { type: 'totalPrice' },
|
|
478
|
+
value: {
|
|
479
|
+
money: [
|
|
480
|
+
{
|
|
481
|
+
centAmount: 500,
|
|
482
|
+
currencyCode: 'EUR',
|
|
483
|
+
fractionDigits: 2,
|
|
484
|
+
type: 'centPrecision',
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
type: 'absolute',
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
])
|
|
491
|
+
})
|
|
492
|
+
|
|
443
493
|
test('setCustomerEmail', async () => {
|
|
444
494
|
assert(cart, 'cart not created')
|
|
445
495
|
|