diff --git a/test-e2e/sync/launch.sh b/test-e2e/sync/launch.sh index c94b9f6c..69eda0b0 100644 --- a/test-e2e/sync/launch.sh +++ b/test-e2e/sync/launch.sh @@ -19,8 +19,6 @@ fi rm -rf "$settingsPath" mkdir "$settingsPath" -# rm ../data/actual_app.json - # Copy app.json init file for testing cp test-e2e/sync/data/empty-app.json "$settingsPath/app.json" @@ -46,4 +44,4 @@ fi cp "$settingsPath"/app.json test-e2e/sync/data/actual-app.json # compare new app.json with expected_app.json -./node_modules/.bin/jest test-e2e/sync/sync-accounts.js +./node_modules/.bin/jest test-e2e/sync/sync-accounts.spec.js diff --git a/test-e2e/sync/sync-accounts.js b/test-e2e/sync/sync-accounts.spec.js similarity index 72% rename from test-e2e/sync/sync-accounts.js rename to test-e2e/sync/sync-accounts.spec.js index fbca733d..b67c505d 100644 --- a/test-e2e/sync/sync-accounts.js +++ b/test-e2e/sync/sync-accounts.spec.js @@ -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}` +}