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. python re 模块和基础正则表达式

    1.迭代器:对象在其内部实现了iter(),__iter__()方法,可以用next方法实现自我遍历. 二.python正则表达式 1.python通过re模块支持正则表达式 2.查看当前系统有哪些p ...

  2. Google调用explorer.exe打开本地文件

    给IE浏览器地址栏输个本地文件路径,会自动用explorer.exe打开,这个挺好的,但是IE对jQuery稍微高点的版本不怎么待见,只好自己给Google折腾一个调用explorer的功能----- ...

  3. mysql中now()函数的使用,还有oracle的sysdate,可能埋下的坑

    mysql中now()函数的使用,还有oracle的sysdate 在需求中如果系统中药添加当前操作的时间那么很简单的一个操作在写sql的时候直接在这个字段对应的位置写上now()函数就可以了,这样就 ...

  4. 使用腾讯开发平台获取QQ用户数据资料

    <今天是七夕:祝大家七夕嗨皮,前可么么哒,后可啪啪啪> Tips:本篇博客将教你如何使用腾讯开发平台获取QQ用户资料 ----------------------------------- ...

  5. Alpha阶段发布说明

    Alpha版本功能介绍 机器法官功能已实现 这是我们统计了当下所有存在的狼人APP的共同缺点.也是用户最主要的痛点.现在所有已知存在的类似APP都不能提供法官功能,我们的APP将该功能革命性的自动实现 ...

  6. Node.js入门笔记(5):案例两则

    案例分析:前端自动化 1. 实现一个自动创建前端项目文件的js 通过node.js自动创建前端项目目录,包括js目录,js目录css目录,index.html和对应的内容. 初步的代码如下: var ...

  7. zabbix添加监控主机(三)

    zabbix添加监控服务器. zabbix添加监控服务器(以添加10.10.100.137为例) (1)创建要监控的主机.点击配置(configuration)–>主机(host) –>创 ...

  8. 阿里巴巴分布式服务框架dubbo学习笔记

    Dubbo是什么? Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.简单的说,dubbo就是个服务框架,如果没有分布式的需求,其实是不需要用的 ...

  9. C# 读取excel日期时获取到数字转换成日期

    string strDate= DateTime.FromOADate(Convert.ToInt32(data[i][7])).ToString("d"); strDate= D ...

  10. Authcode()

    加密解密函数Authcode(): 1.  // 参数解释   2. // $string: 明文 或 密文   3. // $operation:DECODE表示解密,其它表示加密   4. //  ...