From f1acfb67708d8253f551481fd65097add48c6686 Mon Sep 17 00:00:00 2001 From: nicolasnieto92 <91725970+nicolasnieto92@users.noreply.github.com> Date: Fri, 24 Jun 2022 13:25:50 +0200 Subject: [PATCH] feat(sync-actions): add setPriceMode sync action (#1788) * feat(sync-actions): add setPriceMode sync action * test(sync-actions): add test for setPriceMode action * docs(sync-actions): add changeset * refactor(sync-actions): add integration test and add setPriceMode to baseActionsList * refactor(sync-actions): add setPriceMode action on product-sync-base test --- .changeset/little-squids-build.md | 5 + packages/sync-actions/src/product-actions.js | 18 ++-- .../test/product-sync-base.spec.js | 1 + .../test/product-sync-variants.spec.js | 99 +++++++++++++++++++ 4 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 .changeset/little-squids-build.md diff --git a/.changeset/little-squids-build.md b/.changeset/little-squids-build.md new file mode 100644 index 000000000..890963995 --- /dev/null +++ b/.changeset/little-squids-build.md @@ -0,0 +1,5 @@ +--- +'@commercetools/sync-actions': minor +--- + +Add setPriceMode sync action for commercetools-importer project diff --git a/packages/sync-actions/src/product-actions.js b/packages/sync-actions/src/product-actions.js index 815352c42..c67c75d35 100644 --- a/packages/sync-actions/src/product-actions.js +++ b/packages/sync-actions/src/product-actions.js @@ -23,6 +23,7 @@ export const baseActionsList = [ { action: 'setDescription', key: 'description' }, { action: 'setSearchKeywords', key: 'searchKeywords' }, { action: 'setKey', key: 'key' }, + { action: 'setPriceMode', key: 'priceMode' }, ] export const baseAssetActionsList = [ @@ -707,16 +708,13 @@ export function actionsMapPrices( newObj.variants ) if (REGEX_UNDERSCORE_NUMBER.test(key) || REGEX_NUMBER.test(key)) { - const [ - addPriceAction, - changePriceAction, - removePriceAction, - ] = _buildVariantPricesAction( - variant.prices, - oldVariant, - newVariant, - enableDiscounted - ) + const [addPriceAction, changePriceAction, removePriceAction] = + _buildVariantPricesAction( + variant.prices, + oldVariant, + newVariant, + enableDiscounted + ) addPriceActions = addPriceActions.concat(addPriceAction) changePriceActions = changePriceActions.concat(changePriceAction) diff --git a/packages/sync-actions/test/product-sync-base.spec.js b/packages/sync-actions/test/product-sync-base.spec.js index 8638bbfde..959b91ed7 100644 --- a/packages/sync-actions/test/product-sync-base.spec.js +++ b/packages/sync-actions/test/product-sync-base.spec.js @@ -29,6 +29,7 @@ describe('Exports', () => { { action: 'setDescription', key: 'description' }, { action: 'setSearchKeywords', key: 'searchKeywords' }, { action: 'setKey', key: 'key' }, + { action: 'setPriceMode', key: 'priceMode' }, ]) }) diff --git a/packages/sync-actions/test/product-sync-variants.spec.js b/packages/sync-actions/test/product-sync-variants.spec.js index 96dd7966b..2f7421023 100644 --- a/packages/sync-actions/test/product-sync-variants.spec.js +++ b/packages/sync-actions/test/product-sync-variants.spec.js @@ -1022,6 +1022,105 @@ describe('Actions', () => { ]) }) + test('should build `setPriceMode` action', async () => { + const before = { + masterVariant: { + id: 1, + prices: [], + images: [], + attributes: [], + assets: [], + }, + variants: [], + } + + const now = { + masterVariant: { + id: 1, + prices: [], + images: [], + attributes: [], + assets: [], + }, + variants: [], + priceMode: 'Standalone', + } + + const actions = productsSync.buildActions(now, before) + + expect(actions).toEqual([ + { + action: 'setPriceMode', + priceMode: 'Standalone', + }, + ]) + }) + + test('should not build `setPriceMode` action if priceModes did not change', async () => { + const before = { + masterVariant: { + id: 1, + prices: [], + images: [], + attributes: [], + assets: [], + }, + variants: [], + priceMode: 'Embedded', + } + + const now = { + masterVariant: { + id: 1, + prices: [], + images: [], + attributes: [], + assets: [], + }, + variants: [], + priceMode: 'Embedded', + } + + const actions = productsSync.buildActions(now, before) + + expect(actions).toHaveLength(0) + }) + + test('should change `setPriceMode` action', async () => { + const before = { + masterVariant: { + id: 1, + prices: [], + images: [], + attributes: [], + assets: [], + }, + variants: [], + priceMode: 'Embedded', + } + + const now = { + masterVariant: { + id: 1, + prices: [], + images: [], + attributes: [], + assets: [], + }, + variants: [], + priceMode: 'Standalone', + } + + const actions = productsSync.buildActions(now, before) + + expect(actions).toEqual([ + { + action: 'setPriceMode', + priceMode: 'Standalone', + }, + ]) + }) + describe('assets', () => { test('should build "addAsset" action with empty assets', () => { const before = {