Kaynağa Gözat

Add 2 tests for omission of username or password field

sbkwgh 8 yıl önce
ebeveyn
işleme
2339a6f544
1 değiştirilmiş dosya ile 33 ekleme ve 0 silme
  1. 33 0
      test/user.js

+ 33 - 0
test/user.js

@@ -6,6 +6,7 @@ let server = require('../server')
 let should = chai.should()
 
 let User = require('../models').User
+const Errors = require('../lib/errors.js');
 
 chai.use(chaiHttp)
 
@@ -37,6 +38,38 @@ describe('User', () => {
 					res.body.should.have.property('username', 'test')
 					res.body.should.have.property('hash')
 					
+					done()
+				})
+		})
+		it('should throw an error if no username', (done) => {
+			chai.request(server)
+				.post('/api/v1/user')
+				.set('content-type', 'application/x-www-form-urlencoded')
+				.send({
+					password: 'pass'
+				})
+				.end((err, res) => {
+					res.should.have.status(500)
+					res.should.be.json
+					res.body.should.have.property('error')
+					res.body.error.should.deep.equal()
+					
+					done()
+				})
+		})
+		it('should throw an error if no pass', (done) => {
+			chai.request(server)
+				.post('/api/v1/user')
+				.set('content-type', 'application/x-www-form-urlencoded')
+				.send({
+					username: 'test1'
+				})
+				.end((err, res) => {
+					res.should.have.status(200)
+					res.should.be.json
+					res.body.should.have.property('username', 'test')
+					res.body.should.have.property('hash')
+					
 					done()
 				})
 		})