@labdigital/commercetools-mock 2.16.0 → 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.0",
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>,
@@ -345,7 +345,7 @@ export class ShoppingListRepository extends AbstractResourceRepository<'shopping
345
345
  ),
346
346
  }
347
347
 
348
- if (variantId) {
348
+ if (productId && variantId) {
349
349
  return lineItem
350
350
  }
351
351
 
@@ -367,6 +367,7 @@ export class ShoppingListRepository extends AbstractResourceRepository<'shopping
367
367
  ]
368
368
  const variantId = allVariants.find((e) => e.sku === sku)?.id
369
369
  lineItem.variantId = variantId
370
+ lineItem.productId = product.id
370
371
  return lineItem
371
372
  }
372
373
 
@@ -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
 
@@ -93,7 +93,7 @@ describe('Shopping List', () => {
93
93
  expect(response.body.lineItems[0].variantId).toBe(2)
94
94
  })
95
95
 
96
- test('Expands variant on lineItems', async () => {
96
+ test('Expands variant on lineItems when getting', async () => {
97
97
  const response = await supertest(ctMock.app)
98
98
  .get(`/dummy/shopping-lists/${shoppingList.id}`)
99
99
  .query({ expand: 'lineItems[*].variant' })
@@ -104,6 +104,23 @@ describe('Shopping List', () => {
104
104
  sku: '22241940260',
105
105
  })
106
106
  })
107
+
108
+ test('Expands variant on lineItems when creating', async () => {
109
+ const draft: ShoppingListDraft = {
110
+ name: {},
111
+ lineItems: [{ sku: '22241940260' }],
112
+ }
113
+ const response = await supertest(ctMock.app)
114
+ .post('/dummy/shopping-lists')
115
+ .query({ expand: 'lineItems[*].variant' })
116
+ .send(draft)
117
+
118
+ expect(response.status).toBe(201)
119
+ expect(response.body.lineItems[0].variant).toEqual({
120
+ id: 2,
121
+ sku: '22241940260',
122
+ })
123
+ })
107
124
  })
108
125
 
109
126
  describe('Shopping List Update Actions', () => {