Skip to content

Commit

Permalink
feat: to add custom fields to shipping method (#1841)
Browse files Browse the repository at this point in the history
* feat: to add custom fields to shipping method

* Create .changeset/healthy-glasses-prove.md

* include custom into actionGroups(shippingMethods) and add two unit tests

* Update packages/sync-actions/src/shipping-methods.js
  • Loading branch information
Rombelirk authored Mar 3, 2023
1 parent 96e1318 commit b90c723
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-glasses-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@commercetools/sync-actions": minor
---

Add Custom Fields to Shipping Methods.
8 changes: 7 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,11 @@ function createShippingMethodsMapActions(
)
)
)
allActions.push(
mapActionGroup('custom', (): Array<UpdateAction> =>
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 b90c723

Please sign in to comment.