@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
3
  "author": "Michael van Tellingen",
4
- "version": "2.16.1",
4
+ "version": "2.17.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -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