Skip to content

Commit 82c22b7

Browse files
committed
Fix migration dryrun on nested properties
1 parent ee5d807 commit 82c22b7

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

packages/bygger-backend/src/migration/filterUtils.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
componentWithAdvancedConditionalToRadio,
44
componentWithSimpleConditionalToRadio,
55
formWithSimpleConditionalToRadio,
6+
originalOtherDocumentationAttachmentComponent,
67
originalTextFieldComponent,
78
} from './testData';
89

@@ -70,6 +71,18 @@ describe('filterUtils', () => {
7071
).toBe(false);
7172
});
7273

74+
it('handles nested properties with three levels', () => {
75+
expect(
76+
targetMatchesFilters(originalOtherDocumentationAttachmentComponent, [
77+
{
78+
key: 'attachmentValues.leggerVedNaa.enabled',
79+
value: null,
80+
operator: 'exists',
81+
},
82+
]),
83+
).toBe(true);
84+
});
85+
7386
describe('With operators', () => {
7487
const typeEqTextfield = { key: 'type', value: 'textfield' };
7588
const typeEqRadio = { key: 'type', value: 'radio' };

packages/bygger-backend/src/migration/filterUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function parseFiltersFromParam(filtersFromParam: object): Filter[] {
2121
}
2222

2323
function getPropertyFromTarget(comp: any, properties: string[]): string | undefined {
24-
if (properties.length > 1) {
24+
if (properties.length > 1 && comp[properties[0]]) {
2525
return getPropertyFromTarget(comp[properties[0]], properties.slice(1));
2626
}
2727
return comp && comp[properties[0]];

packages/bygger-backend/src/migration/testData.ts

+25
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ const originalFodselsnummerComponent = {
6161
tableView: true,
6262
};
6363

64+
const originalOtherDocumentationAttachmentComponent: Component = {
65+
key: 'annenDokumentasjon',
66+
type: 'attachment',
67+
input: true,
68+
label: 'Annen dokumentasjon',
69+
validate: {
70+
required: true,
71+
},
72+
properties: {
73+
vedleggskode: 'N6',
74+
vedleggstittel: 'Annet',
75+
},
76+
description: 'Har du noen annen dokumentasjon du ønsker å legge ved?',
77+
attachmentType: 'other',
78+
attachmentValues: {
79+
nei: {
80+
enabled: true,
81+
},
82+
leggerVedNaa: {
83+
enabled: true,
84+
},
85+
},
86+
};
87+
6488
const originalForm: NavFormType = {
6589
path: 'testform',
6690
components: [originalFodselsnummerComponent, originalTextFieldComponent],
@@ -189,6 +213,7 @@ export {
189213
formWithSimpleConditionalToRadio,
190214
originalFodselsnummerComponent,
191215
originalForm,
216+
originalOtherDocumentationAttachmentComponent,
192217
originalPanelComponent,
193218
originalSkjemaGruppeComponent,
194219
originalTextFieldComponent,

0 commit comments

Comments
 (0)