Skip to content

Commit

Permalink
Merge branch 'staging' into chore/164859311/update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
aanchirinah committed Mar 27, 2019
2 parents 1d9ccd4 + 75816e0 commit 327ef49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=

JWT_TOKEN=

# sessions details
COOKIE_SECRET=


API_DOMAIN=localhost:3000
29 changes: 20 additions & 9 deletions test/integrations/routes/reportArticle.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import chai, { expect } from 'chai';
import chaiHttp from 'chai-http';
import app from '../../../index';
import models from '../../../models';
import { auth } from '../../helpers';

chai.use(chaiHttp);

describe('Report Article API endpoint', () => {
const token = process.env.JWT_TOKEN;
let authToken;

before(async () => {
const user = await models.User.findByPk(2, { raw: true });
user.password = 'secret';
const response = await auth(user);
authToken = response.body.token;
});

// const token = process.env.JWT_TOKEN;
describe('/reporting article Post Endpoint', () => {
it('should report an article with report-type of "spam"', async () => {
const reportArticle = {
reportType: 'spam',
};
const res = await chai.request(app)
.post('/api/v1/articles/2/report')
.set({ Authorization: `Bearer ${token}` })
.set({ Authorization: `Bearer ${authToken}` })
.send(reportArticle);
expect(res.body.code).to.equal(201);
expect(res.body.data).to.be.an('object');
Expand All @@ -27,7 +38,7 @@ describe('Report Article API endpoint', () => {
};
const res = await chai.request(app)
.post('/api/v1/articles/3/report')
.set({ Authorization: `Bearer ${token}` })
.set({ Authorization: `Bearer ${authToken}` })
.send(reportArticle);
expect(res.body.code).to.equal(201);
expect(res.body.data).to.be.an('object');
Expand All @@ -41,7 +52,7 @@ describe('Report Article API endpoint', () => {
};
const res = await chai.request(app)
.post('/api/v1/articles/2/report')
.set({ Authorization: `Bearer ${token}` })
.set({ Authorization: `Bearer ${authToken}` })
.send(reportArticle);
expect(res.body.code).to.equal(400);
expect(res.body.data).to.be.an('array');
Expand All @@ -55,7 +66,7 @@ describe('Report Article API endpoint', () => {
};
const res = await chai.request(app)
.post('/api/v1/articles/2/report')
.set({ Authorization: `Bearer ${token}` })
.set({ Authorization: `Bearer ${authToken}` })
.send(reportArticle);
expect(res.body.code).to.equal(403);
expect(res.body.data).to.be.an('object');
Expand All @@ -69,7 +80,7 @@ describe('Report Article API endpoint', () => {
};
const res = await chai.request(app)
.post('/api/v1/articles/2/report')
.set({ Authorization: `Bearer ${token}` })
.set({ Authorization: `Bearer ${authToken}` })
.send(reportArticle);
expect(res.body.code).to.equal(400);
expect(res.body.data).to.be.an('array');
Expand All @@ -83,7 +94,7 @@ describe('Report Article API endpoint', () => {
};
const res = await chai.request(app)
.post('/api/v1/articles/4/report')
.set({ Authorization: `Bearer ${token}` })
.set({ Authorization: `Bearer ${authToken}` })
.send(reportArticle);
expect(res.body.code).to.equal(201);
expect(res.body.data).to.be.an('object');
Expand All @@ -96,7 +107,7 @@ describe('Report Article API endpoint', () => {
it('should get a reported article', async () => {
const res = await chai.request(app)
.get('/api/v1/articles/2/report')
.set({ Authorization: `Bearer ${token}` });
.set({ Authorization: `Bearer ${authToken}` });
expect(res.body.code).to.equal(200);
expect(res.body.message).to.equal('success');
expect(res.body.status).to.equal(true);
Expand All @@ -105,7 +116,7 @@ describe('Report Article API endpoint', () => {
it('should return error for non-existing article', async () => {
const res = await chai.request(app)
.get('/api/v1/articles/b/report')
.set({ Authorization: `Bearer ${token}` });
.set({ Authorization: `Bearer ${authToken}` });
expect(res.body.code).to.equal(404);
expect(res.body.message).to.equal('ARTICLE NOT FOUND');
expect(res.body.status).to.equal('Failure');
Expand Down
14 changes: 6 additions & 8 deletions test/unit/middlewares/articlesMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ let authpayload;
let authpayload2;
let articlePayload;

let dummyUser = {
const dummyUser = {
email: faker.internet.email(),
password: 'i2345678',
username: 'error-test'
};

let dummyUser2 = {
const dummyUser2 = {
email: faker.internet.email(),
password: 'p98765435667',
username: 'murderer-inc'
Expand All @@ -42,7 +42,7 @@ const dummyArticle = {
const createUser = async () => {
try {
const user = await models.User.create(dummyUser);
dummyUser = user;
dummyUser.id = user.id;
return dummyUser;
} catch (error) {
return error;
Expand All @@ -52,7 +52,7 @@ const createUser = async () => {
const createUser2 = async () => {
try {
const user = await models.User.create(dummyUser2);
dummyUser2 = user;
dummyUser2.id = user.id;
return dummyUser2;
} catch (error) {
return error;
Expand All @@ -61,14 +61,13 @@ const createUser2 = async () => {

describe('API endpoint: /api/articles (Middleware test)', () => {
before(async () => {
models.sequelize.sync();
createUser();
await createUser();
authpayload = await chai.request(app)
.post('/api/v1/users/login')
.send(dummyUser);
dummyUser.token = authpayload.body.token;

createUser2();
await createUser2();
authpayload2 = await chai.request(app)
.post('/api/v1/users/login')
.send(dummyUser2);
Expand All @@ -85,7 +84,6 @@ describe('API endpoint: /api/articles (Middleware test)', () => {
.set({ Authorization: `Bearer ${dummyUser2.token}` });

dummyArticle2 = articlePayload.body.data;
// return dummyUser;
});

describe('POST: /api/v1/articles', () => {
Expand Down

0 comments on commit 327ef49

Please sign in to comment.