Skip to content

Commit

Permalink
fix(ignore): Fix 2 to 3 migration enabling frontend/availabilty/homea…
Browse files Browse the repository at this point in the history
…ssistant when not set (#25349)
  • Loading branch information
Koenkk authored Dec 30, 2024
1 parent 47d73eb commit 02666e9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/util/settingsMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/settingsMigration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 02666e9

Please sign in to comment.