Adding more tests
							parent
							
								
									519c00f983
								
							
						
					
					
						commit
						802414b208
					
				|  | @ -26,7 +26,7 @@ router.post('/customer/create', (req, res) => { | |||
|     // check for existing customer
 | ||||
|     db.customers.findOne({email: req.body.email}, (err, customer) => { | ||||
|         if(customer){ | ||||
|             res.status(404).json({ | ||||
|             res.status(400).json({ | ||||
|                 err: 'A customer already exists with that email address' | ||||
|             }); | ||||
|             return; | ||||
|  |  | |||
							
								
								
									
										57
									
								
								test/test.js
								
								
								
								
							
							
						
						
									
										57
									
								
								test/test.js
								
								
								
								
							|  | @ -178,3 +178,60 @@ test.serial('[Success] Search products', async t => { | |||
|     // Should be two backpack products
 | ||||
|     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'); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue