Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / migrate.spec.ts
blob321b386d0f2e227ac891b18a1023f87458439377
1 import { createTestItem } from '@proton/pass/lib/items/item.test.utils';
2 import { uniqueId } from '@proton/pass/utils/string/unique-id';
4 import { migrate } from './migrate';
5 import { INITIAL_HIGHSECURITY_SETTINGS, rootReducer } from './reducers';
6 import { INITIAL_ORGANIZATION_SETTINGS } from './reducers/organization';
8 describe('migrate', () => {
9     test('should sanitize invalid items', () => {
10         const state = rootReducer(undefined, { type: '__TEST__' });
11         const shareId = uniqueId();
13         const login = createTestItem('login');
14         const note = createTestItem('note', { shareId });
16         state.items.byShareId[login.shareId] = { [login.itemId]: login };
18         state.items.byShareId[shareId] = {
19             [uniqueId()]: {},
20             [uniqueId()]: null,
21             [uniqueId()]: undefined,
22             [uniqueId()]: false,
23             [note.itemId]: note,
24         } as any;
26         const migration = migrate(state);
28         expect(migration.items.byShareId[shareId]).toStrictEqual({ [note.itemId]: note });
29         expect(migration.items.byShareId[login.shareId]).toStrictEqual({ [login.itemId]: login });
30     });
32     test('should move organization data out of user state', () => {
33         const state = rootReducer(undefined, { type: '__TEST__' });
34         const organization = { ID: uniqueId(), Name: 'ProtonB2B' };
35         state.user = { organization } as any;
36         const migration = migrate(state);
38         expect('organization' in migration.user).toBe(false);
40         expect(migration.organization).toStrictEqual({
41             organization,
42             canUpdate: false,
43             settings: INITIAL_ORGANIZATION_SETTINGS,
44         });
45     });
47     test('should hydrate initial `HighSecurity` settings if empty', () => {
48         const state = rootReducer(undefined, { type: '__TEST__' });
49         state.user.userSettings = {} as any;
50         const migration = migrate(state);
52         expect(migration.user.userSettings!.HighSecurity).toStrictEqual(INITIAL_HIGHSECURITY_SETTINGS);
53     });
54 });