Kaynağa Gözat

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

sbkwgh 8 yıl önce
ebeveyn
işleme
83de1fcd4e
2 değiştirilmiş dosya ile 18 ekleme ve 0 silme
  1. 2 0
      routes/thread.js
  2. 16 0
      test/thread_post.js

+ 2 - 0
routes/thread.js

@@ -100,6 +100,8 @@ router.post('/', async (req, res) => {
 			validationErrors.push(Errors.missingParameter('name'))
 		} else if(typeof req.body.name !== 'string') {
 			validationErrors.push(Errors.invalidParameterType('name', 'string'))
+		} else if(req.body.name.length === 0) {
+			validationErrors.push(Errors.missingParameter('name'))
 		}
 
 		if(req.body.category === undefined) {

+ 16 - 0
test/thread_post.js

@@ -146,6 +146,22 @@ describe('Thread and post', () => {
 				body.errors.should.contain.something.that.deep.equals(Errors.missingParameter('category'))
 			}
 		})
+		it('should return an error if name has no length', done => {
+			userAgent
+					.post('/api/v1/thread')
+					.set('content-type', 'application/json')
+					.send({
+						name: '',
+						category: 'CATEGORY_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 invalid types', async () => {
 			try {
 				let res = await userAgent