Adding more tests

master
Mark Moffat 2019-06-12 18:48:48 +09:30
parent 519c00f983
commit 802414b208
2 changed files with 58 additions and 1 deletions

View File

@ -26,7 +26,7 @@ router.post('/customer/create', (req, res) => {
// check for existing customer // check for existing customer
db.customers.findOne({email: req.body.email}, (err, customer) => { db.customers.findOne({email: req.body.email}, (err, customer) => {
if(customer){ if(customer){
res.status(404).json({ res.status(400).json({
err: 'A customer already exists with that email address' err: 'A customer already exists with that email address'
}); });
return; return;

View File

@ -178,3 +178,60 @@ test.serial('[Success] Search products', async t => {
// Should be two backpack products // Should be two backpack products
t.deepEqual(res.body.length, 2); t.deepEqual(res.body.length, 2);
}); });
test.serial.only('[Success] Check for sitemap.xml', async t => {
const res = await request
.get('/sitemap.xml')
.expect(200);
if(!res.text){
t.fail();
}
// Document should start with XML tag
t.deepEqual(res.text.substring(0, 5), '<?xml');
});
test.serial.only('[Success] Create a customer', async t => {
const customer = {
email: 'sarah.jones@test.com',
firstName: 'Sarah',
lastName: 'Jones',
address1: '1 Sydney Street',
address2: '',
country: 'Australia',
state: 'NSW',
postcode: '2000',
phone: '0400000000',
password: 'password'
};
const res = await request
.post('/customer/create')
.send(customer)
.expect(200);
t.deepEqual(res.body.message, 'Successfully logged in');
});
test.serial.only('[Fail] Try create a duplicate customer', async t => {
const customer = {
email: 'sarah.jones@test.com',
firstName: 'Sarah',
lastName: 'Jones',
address1: '1 Sydney Street',
address2: '',
country: 'Australia',
state: 'NSW',
postcode: '2000',
phone: '0400000000',
password: 'password'
};
const res = await request
.post('/customer/create')
.send(customer)
.expect(400);
t.deepEqual(res.body.err, 'A customer already exists with that email address');
});