Skip to content

Commit

Permalink
feat(sync-actions): add setPriceMode sync action (#1788)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicolasnieto92 authored Jun 24, 2022
1 parent 25cb3f3 commit f1acfb6
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-squids-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools/sync-actions': minor
---

Add setPriceMode sync action for commercetools-importer project
18 changes: 8 additions & 10 deletions packages/sync-actions/src/product-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/sync-actions/test/product-sync-base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('Exports', () => {
{ action: 'setDescription', key: 'description' },
{ action: 'setSearchKeywords', key: 'searchKeywords' },
{ action: 'setKey', key: 'key' },
{ action: 'setPriceMode', key: 'priceMode' },
])
})

Expand Down
99 changes: 99 additions & 0 deletions packages/sync-actions/test/product-sync-variants.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit f1acfb6

Please sign in to comment.