summaryrefslogtreecommitdiff
path: root/goodgame/test/unit.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'goodgame/test/unit.test.js')
-rw-r--r--goodgame/test/unit.test.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/goodgame/test/unit.test.js b/goodgame/test/unit.test.js
new file mode 100644
index 0000000..fec9b31
--- /dev/null
+++ b/goodgame/test/unit.test.js
@@ -0,0 +1,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();
+ });
+ });
+});