Skip to content

Instantly share code, notes, and snippets.

@Johnsonojo
Last active November 22, 2018 21:52
Show Gist options
  • Select an option

  • Save Johnsonojo/2cff5ad6d6f11991bd45983b23d15efd to your computer and use it in GitHub Desktop.

Select an option

Save Johnsonojo/2cff5ad6d6f11991bd45983b23d15efd to your computer and use it in GitHub Desktop.

Revisions

  1. Johnsonojo revised this gist Nov 22, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion DELETE article endpoint
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ const { expect } = chai;

    chai.use(chaiHttp);

    describe('Menu Controller', () => {
    describe('Article Controller', () => {
    before((done) => {
    chai.request(app)
    .post(`${userSignin}`)
  2. Johnsonojo created this gist Nov 22, 2018.
    66 changes: 66 additions & 0 deletions DELETE article endpoint
    Original 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);
    });
    });
    });