You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.3 KiB
90 lines
2.3 KiB
4 years ago
|
import { strict as assert } from 'assert';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import migration50 from './050';
|
||
4 years ago
|
|
||
|
const LEGACY_LOCAL_STORAGE_KEYS = [
|
||
|
'METASWAP_GAS_PRICE_ESTIMATES_LAST_RETRIEVED',
|
||
|
'METASWAP_GAS_PRICE_ESTIMATES',
|
||
|
'cachedFetch',
|
||
|
'BASIC_PRICE_ESTIMATES_LAST_RETRIEVED',
|
||
|
'BASIC_PRICE_ESTIMATES',
|
||
|
'BASIC_GAS_AND_TIME_API_ESTIMATES',
|
||
|
'BASIC_GAS_AND_TIME_API_ESTIMATES_LAST_RETRIEVED',
|
||
|
'GAS_API_ESTIMATES_LAST_RETRIEVED',
|
||
|
'GAS_API_ESTIMATES',
|
||
4 years ago
|
];
|
||
4 years ago
|
|
||
|
describe('migration #50', function () {
|
||
4 years ago
|
let mockLocalStorageRemoveItem;
|
||
4 years ago
|
|
||
|
beforeEach(function () {
|
||
4 years ago
|
mockLocalStorageRemoveItem = sinon.stub(window.localStorage, 'removeItem');
|
||
|
});
|
||
4 years ago
|
|
||
|
afterEach(function () {
|
||
4 years ago
|
sinon.restore();
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should update the version metadata', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {
|
||
|
version: 49,
|
||
|
},
|
||
|
data: {},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
const newStorage = await migration50.migrate(oldStorage);
|
||
4 years ago
|
assert.deepEqual(newStorage.meta, {
|
||
|
version: 50,
|
||
4 years ago
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should call window.localStorage.removeItem for each legacy key', async function () {
|
||
|
const oldStorage = {
|
||
|
meta: {
|
||
|
version: 49,
|
||
|
},
|
||
|
data: {},
|
||
4 years ago
|
};
|
||
4 years ago
|
|
||
4 years ago
|
await migration50.migrate(oldStorage);
|
||
|
assert.equal(mockLocalStorageRemoveItem.callCount, 9);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(0).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[0],
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(1).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[1],
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(2).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[2],
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(3).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[3],
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(4).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[4],
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(5).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[5],
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(6).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[6],
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(7).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[7],
|
||
4 years ago
|
);
|
||
4 years ago
|
assert.equal(
|
||
|
mockLocalStorageRemoveItem.getCall(8).args[0],
|
||
|
LEGACY_LOCAL_STORAGE_KEYS[8],
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|