Skip to content

Commit

Permalink
Merge branch 'master' into CKT-2616_update-tax-rate-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniolodias authored Sep 19, 2024
2 parents a9b1b43 + 1947ded commit c92cbac
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/sync-actions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @commercetools/sync-actions

## 5.19.1

### Patch Changes

- [#1912](https://github.com/commercetools/nodejs/pull/1912) [`06866537`](https://github.com/commercetools/nodejs/commit/06866537feb04eaf26521d43b654cbc2920bab0d) Thanks [@markus-azer](https://github.com/markus-azer)! - Fix product action groups category order hints

## 5.19.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/sync-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": ">=14"
},
"name": "@commercetools/sync-actions",
"version": "5.19.0",
"version": "5.19.1",
"description": "Build API update actions for the commercetools platform.",
"keywords": [
"commercetools",
Expand Down
2 changes: 1 addition & 1 deletion packages/sync-actions/src/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function createProductMapActions(
)

allActions.push(
mapActionGroup('categories', (): Array<UpdateAction> =>
mapActionGroup('categoryOrderHints', (): Array<UpdateAction> =>
productActions.actionsMapCategoryOrderHints(diff, oldObj)
)
)
Expand Down
126 changes: 126 additions & 0 deletions packages/sync-actions/test/product-sync-base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,132 @@ describe('Actions', () => {
expect(actions).toEqual([])
})

test('shouldnt generate any categoryOrderHints actions in case of disallowed', () => {
const productsSyncWithIgnore = productsSyncFn([
{ type: 'categoryOrderHints', group: 'ignore' },
])

const before = {
categoryOrderHints: {
'123e844e-0616-420a-8397-a22c48d5e99f': '0.1',
'aebe844e-0616-420a-8397-a22c48d5e99f': '0.2',
},
}

const now = {
categoryOrderHints: {
'123e844e-0616-420a-8397-a22c48d5e99f': '0.1', // will be ignored
'aebe844e-0616-420a-8397-a22c48d5e99f': '0.5', // updated but will be ignored
},
}

const actions = productsSyncWithIgnore.buildActions(now, before)

expect(actions).toEqual([])
})

test('should generate categoryOrderHints actions and ignore categories', () => {
const productsSyncWithIgnore = productsSyncFn([
{ type: 'categoryOrderHints', group: 'allow' },
{ type: 'categories', group: 'ignore' },
])

const before = {
categories: [
{ id: '123e844e-0616-420a-8397-a22c48d5e99f' }, // will be ignored
{ id: 'aebe844e-0616-420a-8397-a22c48d5e99f' }, // will be ignored
{ id: '34cae6ad-5898-4f94-973b-ae9ceb7464ce' }, // will be ignored
],
categoryOrderHints: {
'123e844e-0616-420a-8397-a22c48d5e99f': '0.1',
'aebe844e-0616-420a-8397-a22c48d5e99f': '0.2',
'34cae6ad-5898-4f94-973b-ae9ceb7464ce': '0.5',
},
}

const now = {
categories: [
{ id: '123e844e-0616-420a-8397-a22c48d5e99f' },
{ id: 'aebe844e-0616-420a-8397-a22c48d5e99f' },
{ id: 'cca7a250-d8cf-4b8a-9d47-60fcc093b86b' },
],
categoryOrderHints: {
'123e844e-0616-420a-8397-a22c48d5e99f': '0.1',
'aebe844e-0616-420a-8397-a22c48d5e99f': '0.5',
'cca7a250-d8cf-4b8a-9d47-60fcc093b86b': '0.999',
},
}

const actions = productsSyncWithIgnore.buildActions(now, before)

expect(actions).toEqual([
{
action: 'setCategoryOrderHint',
categoryId: 'aebe844e-0616-420a-8397-a22c48d5e99f',
orderHint: '0.5',
},
{
action: 'setCategoryOrderHint',
categoryId: '34cae6ad-5898-4f94-973b-ae9ceb7464ce',
},
{
action: 'setCategoryOrderHint',
categoryId: 'cca7a250-d8cf-4b8a-9d47-60fcc093b86b',
orderHint: '0.999',
},
])
})

test('should generate categories actions and ignore categoryOrderHints', () => {
const productsSyncWithIgnore = productsSyncFn([
{ type: 'categoryOrderHints', group: 'ignore' },
{ type: 'categories', group: 'allow' },
])

const before = {
categories: [
{ id: '123e844e-0616-420a-8397-a22c48d5e99f' },
{ id: 'aebe844e-0616-420a-8397-a22c48d5e99f' },
{ id: '34cae6ad-5898-4f94-973b-ae9ceb7464ce' },
],
categoryOrderHints: {
'123e844e-0616-420a-8397-a22c48d5e99f': '0.1', // will be ignored
'aebe844e-0616-420a-8397-a22c48d5e99f': '0.2', // will be ignored
'34cae6ad-5898-4f94-973b-ae9ceb7464ce': '0.5', // will be ignored
},
}

const now = {
categories: [
{ id: '123e844e-0616-420a-8397-a22c48d5e99f' },
{ id: 'aebe844e-0616-420a-8397-a22c48d5e99f' },
{ id: 'cca7a250-d8cf-4b8a-9d47-60fcc093b86b' },
],
categoryOrderHints: {
'123e844e-0616-420a-8397-a22c48d5e99f': '0.1',
'aebe844e-0616-420a-8397-a22c48d5e99f': '0.5',
'cca7a250-d8cf-4b8a-9d47-60fcc093b86b': '0.999',
},
}

const actions = productsSyncWithIgnore.buildActions(now, before)

expect(actions).toEqual([
{
action: 'removeFromCategory',
category: {
id: '34cae6ad-5898-4f94-973b-ae9ceb7464ce',
},
},
{
action: 'addToCategory',
category: {
id: 'cca7a250-d8cf-4b8a-9d47-60fcc093b86b',
},
},
])
})

test('shouldnt generate any searchKeywords actions', () => {
const before = {
searchKeywords: {},
Expand Down

0 comments on commit c92cbac

Please sign in to comment.