Skip to content

Commit cc3d2b4

Browse files
authored
Merge pull request #1589 from commercetools/feat-publish-product-actions
feat(sync-actions): publish product actions
2 parents 8edba21 + b230ff3 commit cc3d2b4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/sync-actions/src/products.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function createProductMapActions(
4343
): Array<UpdateAction> {
4444
const allActions = []
4545
const { sameForAllAttributeNames } = options
46+
const { publish } = newObj
4647

4748
const variantHashMap = findMatchingPairs(
4849
diff.variants,
@@ -129,6 +130,9 @@ function createProductMapActions(
129130
)
130131
)
131132

133+
if (publish === true)
134+
return flatten(allActions).map((action) => ({ ...action, staged: false }))
135+
132136
return flatten(allActions)
133137
}
134138
}

packages/sync-actions/test/product-sync-base.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ describe('Actions', () => {
102102
expect(actions).toEqual([{ action: 'changeName', ...now }])
103103
})
104104

105+
test('should build action with `staged` flag as false', () => {
106+
const before = { name: { en: 'Car', de: 'Auto' } }
107+
const now = { name: { en: 'Sport car' }, publish: true }
108+
const actions = productsSync.buildActions(now, before)
109+
110+
expect(actions).toEqual([
111+
{ action: 'changeName', name: { en: 'Sport car' }, staged: false },
112+
])
113+
})
114+
115+
test('should build action without `staged` flag', () => {
116+
const before = { name: { en: 'Car', de: 'Auto' } }
117+
const now = { name: { en: 'Sport car' }, publish: false }
118+
const actions = productsSync.buildActions(now, before)
119+
120+
expect(actions).toEqual([
121+
{ action: 'changeName', name: { en: 'Sport car' } },
122+
])
123+
})
124+
105125
test('should build `setSearchKeywords` action', () => {
106126
/* eslint-disable max-len */
107127
const before = {

0 commit comments

Comments
 (0)