var rest = require('restler');
var assert = require("assert");
var systemID;
var userID;

console.log('--------------------------------------');
console.log('SYSTEM TEST START ..');
console.log('--------------------------------------');

describe('system',function(){
  it('增加',function(done){
    rest
      .post('http://127.0.0.1:1337/system/',{data:{system:'test',uri:'http://test.com'}})
      .on('complete', function(result) {
        "use strict";
        assert.equal('test',result.result.system);
        assert.equal('http://test.com',result.result.uri);
        systemID = result.result.id;
        done();
      });
  });
  it('修改',function(done){
    rest
      .put('http://127.0.0.1:1337/system/'+systemID,{data:{system:'test',uri:'http://test2.com'}})
      .on('complete', function(result) {
        "use strict";
        //console.log(result);
        assert.equal('test',result.result.system);
        assert.equal('http://test2.com',result.result.uri);
        done();
      });
  });
  it('查看',function(done){
    rest
      .get('http://127.0.0.1:1337/system/')
      .on('complete', function(result) {
        "use strict";
        assert.equal('test',result.result[result.result.length - 1].system);
        assert.equal('http://test2.com',result.result[result.result.length - 1].uri);
        done();
      });
  });
  it('删除',function(done){
    rest
      .del('http://127.0.0.1:1337/system/'+systemID)
      .on('complete', function(result) {
        "use strict";
        assert.equal('test',result.result.system);
        assert.equal('http://test2.com',result.result.uri);
        done();
      });
  });
});

describe('user',function(){
  it('增加',function(done){
    rest
      .post('http://127.0.0.1:1337/user/',{data:{email:'test@test.com',passwd:'test'}})
      .on('complete', function(result) {
        "use strict";
        assert.equal('test@test.com',result.result.email);
        userID = result.result.id;
        done();
      });
  });
  it('修改',function(done){
    rest
      .put('http://127.0.0.1:1337/user/'+userID,{data:{email:'test2@test.com'}})
      .on('complete', function(result) {
        "use strict";
        //console.log(result);
        assert.equal('test2@test.com',result.result.email);
        done();
      });
  });
  it('查看',function(done){
    rest
      .get('http://127.0.0.1:1337/user/')
      .on('complete', function(result) {
        "use strict";
        assert.equal('test2@test.com',result.result[result.result.length - 1].email);
        done();
      });
  });
  it('删除',function(done){
    rest
      .del('http://127.0.0.1:1337/user/'+userID)
      .on('complete', function(result) {
        "use strict";
        assert.equal('test2@test.com',result.result.email);
        done();
      });
  });
});

与你相遇好幸运,mocha接口测试的更多相关文章

  1. nodejs+supertest+mocha 接口测试环境搭建

    系统接口自动化测试 该框架用于对系统的接口自动化测试(nodejs+supertest+mocha)Homebrew 安装: ruby -e "$(curl -fsSL {+}https:/ ...

  2. 与你相遇好幸运,服务器node环境安装

    >服务器更改root密码 sudo passwd root >服务器ubuntu安装ssh apt-get install openssh-server >服务器开启root用户密码 ...

  3. 与你相遇好幸运,My Toolkit of Nodejs

    >测试:restler.mocha.assert.request.request-promise >安装:nrm >运维:pm2.node-gyp >开发:nodemon.in ...

  4. 与你相遇好幸运,使用redis设置定时任务

    参考链接: Nodejs中使用Redis来完成定时任务 自己在 window 7下编码实现: 1 > 首先查看redis版本: redis-server -v , 版本要求大于等于2.8 2&g ...

  5. 与你相遇好幸运,制作自己的Yeoman Generator

    使用别人写好的生成器: npm install -g yonpm install -g generator-angularyo angular 如何自己制作符合自己心仪的生成器呢: https://g ...

  6. 与你相遇好幸运,gen8安装

    gen8到手后,立马去买了 SSD https://item.jd.com/2010277.html 支架 https://item.jd.com/2671609.html NAS盘 https:// ...

  7. 与你相遇好幸运,德淘gen8历程

    应该是十月底了 , 在浏览色魔张大妈(smzdm) http://www.smzdm.com/p/6517684/ 的时候看见了这个 , 以前大学就想买个这个 , 苦于没钱.... 然后当时打算买 , ...

  8. 与你相遇好幸运,用sinopia搭建npm私服

    需求: >在企业内部搭建私有npm服务器,企业开发人员上传下载自己开发的npm包 >私有npm服务器包不存在时,找npm或者taobao的镜像站点 >服务器硬盘有限,希望只缓存下载过 ...

  9. 与你相遇好幸运,Postman设置Header不生效问题解决

    POstMan安装地址 安装完 , Postman 设置Header的Referer不生效 , 提示 Restricted Header (use postman interceptor) 时 , 要 ...

随机推荐

  1. nginx中将POST数据写到日志里面的正确方式

    http://www.cnblogs.com/meteorx/p/3188647.html

  2. TypeScript Function(函数)

    在JavaScript中,函数是构成任何应用程序的基础块.通过函数,你得以实现建立抽象层.模仿类.信息隐藏和模块化.在TypeScript中,虽然已经存在类和模块化,但是函数依旧在如何去"处 ...

  3. 对于angularJS的一点思考

    已经找好工作近两周了,入职基本上还算顺利,自己两年来的挑灯夜战也算是有了收获,于是这两周基本上是按部就班的工作,没有学习什么新技术.在上个公司的时候,同事在项目中使用angularJs,之前他也没有接 ...

  4. Ubuntu学习总结-07 Nodejs和npm的安装

    一 安装NodeJS 1 下载nodejs源码 从以下网址下载最新的Nodejs源码 https://nodejs.org/en/download/ 2 安装依赖的 python,gcc,g++ 函数 ...

  5. js自执行函数注意事项

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. java读取项目根路径下和任意磁盘位置下的properties文件

    1.读取项目根路径下的properties文件比较简单也是比较常见的一种操作. 具体代码如下: package com.xuanen.util; import java.util.Properties ...

  7. sql 查询

    select * from (select * ,row_number() over(partition by CreateUID order by asid)num from AuctionSell ...

  8. UIScrollView的常见属性

    @property(nonatomic) CGPoint contentOffset; 这个属性用来表示UIScrollView滚动的位置 (其实就是内容左上角与scrollView左上角的间距值) ...

  9. mysql遇到锁表常用命令

    出现 waiting for table metadata lock 锁表的解决方法 1. show processlist; kill xxx; //xxx 为会话id 2.查询是否有未提交的事物 ...

  10. 微信服务号模板消息接口新增"设置行业"和"添加模板"及细节优化

    微信服务号模板消息可以向用户发送重要的服务通知,如信用卡刷卡通知,商品购买成功通知等.昨日,微信团队发布公告称模板消息新增“设置行业”和“添加模板”接口及细节优化,详细变动如下 模板消息[业务通知]自 ...