2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import firstTimeState from '../../../app/scripts/first-time-state';
|
|
|
|
import migration27 from '../../../app/scripts/migrations/027';
|
|
|
|
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
transactions.push({ status: TRANSACTION_STATUSES.REJECTED });
|
|
|
|
transactions.push({ status: TRANSACTION_STATUSES.UNAPPROVED });
|
|
|
|
transactions.push({ status: TRANSACTION_STATUSES.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
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('migration #27', function () {
|
|
|
|
it('should remove rejected transactions', function (done) {
|
2020-11-03 00:41:28 +01:00
|
|
|
migration27
|
|
|
|
.migrate(oldStorage)
|
2018-06-25 20:45:00 +02:00
|
|
|
.then((newStorage) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const newTransactions =
|
2021-02-04 19:15:23 +01:00
|
|
|
newStorage.data.TransactionController.transactions;
|
2020-11-03 00:41:28 +01:00
|
|
|
assert.equal(
|
|
|
|
newTransactions.length,
|
|
|
|
6,
|
|
|
|
'transactions is expected to have the length of 6',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-25 20:45:00 +02:00
|
|
|
newTransactions.forEach((txMeta) => {
|
2020-11-07 08:38:12 +01:00
|
|
|
if (txMeta.status === TRANSACTION_STATUSES.REJECTED) {
|
2021-02-04 19:15:23 +01:00
|
|
|
done(new Error('transaction was found with a status of rejected'));
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
done();
|
2018-06-25 20:45:00 +02:00
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.catch(done);
|
|
|
|
});
|
2018-06-25 20:45:00 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should successfully migrate first time state', function (done) {
|
2020-11-03 00:41:28 +01:00
|
|
|
migration27
|
|
|
|
.migrate({
|
|
|
|
meta: {},
|
|
|
|
data: firstTimeState,
|
|
|
|
})
|
2018-06-25 20:45:00 +02:00
|
|
|
.then((migratedData) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.equal(migratedData.meta.version, migration27.version);
|
|
|
|
done();
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
2021-02-04 19:15:23 +01:00
|
|
|
.catch(done);
|
|
|
|
});
|
|
|
|
});
|