Mocha-测试具有多个http状态的api

时间:2016-10-13 09:25:41

标签: javascript node.js mocha chai

我正在使用多种可能的http响应代码测试API [向用户说明] 。像

1. http status code -200. 
  

消息:"用户已添加成功"

2. http status code -422
  

Meaasage:"缺少输入数据"

3. http status code -500
  

Meaasage:"用户添加成功"

4. http status code -409
  

Meaasage:"用户已经超过"

我怎么能用摩卡测试这样的APi。这是我的代码

describe('mobile/user api ',function(){

it('signup user with username ,email and password only',function(done){
  chai.request(testCaseUrl)
      .post('/v2/mobile/organizers/'+organizerId+'/apps/'+appid+'/attendees/signup')
      .send({'name':'afraz','email':'afrazahmad@gmail.com','password':'newton'})
      .end(function(err,res){

        console.log(res.text.message);
         if(err){
             done(err);
             return;
         }
         //Expecting multiple  response status here
         res.status.should.be.equal(400);
         done(res.text);

        });

});

0 个答案:

没有答案