diff --git a/src/settings/helpers/index.ts b/src/settings/helpers/index.ts index a405e827..160c5434 100644 --- a/src/settings/helpers/index.ts +++ b/src/settings/helpers/index.ts @@ -1,6 +1,10 @@ import { ShlinkState } from '../../container/types'; -export const migrateDeprecatedSettings = (state: ShlinkState): ShlinkState => { +export const migrateDeprecatedSettings = (state: Partial): Partial => { + if (!state.settings) { + return state; + } + // The "last180Days" interval had a typo, with a lowercase d if ((state.settings.visits?.defaultInterval as any) === 'last180days') { state.settings.visits && (state.settings.visits.defaultInterval = 'last180Days'); diff --git a/test/settings/helpers/index.test.ts b/test/settings/helpers/index.test.ts index 0a3b349e..ba313125 100644 --- a/test/settings/helpers/index.test.ts +++ b/test/settings/helpers/index.test.ts @@ -4,6 +4,10 @@ import { ShlinkState } from '../../../src/container/types'; describe('settings-helpers', () => { describe('migrateDeprecatedSettings', () => { + it('returns object as is if settings are not set', () => { + expect(migrateDeprecatedSettings({})).toEqual({}); + }); + it('updates settings as expected', () => { const state = Mock.of({ settings: {