Browse Source

Merge pull request #1529 from Arnaud97234/test-e2e

Update e2e test & config
gre-patch-1
Meriadec Pillet 6 years ago
committed by GitHub
parent
commit
b59aad3a41
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      test-e2e/sync/launch.sh
  2. 21
      test-e2e/sync/sync-accounts.spec.js

4
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

21
test-e2e/sync/sync-accounts.js → 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}`
}
Loading…
Cancel
Save