Skip to content

Commit 7d17205

Browse files
authored
fix(sync-actions): changing order of actions (#1662)
1 parent 4c463b0 commit 7d17205

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

packages/sync-actions/src/product-actions.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,18 +437,23 @@ export function actionsMapMeta(diff, oldObj, newObj) {
437437
})
438438
}
439439

440-
export function actionsMapVariants(diff, oldObj, newObj) {
440+
export function actionsMapAddVariants(diff, oldObj, newObj) {
441441
const handler = createBuildArrayActions('variants', {
442442
[ADD_ACTIONS]: (newObject) => ({
443443
...newObject,
444444
action: 'addVariant',
445445
}),
446+
})
447+
return handler(diff, oldObj, newObj)
448+
}
449+
450+
export function actionsMapRemoveVariants(diff, oldObj, newObj) {
451+
const handler = createBuildArrayActions('variants', {
446452
[REMOVE_ACTIONS]: ({ id }) => ({
447453
action: 'removeVariant',
448454
id,
449455
}),
450456
})
451-
452457
return handler(diff, oldObj, newObj)
453458
}
454459

packages/sync-actions/src/products.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ function createProductMapActions(
6565

6666
allActions.push(
6767
mapActionGroup('variants', (): Array<UpdateAction> =>
68-
productActions.actionsMapVariants(diff, oldObj, newObj)
68+
productActions.actionsMapAddVariants(diff, oldObj, newObj)
69+
)
70+
)
71+
72+
allActions.push(productActions.actionsMapMasterVariant(oldObj, newObj))
73+
74+
allActions.push(
75+
mapActionGroup('variants', (): Array<UpdateAction> =>
76+
productActions.actionsMapRemoveVariants(diff, oldObj, newObj)
6977
)
7078
)
7179

@@ -87,8 +95,6 @@ function createProductMapActions(
8795
)
8896
)
8997

90-
allActions.push(productActions.actionsMapMasterVariant(oldObj, newObj))
91-
9298
allActions.push(
9399
mapActionGroup('images', (): Array<UpdateAction> =>
94100
productActions.actionsMapImages(diff, oldObj, newObj, variantHashMap)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@ describe('Actions', () => {
304304
}
305305
const actions = productsSync.buildActions(now, before)
306306
expect(actions).toEqual([
307-
{
308-
action: 'removeVariant',
309-
id: 10,
310-
},
311307
{
312308
action: 'changeMasterVariant',
313309
variantId: 1,
314310
},
311+
{
312+
action: 'removeVariant',
313+
id: 10,
314+
},
315315
{
316316
action: 'moveImageToPosition',
317317
variantId: 1,
@@ -454,14 +454,14 @@ describe('Actions', () => {
454454

455455
const actions = productsSync.buildActions(now, before)
456456
expect(actions).toEqual([
457-
{
458-
action: 'removeVariant',
459-
id: 10,
460-
},
461457
{
462458
action: 'changeMasterVariant',
463459
variantId: 1,
464460
},
461+
{
462+
action: 'removeVariant',
463+
id: 10,
464+
},
465465
{
466466
action: 'removeImage',
467467
imageUrl:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ describe('Actions', () => {
269269
const actions = productsSync.buildActions(now, before)
270270

271271
expect(actions).toEqual([
272-
{ action: 'removeVariant', id: 3 },
273272
{ action: 'addVariant', ...newVariant },
273+
{ action: 'removeVariant', id: 3 },
274274
])
275275
})
276276

@@ -524,14 +524,14 @@ describe('Actions', () => {
524524
const actions = productsSync.buildActions(now, before)
525525

526526
expect(actions).toEqual([
527-
{ action: 'removeVariant', id: 1 },
528527
{
529528
action: 'addVariant',
530529
attributes: [{ name: 'foo', value: 'bar' }],
531530
id: 2,
532531
sku: 'v1',
533532
},
534533
{ action: 'changeMasterVariant', variantId: 2 },
534+
{ action: 'removeVariant', id: 1 },
535535
])
536536
})
537537
})

0 commit comments

Comments
 (0)