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] = {
21 [uniqueId()]: undefined,
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 });
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({
43 settings: INITIAL_ORGANIZATION_SETTINGS,
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);