diff --git a/.changeset/cyan-taxis-judge.md b/.changeset/cyan-taxis-judge.md new file mode 100644 index 000000000..0580e0466 --- /dev/null +++ b/.changeset/cyan-taxis-judge.md @@ -0,0 +1,5 @@ +--- +'@commercetools/sync-actions': minor +--- + +Add custom fields sync for shipping methods diff --git a/packages/sync-actions/src/shipping-methods.js b/packages/sync-actions/src/shipping-methods.js index 8ea08c806..7e6f3d6f3 100644 --- a/packages/sync-actions/src/shipping-methods.js +++ b/packages/sync-actions/src/shipping-methods.js @@ -8,10 +8,11 @@ import type { } from 'types/sdk' import createBuildActions from './utils/create-build-actions' import createMapActionGroup from './utils/create-map-action-group' +import actionsMapCustom from './utils/action-map-custom' import * as shippingMethodsActions from './shipping-methods-actions' import * as diffpatcher from './utils/diffpatcher' -export const actionGroups = ['base', 'zoneRates'] +export const actionGroups = ['base', 'zoneRates', 'custom'] function createShippingMethodsMapActions( mapActionGroup: Function, @@ -40,6 +41,9 @@ function createShippingMethodsMapActions( ) ) ) + allActions.push( + mapActionGroup('custom', () => actionsMapCustom(diff, newObj, oldObj)) + ) return flatten(allActions) } } diff --git a/packages/sync-actions/test/shipping-methods.spec.js b/packages/sync-actions/test/shipping-methods.spec.js index cb1c2aff1..8c2bcf255 100644 --- a/packages/sync-actions/test/shipping-methods.spec.js +++ b/packages/sync-actions/test/shipping-methods.spec.js @@ -3,7 +3,7 @@ import { baseActionsList } from '../src/shipping-methods-actions' describe('Exports', () => { test('action group list', () => { - expect(actionGroups).toEqual(['base', 'zoneRates']) + expect(actionGroups).toEqual(['base', 'zoneRates', 'custom']) }) test('correctly define base actions list', () => { @@ -530,4 +530,68 @@ describe('Actions', () => { expect(actual).toEqual(expected) }) }) + + describe('custom fields', () => { + test('should build `setCustomType` action', () => { + const before = { + custom: { + type: { + typeId: 'type', + id: 'customType1', + }, + fields: { + customField1: true, + }, + }, + } + const now = { + custom: { + type: { + typeId: 'type', + id: 'customType2', + }, + fields: { + customField1: true, + }, + }, + } + const actual = shippingMethodsSync.buildActions(now, before) + const expected = [{ action: 'setCustomType', ...now.custom }] + expect(actual).toEqual(expected) + }) + + test('should build `setCustomField` action', () => { + const before = { + custom: { + type: { + typeId: 'type', + id: 'customType1', + }, + fields: { + customField1: false, + }, + }, + } + const now = { + custom: { + type: { + typeId: 'type', + id: 'customType1', + }, + fields: { + customField1: true, + }, + }, + } + const actual = shippingMethodsSync.buildActions(now, before) + const expected = [ + { + action: 'setCustomField', + name: 'customField1', + value: true, + }, + ] + expect(actual).toEqual(expected) + }) + }) })