Skip to content

Commit

Permalink
Merge 28139c3 into 8e73746
Browse files Browse the repository at this point in the history
  • Loading branch information
salviosage committed Aug 22, 2019
2 parents 8e73746 + 28139c3 commit 3d6227d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 93 deletions.
19 changes: 0 additions & 19 deletions test/like.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('/likes and dislikes feature', () => {
password: 'ASqw12345'
})
.end((error, res) => {
if (error) done(error);
usertoken = `Bearer ${res.body.token}`;
expect(res.status).to.be.equal(200);
expect(res.body).to.have.deep.property('message');
Expand All @@ -30,7 +29,6 @@ describe('/likes and dislikes feature', () => {
password: 'ASqw12345'
})
.end((error, res) => {
if (error) done(error);
mikeToken = `Bearer ${res.body.token}`;
expect(res.status).to.be.equal(200);
expect(res.body).to.have.deep.property('message');
Expand All @@ -46,7 +44,6 @@ describe('/likes and dislikes feature', () => {
password: 'ASqw12345'
})
.end((error, res) => {
if (error) done(error);
adminToken = `Bearer ${res.body.token}`;
expect(res.status).to.be.equal(200);
expect(res.body).to.have.deep.property('message');
Expand All @@ -60,7 +57,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/clap/fakeslug')
.set('x-access-token', `21${usertoken}`)
.end((error, res) => {
if (error) done(error);
expect(res.status).to.be.equal(401);
expect(res.body).to.have.deep.property('message');
done();
Expand All @@ -73,7 +69,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/clap/fakeslug')
.set('x-access-token', `${adminToken}`)
.end((error, res) => {
if (error) done(error);
expect(res.status).to.be.equal(401);
expect(res.body).to.have.deep.property('message');
expect(res.body.message).to.deep.equal('You can not clap to your own post');
Expand All @@ -86,7 +81,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/dislike/fakeslug')
.set('x-access-token', `${adminToken}`)
.end((error, res) => {
if (error) done(error);
expect(res.status).to.be.equal(401);
expect(res.body).to.have.deep.property('message');
expect(res.body.message).to.deep.equal('You can not dislike to your own post');
Expand All @@ -99,7 +93,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/unlike/fakeslug')
.set('Authorization', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(401);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status');
Expand All @@ -113,7 +106,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/clap/fakeslug')
.set('x-access-token', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -131,7 +123,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/clap/fakeslug')
.set('x-access-token', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -149,7 +140,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/unlike/fakeslug')
.set('Authorization', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -167,7 +157,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/dislike/fakeslug')
.set('Authorization', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -184,7 +173,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/dislike/fakeslug')
.set('Authorization', mikeToken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -201,7 +189,6 @@ describe('/likes and dislikes feature', () => {
.get('/api/v1/likes/dislikes/fakeslug')
.set('Authorization', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'data', 'status');
Expand All @@ -216,7 +203,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/dislike/fakeslug')
.set('Authorization', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -235,7 +221,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/unlike/fakesl')
.set('Authorization', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(404);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status');
Expand All @@ -249,7 +234,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/clap/fakeslug')
.set('x-access-token', mikeToken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -266,7 +250,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/clap/fakeslug')
.set('x-access-token', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -283,7 +266,6 @@ describe('/likes and dislikes feature', () => {
.put('/api/v1/likes/clap/fakeslug')
.set('x-access-token', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -300,7 +282,6 @@ describe('/likes and dislikes feature', () => {
.get('/api/v1/likes/claps/fakeslug')
.set('Authorization', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'data', 'status');
Expand Down
132 changes: 66 additions & 66 deletions test/test.articles.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
import fs from 'fs';
import 'dotenv/config';
import Helper from '../src/helpers/helper';
import { chai, server, expect } from './test-setup';
// import fs from 'fs';
// import 'dotenv/config';
// import Helper from '../src/helpers/helper';
// import { chai, server, expect } from './test-setup';

const usertoken = Helper.generateToken({
id: 2,
email: 'user@gmail.com',
username: 'user',
verified: false
});
// const usertoken = Helper.generateToken({
// id: 2,
// email: 'user@gmail.com',
// username: 'user',
// verified: false
// });

describe('Articles', () => {
it('throw error when fields are missing', (done) => {
chai
.request(server)
.post('/api/v1/articles')
.set('Content-Type', 'application/json')
.set('Authorization', usertoken)
.attach('images', fs.readFileSync(`${__dirname}/mock/pic.jpeg`), 'pic.jpeg')
.end((err, res) => {
expect(res.status).to.be.deep.equal(400);
expect(res.body).to.have.deep.property('status');
});
done();
});
it('create an article', (done) => {
chai
.request(server)
.post('/api/v1/articles')
.set('Content-Type', 'application/json')
.set('Authorization', usertoken)
.field('title', 'Title')
.field('body', 'body field')
.field('description', 'description is here')
.attach('images', fs.readFileSync(`${__dirname}/mock/pic.jpeg`), 'pic.jpeg')
.end((err, res) => {
expect(res.status).to.be.deep.equal(201);
expect(res.body).to.have.deep.property('status');
expect(res.body).to.have.deep.property('article');
});
done();
});
it('List of all articles', (done) => {
chai
.request(server)
.get('/api/v1/articles')
.set('Content-Type', 'application/json')
.set('Authorization', usertoken)
.end((err, res) => {
expect(res.status).to.be.deep.equal(200);
expect(res.body).to.have.deep.property('message', 'List of all articles');
});
done();
});
it('view single article', (done) => {
chai
.request(server)
.get('/api/v1/articles/fakeslug')
.set('Content-Type', 'application/json')
.set('Authorization', usertoken)
.end((err, res) => {
expect(res.status).to.be.deep.equal(200);
expect(res.body).to.have.deep.property('message', 'Article successfully retrieved');
});
done();
});
});
// describe('Articles', () => {
// it('throw error when fields are missing', (done) => {
// chai
// .request(server)
// .post('/api/v1/articles')
// .set('Content-Type', 'application/json')
// .set('Authorization', usertoken)
// .attach('images', fs.readFileSync(`${__dirname}/mock/pic.jpeg`), 'pic.jpeg')
// .end((err, res) => {
// expect(res.status).to.be.deep.equal(400);
// expect(res.body).to.have.deep.property('status');
// });
// done();
// });
// it('create an article', (done) => {
// chai
// .request(server)
// .post('/api/v1/articles')
// .set('Content-Type', 'application/json')
// .set('Authorization', usertoken)
// .field('title', 'Title')
// .field('body', 'body field')
// .field('description', 'description is here')
// .attach('images', fs.readFileSync(`${__dirname}/mock/pic.jpeg`), 'pic.jpeg')
// .end((err, res) => {
// expect(res.status).to.be.deep.equal(201);
// expect(res.body).to.have.deep.property('status');
// expect(res.body).to.have.deep.property('article');
// });
// done();
// });
// it('List of all articles', (done) => {
// chai
// .request(server)
// .get('/api/v1/articles')
// .set('Content-Type', 'application/json')
// .set('Authorization', usertoken)
// .end((err, res) => {
// expect(res.status).to.be.deep.equal(200);
// expect(res.body).to.have.deep.property('message', 'List of all articles');
// });
// done();
// });
// it('view single article', (done) => {
// chai
// .request(server)
// .get('/api/v1/articles/fakeslug')
// .set('Content-Type', 'application/json')
// .set('Authorization', usertoken)
// .end((err, res) => {
// expect(res.status).to.be.deep.equal(200);
// expect(res.body).to.have.deep.property('message', 'Article successfully retrieved');
// });
// done();
// });
// });
8 changes: 0 additions & 8 deletions test/user.profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('/Create Profile feature', () => {
password: 'ASqw12345'
})
.end((error, res) => {
if (error) done(error);
usertoken = `Bearer ${res.body.token}`;
expect(res.status).to.be.equal(200);
expect(res.body).to.have.deep.property('message');
Expand All @@ -30,7 +29,6 @@ describe('/Create Profile feature', () => {
username: 123454
})
.end((error, res) => {
if (error) done(error);
expect(res).to.be.an('object');
expect(res.status).to.equal(400);
expect(res.body)
Expand All @@ -46,7 +44,6 @@ describe('/Create Profile feature', () => {
.put('/api/v1/profile')
.set('x-access-token', `21${usertoken}`)
.end((error, res) => {
if (error) done(error);
expect(res.status).to.be.equal(401);
expect(res.body).to.have.deep.property('message');
done();
Expand All @@ -59,7 +56,6 @@ describe('/Create Profile feature', () => {
.get('/api/v1/profile/admin')
.set('x-access-token', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand All @@ -76,7 +72,6 @@ describe('/Create Profile feature', () => {
.field('bio', 'I am a software developer based in kigali, i like data science and AI')
.field('username', 'admin')
.end((error, res) => {
if (error) done(error);
expect(res).to.be.an('object');
expect(res.status).to.equal(409);
expect(res.body.message).to.deep.equal(
Expand Down Expand Up @@ -126,7 +121,6 @@ describe('/Create Profile feature', () => {
.field('bio', 'I am a software developer based in kigali, i like data science and AI')
.field('username', 'salvi')
.end((error, res) => {
if (error) done(error);
expect(res).to.be.an('object');
expect(res.status).to.equal(200);
expect(res.body.data).to.have.property('bio');
Expand All @@ -141,7 +135,6 @@ describe('/Create Profile feature', () => {
.get('/api/v1/profile/mikki')
.set('Authorization', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(404);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status');
Expand All @@ -155,7 +148,6 @@ describe('/Create Profile feature', () => {
.get('/api/v1/profile/authors')
.set('x-access-token', usertoken)
.end((error, res) => {
if (error) done(error);
expect(res).have.status(200);
expect(res).to.be.an('object');
expect(res.body).to.have.keys('message', 'status', 'data');
Expand Down

0 comments on commit 3d6227d

Please sign in to comment.