fix(ignore): Fix 2 to 3 migration enabling frontend/availabilty/homeassistant when not set (#25349)

This commit is contained in:
Koen Kanters
2024-12-30 14:22:18 +01:00
committed by GitHub
parent 47d73eb23a
commit 02666e9139
2 changed files with 34 additions and 3 deletions
+4 -3
View File
@@ -86,16 +86,17 @@ function setValue(currentSettings: any, path: string[], value: unknown, createPa
function getValue(currentSettings: any, path: string[]): [validPath: boolean, value: unknown] {
for (let i = 0; i < path.length; i++) {
const key = path[i];
const value = currentSettings[key];
if (i === path.length - 1) {
return [true, currentSettings[key]];
return [value !== undefined, value];
} else {
if (!currentSettings[key]) {
if (!value) {
// invalid path
break;
}
currentSettings = currentSettings[key];
currentSettings = value;
}
}
+30
View File
@@ -807,6 +807,36 @@ describe('Settings Migration', () => {
expect(migrationNotesContent).toContain(`[SPECIAL] Property 'frontend' is now always an object.`);
expect(migrationNotesContent).toContain(`[SPECIAL] Property 'availability' is now always an object.`);
});
it('Update when not set, tests that frontend/availability is not added when not set', () => {
// @ts-expect-error workaround
const beforeSettings = objectAssignDeep.noMutate({}, settings.getPersistedSettings());
// @ts-expect-error workaround
const afterSettings = objectAssignDeep.noMutate({}, settings.getPersistedSettings());
afterSettings.version = 3;
afterSettings.homeassistant = {enabled: false};
settings.set(['homeassistant'], false);
expect(settings.getPersistedSettings()).toStrictEqual(
// @ts-expect-error workaround
objectAssignDeep.noMutate(beforeSettings, {
homeassistant: false,
}),
);
settingsMigration.migrateIfNecessary();
const migratedSettings = settings.getPersistedSettings();
expect(migratedSettings).toStrictEqual(afterSettings);
const migrationNotes = mockedData.joinPath('migration-2-to-3.log');
expect(existsSync(migrationNotes)).toStrictEqual(true);
const migrationNotesContent = readFileSync(migrationNotes, 'utf8');
expect(migrationNotesContent).toContain(`[SPECIAL] Property 'homeassistant' is now always an object.`);
expect(migrationNotesContent).not.toContain(`[SPECIAL] Property 'frontend' is now always an object.`);
expect(migrationNotesContent).not.toContain(`[SPECIAL] Property 'availability' is now always an object.`);
});
});
describe('Migrates v3 to v4', () => {