|
|
@ -18,7 +18,7 @@ const ACCOUNTS_FIELDS = [ |
|
|
|
|
|
|
|
const OPS_FIELDS = ['id', 'hash', 'accountId', 'type', 'senders', 'recipients', 'value', 'fee'] |
|
|
|
|
|
|
|
const ALPHA_SORT = (a, b) => { |
|
|
|
const OP_SORT = (a, b) => { |
|
|
|
const aHash = getOpHash(a) |
|
|
|
const bHash = getOpHash(b) |
|
|
|
if (aHash < bHash) return -1 |
|
|
@ -26,6 +26,14 @@ const ALPHA_SORT = (a, b) => { |
|
|
|
return 0 |
|
|
|
} |
|
|
|
|
|
|
|
const ACCOUNT_SORT = (a, b) => { |
|
|
|
const aHash = getAccountHash(a) |
|
|
|
const bHash = getAccountHash(b) |
|
|
|
if (aHash < bHash) return -1 |
|
|
|
if (aHash > bHash) return 1 |
|
|
|
return 0 |
|
|
|
} |
|
|
|
|
|
|
|
describe('sync accounts', () => { |
|
|
|
test('should give the same app.json', () => { |
|
|
|
const expected = getSanitized('./data/expected-app.json') |
|
|
@ -36,11 +44,12 @@ describe('sync accounts', () => { |
|
|
|
|
|
|
|
function getSanitized(filePath) { |
|
|
|
const data = require(`${filePath}`) // eslint-disable-line import/no-dynamic-require
|
|
|
|
return data.data.accounts |
|
|
|
.map(a => a.data) |
|
|
|
const accounts = data.data.accounts.map(a => a.data) |
|
|
|
accounts.sort(ACCOUNT_SORT) |
|
|
|
return accounts |
|
|
|
.map(a => pick(a, ACCOUNTS_FIELDS)) |
|
|
|
.map(a => { |
|
|
|
a.operations.sort(ALPHA_SORT) |
|
|
|
a.operations.sort(OP_SORT) |
|
|
|
return { |
|
|
|
...a, |
|
|
|
operations: a.operations.map(o => pick(o, OPS_FIELDS)), |
|
|
@ -51,3 +60,7 @@ function getSanitized(filePath) { |
|
|
|
function getOpHash(op) { |
|
|
|
return `${op.accountId}--${op.hash}--${op.type}` |
|
|
|
} |
|
|
|
|
|
|
|
function getAccountHash(account) { |
|
|
|
return `${account.name}` |
|
|
|
} |