From ce17fa8773499ae49ba64d162acaab84162e9666 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 13 Dec 2016 15:15:08 -0700 Subject: [PATCH] Updated tests, fixes #166 --- .babelrc | 2 +- package.json | 1 - tests/models/asset.js | 5 +++-- tests/models/user.js | 49 +++++++++++++++++++++---------------------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/.babelrc b/.babelrc index cf99c0639..ca2e2cead 100644 --- a/.babelrc +++ b/.babelrc @@ -2,7 +2,7 @@ "sourceMaps": true, "presets": [ "stage-0", - "es2015-minimal" + "es2015" ], "plugins": [ ["transform-decorators-legacy"], diff --git a/package.json b/package.json index 53af9910b..33b21f0da 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ "babel-plugin-transform-react-jsx": "^6.8.0", "babel-polyfill": "^6.16.0", "babel-preset-es2015": "^6.18.0", - "babel-preset-es2015-minimal": "^2.1.0", "babel-preset-stage-0": "^6.16.0", "chai": "^3.5.0", "chai-http": "^3.0.0", diff --git a/tests/models/asset.js b/tests/models/asset.js index c9eff819e..7c5869caf 100644 --- a/tests/models/asset.js +++ b/tests/models/asset.js @@ -24,11 +24,12 @@ describe('models.Asset', () => { }); describe('#findByUrl', ()=> { + beforeEach(() => Asset.findOrCreateByUrl('http://test.com')); + it('should find an asset by a url', () => { return Asset.findByUrl('http://test.com') .then((asset) => { - expect(asset).to.have.property('url') - .and.to.equal('http://test.com'); + expect(asset).to.have.property('url', 'http://test.com'); }); }); diff --git a/tests/models/user.js b/tests/models/user.js index 43b60a784..3883e2e42 100644 --- a/tests/models/user.js +++ b/tests/models/user.js @@ -95,12 +95,17 @@ describe('models.User', () => { }); describe('#ban', () => { + let mockComment; + beforeEach(() => { - return Promise.all([ - Comment.create([{body: 'testing the comment for that user if it is rejected.', id: mockUsers[0].id}]) + return Comment.create([ + { + body: 'testing the comment for that user if it is rejected.', + id: mockUsers[0].id + } ]) - .then((comment) => { + .then(([comment]) => { mockComment = comment; }); }); @@ -109,11 +114,11 @@ describe('models.User', () => { return User .setStatus(mockUsers[0].id, 'banned', mockComment.id) .then(() => { - User.findById(mockUsers[0].id) - .then((user) => { - expect(user).to.have.property('status') - .and.to.equal('banned'); - }); + return User.findById(mockUsers[0].id); + }) + .then((user) => { + expect(user).to.have.property('status') + .and.to.equal('banned'); }); }); @@ -121,23 +126,20 @@ describe('models.User', () => { return User .setStatus(mockUsers[0].id, 'banned', mockComment.id) .then(() => { - Comment.findById(mockComment.id) - .then((comment) => { - expect(comment).to.have.property('status') - .and.to.equal('rejected'); - }); + return Comment.findById(mockComment.id); + }) + .then((comment) => { + expect(comment).to.have.property('status') + .and.to.equal('rejected'); }); }); it('should still disable and ban the user if there is no comment', () => { return User .setStatus(mockUsers[0].id, 'banned', '') - .then(() => { - User.findById(mockUsers[0].id) - .then((user) => { - expect(user).to.have.property('status') - .and.to.equal('banned'); - }); + .then(() => User.findById(mockUsers[0].id)) + .then((user) => { + expect(user).to.have.property('status', 'banned'); }); }); }); @@ -156,12 +158,9 @@ describe('models.User', () => { it('should set the status to active', () => { return User .setStatus(mockUsers[0].id, 'active', mockComment.id) - .then(() => { - User.findById(mockUsers[0].id) - .then((user) => { - expect(user).to.have.property('status') - .and.to.equal('active'); - }); + .then(() => User.findById(mockUsers[0].id)) + .then((user) => { + expect(user).to.have.property('status', 'active'); }); }); });