Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .changeset/bumpy-clouds-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@commercetools/sync-actions': patch
---

Added the following recurring orders sync actions

- setOrderSkipConfiguration
- setStartsAt
- setExpiresAt
- setSchedule
21 changes: 20 additions & 1 deletion packages/sync-actions/src/recurring-orders-actions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { buildBaseAttributesActions } from './utils/common-actions'
import {
buildBaseAttributesActions,
buildReferenceActions,
} from './utils/common-actions'

export const baseActionsList = [
{ action: 'setKey', key: 'key' },
{ action: 'setRecurringOrderState', key: 'recurringOrderState' },
{ action: 'transitionState', key: 'state' },
{ action: 'setOrderSkipConfiguration', key: 'skipConfiguration' },
{ action: 'setStartsAt', key: 'startsAt' },
{ action: 'setExpiresAt', key: 'expiresAt' },
]

export const referenceActionsList = [
{ action: 'setSchedule', key: 'recurrencePolicy' },
]

export function actionsMapBase(diff, oldObj, newObj, config = {}) {
Expand All @@ -18,3 +28,12 @@ export function actionsMapBase(diff, oldObj, newObj, config = {}) {
config.shouldPreventUnsettingRequiredFields,
})
}

export function actionsMapReferences(diff, oldObj, newObj) {
return buildReferenceActions({
actions: referenceActionsList,
diff,
oldObj,
newObj,
})
}
8 changes: 7 additions & 1 deletion packages/sync-actions/src/recurring-orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import actionsMapCustom from './utils/action-map-custom'
import * as RecurringOrdersActions from './recurring-orders-actions'
import * as diffpatcher from './utils/diffpatcher'

const actionGroups = ['base', 'custom']
const actionGroups = ['base', 'references', 'custom']

function createRecurringOrdersMapActions(
mapActionGroup: Function,
Expand Down Expand Up @@ -41,6 +41,12 @@ function createRecurringOrdersMapActions(
)
)

allActions.push(
mapActionGroup('references', (): Array<UpdateAction> =>
RecurringOrdersActions.actionsMapReferences(diff, oldObj, newObj)
)
)

allActions.push(
mapActionGroup('custom', (): Array<UpdateAction> =>
actionsMapCustom(diff, newObj, oldObj)
Expand Down
108 changes: 105 additions & 3 deletions packages/sync-actions/test/recurring-orders-sync.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import createRecurringOrdersSync, {
actionGroups,
} from '../src/recurring-orders'
import { baseActionsList } from '../src/recurring-orders-actions'
import {
baseActionsList,
referenceActionsList,
} from '../src/recurring-orders-actions'

describe('Exports', () => {
test('action group list', () => {
expect(actionGroups).toEqual(['base', 'custom'])
expect(actionGroups).toEqual(['base', 'references', 'custom'])
})

describe('action list', () => {
describe('base action list', () => {
test('should contain `setRecurringOrderState` action', () => {
expect(baseActionsList).toEqual(
expect.arrayContaining([
Expand All @@ -28,11 +31,42 @@ describe('Exports', () => {
expect.arrayContaining([{ action: 'transitionState', key: 'state' }])
)
})

test('should contain `setOrderSkipConfiguration` action', () => {
expect(baseActionsList).toEqual(
expect.arrayContaining([
{ action: 'setOrderSkipConfiguration', key: 'skipConfiguration' },
])
)
})

test('should contain `setStartsAt` action', () => {
expect(baseActionsList).toEqual(
expect.arrayContaining([{ action: 'setStartsAt', key: 'startsAt' }])
)
})

test('should contain `setExpiresAt` action', () => {
expect(baseActionsList).toEqual(
expect.arrayContaining([{ action: 'setExpiresAt', key: 'expiresAt' }])
)
})
})

describe('reference action list', () => {
test('should contain `recurrencePolicy` action', () => {
expect(referenceActionsList).toEqual(
expect.arrayContaining([
{ action: 'setSchedule', key: 'recurrencePolicy' },
])
)
})
})
})

describe('Actions', () => {
let recurringOrdersSync

beforeEach(() => {
recurringOrdersSync = createRecurringOrdersSync()
})
Expand Down Expand Up @@ -86,6 +120,50 @@ describe('Actions', () => {
expect(actual).toEqual(expected)
})

test('should build `setOrderSkipConfiguration` action', () => {
const before = {
skipConfiguration: { type: 'counter', totalToSkip: 2, skipped: 1 },
}
const now = {
skipConfiguration: { type: 'counter', totalToSkip: 5 },
}

const expected = [
{
action: 'setOrderSkipConfiguration',
...now,
},
]
const actual = recurringOrdersSync.buildActions(now, before)
expect(actual).toEqual(expected)
})

test('should build `setStartsAt` action', () => {
const before = { startsAt: '2025-10-01T00:00:00.000Z' }
const now = { startsAt: '2026-01-10T00:00:00.000Z' }
const actual = recurringOrdersSync.buildActions(now, before)
const expected = [
{
action: 'setStartsAt',
...now,
},
]
expect(actual).toEqual(expected)
})

test('should build `setExpiresAt` action', () => {
const before = { expiresAt: '2025-10-01T00:00:00.000Z' }
const now = { expiresAt: '2026-01-10T00:00:00.000Z' }
const actual = recurringOrdersSync.buildActions(now, before)
const expected = [
{
action: 'setExpiresAt',
...now,
},
]
expect(actual).toEqual(expected)
})

test('should build `setCustomType` action', () => {
const before = {
custom: {
Expand Down Expand Up @@ -147,4 +225,28 @@ describe('Actions', () => {
]
expect(actual).toEqual(expected)
})

test('should build `setSchedule` action', () => {
const before = {
recurrencePolicy: {
typeId: 'recurrence-policy',
id: '999-9999-9999',
},
}
const now = {
recurrencePolicy: {
typeId: 'recurrence-policy',
id: '1212-1212-1212',
},
}

const actual = recurringOrdersSync.buildActions(now, before)
const expected = [
{
action: 'setSchedule',
...now,
},
]
expect(actual).toEqual(expected)
})
})