Last active
November 22, 2018 21:52
-
-
Save Johnsonojo/2cff5ad6d6f11991bd45983b23d15efd to your computer and use it in GitHub Desktop.
Revisions
-
Johnsonojo revised this gist
Nov 22, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const { expect } = chai; chai.use(chaiHttp); describe('Article Controller', () => { before((done) => { chai.request(app) .post(`${userSignin}`) -
Johnsonojo created this gist
Nov 22, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ import chaiHttp from 'chai-http'; import chai from 'chai'; import app from '../app'; let userToken; const userSignin = '/api/v1/auth/login'; const user = { email: 'johndoe@gmail.com', password: 'WhyDoYouCare?', }; const { expect } = chai; chai.use(chaiHttp); describe('Menu Controller', () => { before((done) => { chai.request(app) .post(`${userSignin}`) .send(user) .end((err, res) => { userToken = res.body.data.token; done(err); }); }); it('should allow authencticated delete his article', (done) => { chai.request(app) .delete('/api/v1/users/10/articles/1') .set('token', userToken) .end((err, res) => { expect(res.status).to.equal(200); expect(res.body).to.be.an('object'); expect(res.body.status).to.equal('success'); expect(res.body.message).to.equal('Article 1 deleted successfully'); done(err); }); }); it('should throw an error for a non-existent article id', (done) => { chai.request(app) .delete('/api/v1/users/10/articles/10000') .set('token', userToken) .end((err, res) => { expect(res.status).to.equal(404); expect(res.body).to.be.an('object'); expect(res.body.status).to.equal('failure'); expect(res.body.message).to.equal('Article not found'); done(err); }); }); it('should throw an error for a string article id', (done) => { chai.request(app) .delete('/api/v1/users/10/articles/1o0') .set('token', userToken) .end((err, res) => { expect(res.status).to.equal(400); expect(res.body).to.be.an('object'); expect(res.body.status).to.equal('failure'); expect(res.body.message).to.equal('Article validation not successful'); expect(res.body.data[0].msg).to.equal('Article id must be an integer'); done(err); }); }); });