summaryrefslogtreecommitdiff
path: root/payever/test/app.test.js
blob: 2e2318829580712fc06ddb7e870edf096a1334a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
process.env.NODE_ENV = 'test';

const fs = require('fs');
const path = require('path');
const chai = require('chai');
const chaiHttp = require('chai-http');

const should = chai.should();
const app = require('../src/start');

chai.use(chaiHttp);

describe('The app:', () => {
  it('should get user 1 information', done => {
    chai
      .request(app)
      .get('/api/user/1')
      .end((err, res) => {
        res.should.have.status(200);
        res.body.should.have.property('email').eql('george.bluth@reqres.in');
        done();
      });
  });

  it('should get user 1 avatar, save it and return it locally', done => {
    chai
      .request(app)
      .get('/api/user/1/avatar')
      .end((err, res) => {
        res.should.have.status(200);
        fs.existsSync(
          path.resolve(__dirname, '../src', 'images', 'calebogden.jpg')
        ).should.eql(true);
        chai
          .request(app)
          .get('/api/user/1/avatar')
          .end((err_, res_) => {
            res_.should.have.status(200);
            done();
          });
      });
  });

  it('should delete user 1 avatar', done => {
    chai
      .request(app)
      .delete('/api/user/1/avatar')
      .end((err, res) => {
        res.should.have.status(204);
        done();
      });
  });

  it('should return error if user avatar is not saved locally', done => {
    chai
      .request(app)
      .delete('/api/user/2/avatar')
      .end((err, res) => {
        res.should.have.status(400);
        done();
      });
  });
});