2021-03-16 22:00:08 +01:00
|
|
|
import firstTimeState from '../first-time-state';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { TransactionStatus } from '../../../shared/constants/transaction';
|
2021-03-16 22:00:08 +01:00
|
|
|
import migration27 from './027';
|
2018-06-25 20:45:00 +02:00
|
|
|
|
|
|
|
const oldStorage = {
|
2020-11-03 00:41:28 +01:00
|
|
|
meta: {},
|
|
|
|
data: {
|
|
|
|
TransactionController: {
|
|
|
|
transactions: [],
|
2018-06-25 20:45:00 +02:00
|
|
|
},
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-25 20:45:00 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const transactions = [];
|
2018-06-25 20:45:00 +02:00
|
|
|
|
|
|
|
while (transactions.length < 9) {
|
2023-01-18 15:47:29 +01:00
|
|
|
transactions.push({ status: TransactionStatus.rejected });
|
|
|
|
transactions.push({ status: TransactionStatus.unapproved });
|
|
|
|
transactions.push({ status: TransactionStatus.approved });
|
2018-06-25 20:45:00 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
oldStorage.data.TransactionController.transactions = transactions;
|
2018-06-25 20:45:00 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
describe('migration #27', () => {
|
|
|
|
it('should remove rejected transactions', async () => {
|
|
|
|
const newStorage = await migration27.migrate(oldStorage);
|
|
|
|
|
|
|
|
const newTransactions = newStorage.data.TransactionController.transactions;
|
|
|
|
|
|
|
|
expect(newTransactions).toHaveLength(6);
|
|
|
|
|
|
|
|
newTransactions.forEach((txMeta) => {
|
2023-01-18 15:47:29 +01:00
|
|
|
if (txMeta.status === TransactionStatus.rejected) {
|
2021-09-21 18:28:13 +02:00
|
|
|
throw new Error('transaction was found with a status of rejected');
|
|
|
|
}
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-06-25 20:45:00 +02:00
|
|
|
|
2021-09-21 18:28:13 +02:00
|
|
|
it('should successfully migrate first time state', async () => {
|
|
|
|
const migratedData = await migration27.migrate({
|
|
|
|
meta: {},
|
|
|
|
data: firstTimeState,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(migratedData.meta.version).toStrictEqual(migration27.version);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|