Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sync custom fields for shipping methods #1783

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
})