summaryrefslogtreecommitdiff
path: root/goodgame/test/unit.test.js
blob: fec9b31423895ed4c3f03dd8f504560c3a9ff176 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
process.env.NODE_ENV = 'test';

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

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

chai.use(chaiHttp);

describe('The units creator:', () => {
  it('should not generate new random units if the amount is not specified', done => {
    chai
      .request(app)
      .post('/')
      .end((err, res) => {
        res.should.have.status(422);
        res.body.should.have.property('ok').eql(false);
        res.body.should.have
          .property('response')
          .eql([
            'amount: Amount cannot be blank!',
            'amount: Amount should be an int!',
          ]);
        done();
      });
  });

  it('should not generate new random units if the amount is not an integer', done => {
    const data = { amount: 'hello' };
    chai
      .request(app)
      .post('/')
      .send(data)
      .end((err, res) => {
        res.should.have.status(422);
        res.body.should.have.property('ok').eql(false);
        res.body.should.have
          .property('response')
          .eql(['amount: Amount should be an int!']);
        done();
      });
  });

  it('should not generate new random units if the amount is less than the available units', done => {
    const data = { amount: 3 };
    chai
      .request(app)
      .post('/')
      .send(data)
      .end((err, res) => {
        res.should.have.status(422);
        res.body.should.have.property('ok').eql(false);
        res.body.should.have
          .property('response')
          .eql(
            'Amount has to be a higher number than the available units. Current available units is 7'
          );
        done();
      });
  });

  it('should generate new random units', done => {
    const data = { amount: 1000 };
    chai
      .request(app)
      .post('/')
      .send(data)
      .end((err, res) => {
        res.should.have.status(201);
        res.body.should.have.property('ok').eql(true);
        res.body.response.should.have.property('total').eql(data.amount);
        done();
      });
  });
});