Skip to content

Commit

Permalink
Merge pull request #3 from FrankAst/fix-ci
Browse files Browse the repository at this point in the history
refactor: fix tests, ci
  • Loading branch information
borodayev authored Jan 8, 2019
2 parents 61cf2b0 + 85f83fb commit 84970b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/diff-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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' },
]);
Expand Down
5 changes: 3 additions & 2 deletions src/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ export class DiffDoc /* :: extends Mongoose$Document */ {
.exec();
}

static async revertToVersion(doc: Object, v: number): Promise<any> {
static async revertToVersion(d: Object, v: number): Promise<any> {
const doc = typeof d.toObject === 'function' ? d.toObject() : d;
const changes: Array<RawChangeT> = [];
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);
}

Expand Down

0 comments on commit 84970b0

Please sign in to comment.