-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27795 from software-mansion-labs/ts-migration/Mov…
…eToIndexedDB [No QA][TS migration] Migrate 'MoveToIndexedDB.js' lib to TypeScript
- Loading branch information
Showing
3 changed files
with
1 addition
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
import CONST from '../../src/CONST'; | ||
import Log from '../../src/libs/Log'; | ||
import getPlatform from '../../src/libs/getPlatform'; | ||
import AddLastVisibleActionCreated from '../../src/libs/migrations/AddLastVisibleActionCreated'; | ||
import MoveToIndexedDB from '../../src/libs/migrations/MoveToIndexedDB'; | ||
import PersonalDetailsByAccountID from '../../src/libs/migrations/PersonalDetailsByAccountID'; | ||
import CheckForPreviousReportActionID from '../../src/libs/migrations/CheckForPreviousReportActionID'; | ||
import ONYXKEYS from '../../src/ONYXKEYS'; | ||
|
@@ -28,71 +25,6 @@ describe('Migrations', () => { | |
return waitForBatchedUpdates(); | ||
}); | ||
|
||
describe('MoveToIndexedDb', () => { | ||
let mockMultiSet; | ||
beforeEach(() => { | ||
getPlatform.mockImplementation(() => CONST.PLATFORM.WEB); | ||
mockMultiSet = jest.spyOn(Onyx, 'multiSet').mockImplementation(() => Promise.resolve()); | ||
localStorage.clear(); | ||
}); | ||
|
||
afterAll(() => { | ||
mockMultiSet.mockRestore(Onyx, 'multiSet'); | ||
localStorage.clear(); | ||
}); | ||
|
||
it('Should do nothing for non web/desktop platforms', () => { | ||
// Given the migration is not running on web or desktop | ||
getPlatform.mockImplementation(() => CONST.PLATFORM.ANDROID); | ||
|
||
// When the migration runs | ||
return MoveToIndexedDB().then(() => { | ||
// Then we don't expect any storage calls | ||
expect(Onyx.multiSet).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('Should do nothing when there is no old session data', () => { | ||
// Given no session in old storage medium (localStorage) | ||
localStorage.removeItem(ONYXKEYS.SESSION); | ||
|
||
// When the migration runs | ||
return MoveToIndexedDB().then(() => { | ||
// Then we don't expect any storage calls | ||
expect(Onyx.multiSet).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('Should migrate Onyx keys in localStorage to (new) Onyx', () => { | ||
// Given some old data exists in storage | ||
const data = { | ||
[ONYXKEYS.SESSION]: {authToken: 'mock-token', loading: false}, | ||
[ONYXKEYS.ACCOUNT]: {email: '[email protected]'}, | ||
[ONYXKEYS.NETWORK]: {isOffline: true}, | ||
}; | ||
|
||
_.forEach(data, (value, key) => localStorage.setItem(key, JSON.stringify(value))); | ||
|
||
// When the migration runs | ||
return MoveToIndexedDB().then(() => { | ||
// Then multiset should be called with all the data available in localStorage | ||
expect(Onyx.multiSet).toHaveBeenCalledWith(data); | ||
}); | ||
}); | ||
|
||
it('Should not clear non Onyx keys from localStorage', () => { | ||
// Given some Onyx and non-Onyx data exists in localStorage | ||
localStorage.setItem(ONYXKEYS.SESSION, JSON.stringify({authToken: 'mock-token'})); | ||
localStorage.setItem('non-onyx-item', 'MOCK'); | ||
|
||
// When the migration runs | ||
return MoveToIndexedDB().then(() => { | ||
// Then non-Onyx data should remain in localStorage | ||
expect(localStorage.getItem('non-onyx-item')).toEqual('MOCK'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('AddLastVisibleActionCreated', () => { | ||
it('Should add lastVisibleActionCreated wherever lastActionCreated currently is', () => | ||
Onyx.multiSet({ | ||
|