Skip to content

Commit

Permalink
feat: sync custom fields for shipping methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AlesJiranek committed May 17, 2022
1 parent fe7d2f1 commit 1b95d42
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-taxis-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools/sync-actions': minor
---

Add custom fields sync for shipping methods
6 changes: 5 additions & 1 deletion packages/sync-actions/src/shipping-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -40,6 +41,9 @@ function createShippingMethodsMapActions(
)
)
)
allActions.push(
mapActionGroup('custom', () => actionsMapCustom(diff, newObj, oldObj))
)
return flatten(allActions)
}
}
Expand Down
66 changes: 65 additions & 1 deletion packages/sync-actions/test/shipping-methods.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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)
})
})
})

0 comments on commit 1b95d42

Please sign in to comment.