Browse Source

Add tests so to return error if category name has no length

sbkwgh 8 years ago
parent
commit
054ab41e84
2 changed files with 27 additions and 1 deletions
  1. 1 1
      routes/category.js
  2. 26 0
      test/category.js

+ 1 - 1
routes/category.js

@@ -155,7 +155,7 @@ router.post('/', async (req, res) => {
 		} else if(typeof req.body.name !== 'string') {
 			validationErrors.push(Errors.invalidParameterType('name', 'string'))
 		} else if(!req.body.name.length) {
-			validationErrors.push(Errors.parameterLengthTooSmall('name', '0'))
+			validationErrors.push(Errors.missingParameter('name'))
 		}
 
 		if(validationErrors.length) throw Errors.VALIDAITON_ERROR

+ 26 - 0
test/category.js

@@ -83,6 +83,32 @@ describe('Category', () => {
 				JSON.parse(res.response.text).errors.should.contain.something.that.deep.equals(Errors.categoryAlreadyExists)
 			}
 		})
+		it('should return an error if missing category parameter', done => {
+			agent
+				.post('/api/v1/category')
+				.set('content-type', 'application/json')
+				.send({})
+				.end((err, res) => {
+					res.should.be.json
+					res.should.have.status(400)
+					res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('name'))
+
+					done()
+				})
+		})
+		it('should return an error if category parameter has no length', done => {
+			agent
+				.post('/api/v1/category')
+				.set('content-type', 'application/json')
+				.send({ name: '' })
+				.end((err, res) => {
+					res.should.be.json
+					res.should.have.status(400)
+					res.body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('name'))
+
+					done()
+				})
+		})
 		it('should return an error if not an admin account', async () => {
 			let agent = chai.request.agent(server)