Skip to content

Commit 94a376c

Browse files
authored
BMU-401 fix(sync-actions): fix type sync-actions errors (#1852)
* fix(sync-actions): fix type sync-actions errors * test(sync-actions): update test description * ci(sync-actions): add changeset
1 parent b7d3eb1 commit 94a376c

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

.changeset/rich-taxis-shake.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@commercetools/sync-actions': minor
3+
---
4+
5+
types sync-actions: fix action structure for changeFieldDefinitionOrder
6+
fix internal type sync error by adding optional chaining

packages/sync-actions/src/types-actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function actionsMapFieldDefinitions(
136136
label: extractedPairs.newObj.label,
137137
fieldName: extractedPairs.oldObj.name,
138138
})
139-
} else if (diffValue.type.values) {
139+
} else if (diffValue?.type?.values) {
140140
actions.push(
141141
...actionsMapEnums(
142142
extractedPairs.oldObj.name,
@@ -152,7 +152,7 @@ export function actionsMapFieldDefinitions(
152152
if (diffValue.length === 3 && diffValue[2] === 3) {
153153
actions.push({
154154
action: 'changeFieldDefinitionOrder',
155-
fieldNames: next,
155+
fieldNames: next.map((n) => n.name),
156156
})
157157
} else {
158158
const deltaValue = diffPatcher.getDeltaValue(diffValue)

packages/sync-actions/test/types-sync-fields.spec.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('Actions', () => {
110110
expect(updateActions).toEqual([
111111
{
112112
action: 'changeFieldDefinitionOrder',
113-
fieldNames: [{ name: 'second' }, { name: 'first' }],
113+
fieldNames: ['second', 'first'],
114114
},
115115
])
116116
})
@@ -336,4 +336,35 @@ describe('Actions', () => {
336336
])
337337
})
338338
})
339+
340+
/**
341+
* there is no update action for fieldDefinition -> required,
342+
* so this field is immutable and unchangeable.
343+
* in case of changing it, this were throwing `Cannot read properties of undefined` cause its nested field.
344+
* below test is making sure this field is ignored and without any internal package errors.
345+
*/
346+
describe('should ignore changes in required field in fieldDefinition', () => {
347+
beforeEach(() => {
348+
before = createTestType({
349+
fieldDefinitions: [
350+
{
351+
name: 'first',
352+
required: true,
353+
},
354+
],
355+
})
356+
now = createTestType({
357+
fieldDefinitions: [
358+
{
359+
name: 'first',
360+
required: false,
361+
},
362+
],
363+
})
364+
updateActions = typesSync.buildActions(now, before)
365+
})
366+
test('should return no action', () => {
367+
expect(updateActions).toEqual([])
368+
})
369+
})
339370
})

0 commit comments

Comments
 (0)