@labdigital/commercetools-mock 2.9.0 → 2.10.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.9.0",
4
+ "version": "2.10.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -230,6 +230,15 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
230
230
  // Update cart total price
231
231
  resource.totalPrice.centAmount = calculateCartTotalPrice(resource)
232
232
  },
233
+ recalculate: () => {
234
+ // Dummy action when triggering a recalculation of the cart
235
+ //
236
+ // From commercetools documentation:
237
+ // This update action does not set any Cart field in particular,
238
+ // but it triggers several Cart updates to bring prices and discounts to the latest state.
239
+ // Those can become stale over time when no Cart updates have been performed for a while
240
+ // and prices on related Products have changed in the meanwhile.
241
+ },
233
242
  addItemShippingAddress: (
234
243
  context: RepositoryContext,
235
244
  resource: Writable<Cart>,
@@ -303,6 +303,30 @@ describe('Cart Update Actions', () => {
303
303
  expect(response.body.lineItems).toHaveLength(0)
304
304
  })
305
305
 
306
+ test('recalculate', async () => {
307
+ const product = await supertest(ctMock.app)
308
+ .post(`/dummy/products`)
309
+ .send(productDraft)
310
+ .then((x) => x.body)
311
+
312
+ assert(cart, 'cart not created')
313
+
314
+ const response = await supertest(ctMock.app)
315
+ .post(`/dummy/carts/${cart.id}`)
316
+ .send({
317
+ version: 1,
318
+ actions: [
319
+ {
320
+ action: 'recalculate',
321
+ updateProductData: true,
322
+ },
323
+ ],
324
+ })
325
+
326
+ expect(response.status).toBe(200)
327
+ expect(response.body.version).toBe(1)
328
+ })
329
+
306
330
  test('removeLineItem', async () => {
307
331
  const product = await supertest(ctMock.app)
308
332
  .post(`/dummy/products`)