Test for stock control
parent
3c38a6f9da
commit
3a61855609
14
test/test.js
14
test/test.js
|
@ -3,7 +3,6 @@ const fs = require('fs');
|
||||||
const app = require('../app');
|
const app = require('../app');
|
||||||
const common = require('../lib/common');
|
const common = require('../lib/common');
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
const agent = request.agent(app);
|
|
||||||
|
|
||||||
// Get test data to compare in tests
|
// Get test data to compare in tests
|
||||||
const rawTestData = fs.readFileSync('./bin/testdata.json', 'utf-8');
|
const rawTestData = fs.readFileSync('./bin/testdata.json', 'utf-8');
|
||||||
|
@ -123,6 +122,19 @@ test.serial('[Success] Add product to cart', async t => {
|
||||||
t.deepEqual(res.body.message, 'Cart successfully updated');
|
t.deepEqual(res.body.message, 'Cart successfully updated');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.serial('[Fail] Add product to cart with not enough stock', async t => {
|
||||||
|
const res = await request(app)
|
||||||
|
.post('/product/addtocart')
|
||||||
|
.send({
|
||||||
|
productId: products[0]._id,
|
||||||
|
productQuantity: 100,
|
||||||
|
productOptions: JSON.stringify(products[0].productOptions)
|
||||||
|
})
|
||||||
|
.expect(400)
|
||||||
|
|
||||||
|
t.deepEqual(res.body.message, 'There is insufficient stock of this product.');
|
||||||
|
});
|
||||||
|
|
||||||
test.serial('[Fail] Add incorrect product to cart', async t => {
|
test.serial('[Fail] Add incorrect product to cart', async t => {
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.post('/product/addtocart')
|
.post('/product/addtocart')
|
||||||
|
|
Loading…
Reference in New Issue