Test for stock control

master
Mark Moffat 2019-06-09 22:19:50 +09:30
parent 3c38a6f9da
commit 3a61855609
1 changed files with 13 additions and 1 deletions

View File

@ -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')