Skip to content

Commit 9e15350

Browse files
authored
feat(sync-actions/stores): add support custom fields actions on store level (#1638)
1 parent 6af9fc6 commit 9e15350

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed

packages/sync-actions/src/stores.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import flatten from 'lodash.flatten'
33
import type { SyncAction, UpdateAction, ActionGroup } from 'types/sdk'
44
import createBuildActions from './utils/create-build-actions'
55
import createMapActionGroup from './utils/create-map-action-group'
6+
import actionsMapCustom from './utils/action-map-custom'
67
import * as storesActions from './stores-actions'
78
import * as diffpatcher from './utils/diffpatcher'
89

@@ -24,11 +25,19 @@ function createStoresMapActions(
2425
next: Object,
2526
previous: Object
2627
): Array<UpdateAction> {
27-
return flatten([
28+
const allActions = []
29+
allActions.push(
2830
mapActionGroup('base', (): Array<UpdateAction> =>
2931
storesActions.actionsMapBase(diff, previous, next)
30-
),
31-
])
32+
)
33+
)
34+
allActions.push(
35+
mapActionGroup('custom', (): Array<UpdateAction> =>
36+
actionsMapCustom(diff, next, previous)
37+
)
38+
)
39+
40+
return flatten(allActions)
3241
}
3342
}
3443

packages/sync-actions/test/stores-sync.spec.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,68 @@ describe('Actions', () => {
108108
},
109109
])
110110
})
111+
112+
describe('custom fields', () => {
113+
test('should build `setCustomType` action', () => {
114+
const before = {
115+
custom: {
116+
type: {
117+
typeId: 'type',
118+
id: 'customType1',
119+
},
120+
fields: {
121+
customField1: true,
122+
},
123+
},
124+
}
125+
const now = {
126+
custom: {
127+
type: {
128+
typeId: 'type',
129+
id: 'customType2',
130+
},
131+
fields: {
132+
customField1: true,
133+
},
134+
},
135+
}
136+
const actual = storesSync.buildActions(now, before)
137+
const expected = [{ action: 'setCustomType', ...now.custom }]
138+
expect(actual).toEqual(expected)
139+
})
140+
})
141+
142+
test('should build `setCustomField` action', () => {
143+
const before = {
144+
custom: {
145+
type: {
146+
typeId: 'type',
147+
id: 'customType1',
148+
},
149+
fields: {
150+
customField1: false,
151+
},
152+
},
153+
}
154+
const now = {
155+
custom: {
156+
type: {
157+
typeId: 'type',
158+
id: 'customType1',
159+
},
160+
fields: {
161+
customField1: true,
162+
},
163+
},
164+
}
165+
const actual = storesSync.buildActions(now, before)
166+
const expected = [
167+
{
168+
action: 'setCustomField',
169+
name: 'customField1',
170+
value: true,
171+
},
172+
]
173+
expect(actual).toEqual(expected)
174+
})
111175
})

0 commit comments

Comments
 (0)