mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 01:37:24 +03:00
Ensured settings migration function does not crash if settings are not set
This commit is contained in:
parent
af0d2d3cdc
commit
e77b4d7a82
2 changed files with 9 additions and 1 deletions
|
@ -1,6 +1,10 @@
|
|||
import { ShlinkState } from '../../container/types';
|
||||
|
||||
export const migrateDeprecatedSettings = (state: ShlinkState): ShlinkState => {
|
||||
export const migrateDeprecatedSettings = (state: Partial<ShlinkState>): Partial<ShlinkState> => {
|
||||
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');
|
||||
|
|
|
@ -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<ShlinkState>({
|
||||
settings: {
|
||||
|
|
Loading…
Reference in a new issue