Skip to content

Instantly share code, notes, and snippets.

@akhilome
Last active August 28, 2019 14:24
Show Gist options
  • Save akhilome/04203b7c879458d49170ce49558797ad to your computer and use it in GitHub Desktop.
Save akhilome/04203b7c879458d49170ce49558797ad to your computer and use it in GitHub Desktop.
import chai from 'chai';
import 'chai/register-should';
import chaiHttp from 'chai-http';
import app from '../../src/app.js';
import { publications, articles } from '../mockData';
chai.use(chaiHttp);
describe('GET all articles for a particular publication', () => {
it('should return a 404 if publication does not exist', (done) => {
chai.request(app)
.get(`/api/${publications.invalid}`)
.end((err, res) => {
if (err) done(err);
res.status.should.eql(404);
res.body.message.should.eql('no such publication found');
done();
});
});
it('should return an array containing the publication\'s articles', (done) => {
chai.request(app)
.get(`/api/${publications.valid}`)
.end((err, res) => {
if (err) done(err);
res.status.should.eql(200);
res.body.articles.should.be.an('array');
res.body.articles[0].should.have.all.keys(Object.keys(articles[0]));
done();
});
});
});
@marcdomain
Copy link

Good job. What does "publications.valid" and "publications.invalid" represent?

@akhilome
Copy link
Author

Good job. What does "publications.valid" and "publications.invalid" represent?

Thanks, @marcdomain. 🙏

To your question, publications, imported on line 6, is an object which would contain various valid publication names and invalid ones as well. It would essentially take the following form:

const publications = {
  valid: 'a-valid-publication',
  invalid: 'this-publication-does-not-exist-yet'
};

Thanks for taking time out to go over my work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment