diff options
-rw-r--r-- | app/scripts/lib/tx-state-history-helper.js | 7 | ||||
-rw-r--r-- | test/unit/tx-state-history-helper.js | 9 |
2 files changed, 10 insertions, 6 deletions
diff --git a/app/scripts/lib/tx-state-history-helper.js b/app/scripts/lib/tx-state-history-helper.js index 5ebd78689..db6e3bc9f 100644 --- a/app/scripts/lib/tx-state-history-helper.js +++ b/app/scripts/lib/tx-state-history-helper.js @@ -20,8 +20,11 @@ function migrateFromSnapshotsToDiffs(longHistory) { ) } -function generateHistoryEntry(previousState, newState) { - return jsonDiffer.compare(previousState, newState) +function generateHistoryEntry(previousState, newState, note) { + const entry = jsonDiffer.compare(previousState, newState) + // Add a note to the first op, since it breaks if we append it to the entry + if (note && entry[0]) entry[0].note = note + return entry } function replayHistory(_shortHistory) { diff --git a/test/unit/tx-state-history-helper.js b/test/unit/tx-state-history-helper.js index e5075af88..79ee26d6e 100644 --- a/test/unit/tx-state-history-helper.js +++ b/test/unit/tx-state-history-helper.js @@ -23,16 +23,16 @@ describe('tx-state-history-helper', function () { it('replaying history does not mutate the original obj', function () { const initialState = { test: true, message: 'hello', value: 1 } - const diff1 = { + const diff1 = [{ "op": "replace", "path": "/message", "value": "haay", - } - const diff2 = { + }] + const diff2 = [{ "op": "replace", "path": "/value", "value": 2, - } + }] const history = [initialState, diff1, diff2] const beforeStateSnapshot = JSON.stringify(initialState) @@ -42,4 +42,5 @@ describe('tx-state-history-helper', function () { assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state') assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run') }) + }) |