From c50b26199e71413bae70aea34f15cdadadd21ed9 Mon Sep 17 00:00:00 2001 From: frankast Date: Wed, 9 Jan 2019 00:15:15 +0600 Subject: [PATCH 1/2] wip --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e03e099..08ff497 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "8" before_install: - yarn global add greenkeeper-lockfile@1 - - yarn add mongoose + - yarn add mongoose --peer before_script: greenkeeper-lockfile-update after_script: greenkeeper-lockfile-upload script: From 85f83fb2c1da6e343cbc081b0311aa41fe43294f Mon Sep 17 00:00:00 2001 From: frankast Date: Wed, 9 Jan 2019 00:31:56 +0600 Subject: [PATCH 2/2] refactor: fix ci, fix dates in test --- .travis.yml | 2 +- src/__tests__/diff-test.js | 6 +++--- src/definitions.js | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08ff497..e03e099 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "8" before_install: - yarn global add greenkeeper-lockfile@1 - - yarn add mongoose --peer + - yarn add mongoose before_script: greenkeeper-lockfile-update after_script: greenkeeper-lockfile-upload script: diff --git a/src/__tests__/diff-test.js b/src/__tests__/diff-test.js index fa486ed..8b0ad02 100644 --- a/src/__tests__/diff-test.js +++ b/src/__tests__/diff-test.js @@ -31,7 +31,7 @@ describe('findDiff', () => { { k: 'N', p: ['string'], r: 'str1' }, { k: 'N', p: ['newString'], r: 'str2' }, { k: 'N', p: ['number'], r: 1 }, - { k: 'N', p: ['date'], r: new Date('2018-11-29T18:00:00.000Z') }, + { k: 'N', p: ['date'], r: new Date('2018/11/30') }, ]); expect(modifiedDiffs).toEqual([ @@ -43,9 +43,9 @@ describe('findDiff', () => { { k: 'E', l: 0, p: ['number'], r: 1 }, { k: 'E', - l: new Date('2018-12-29T18:00:00.000Z'), + l: new Date('2018/12/30'), p: ['date'], - r: new Date('2018-11-29T18:00:00.000Z'), + r: new Date('2018/11/30'), }, { k: 'N', p: ['newString'], r: 'str2' }, ]); diff --git a/src/definitions.js b/src/definitions.js index f988941..304b36d 100644 --- a/src/definitions.js +++ b/src/definitions.js @@ -65,12 +65,13 @@ export class DiffDoc /* :: extends Mongoose$Document */ { .exec(); } - static async revertToVersion(doc: Object, v: number): Promise { + static async revertToVersion(d: Object, v: number): Promise { + const doc = typeof d.toObject === 'function' ? d.toObject() : d; const changes: Array = []; const diffDocs = (await this.findAfterVersion(doc._id, v): any); if (diffDocs.length === 0) return null; - diffDocs.forEach(d => changes.push(...d.c)); + diffDocs.forEach(diffDoc => changes.push(...diffDoc.c)); return revertChanges(doc, changes); }