2.0.3 • Published 9 years ago

ivitest v2.0.3

Weekly downloads
59
License
-
Repository
github
Last release
9 years ago

iviTest

NPM version Stories in Ready

NPM

Simple REST API unit test, based from vowsjs and request.
Use chaijs to find BDD & TDD documentation.

Simple to use

just place your code in test folder inside ivitest main folder, or you can create custom folder anywhere.

    {
        request     : {}, // GLOBAL
        response    : {}, // GLOBAL
        "a context" : {  // LOCAL
            request     : {},
            response    : {},
            callback    : function(err,res,body) {},
            before      : function(data,done) {},
            after       : function(data,done) {}
        }
    }

Request

    {
        url     : "http://google.com",
        method  : "GET", // POST, GET, PUT, & etc
        headers : {
            'Content-Type': 'text/plain'
        }
    }

Response

Check data type

    // sample response
    // {
    //      data : [],
    //      list : [],
    //      body : {},
    //      foo  : {},
    //      "check the child" : {
    //          name    : "",
    //          address : "",
    //          years   : 2014,
    //          age     : 26,
    //      }
    // }
    {
        array   : ["data","list"],
        object  : ["body","foo"],
        "check the child"  : {
            string  : ["name","address"],
            number  : ["years","age"],
        }
    }

Check object inside array

    //  sample response
    //  [
    //      {
    //          "name"      : "yuda",
    //          "adress"    : "surabaya",
    //      }
    //  ]
    {
        each   : ["name","address"] // each response has property name and address
    }

callback

assert, should or expect can directly call from this function

    // sample response
    // {
    //      data : [],
    //      list : [],
    //      foo  : {},
    //      "check the child" : {
    //          name    : "",
    //          address : "",
    //          years   : 2014,
    //          age     : 26,
    //      }
    // }
    callback: function(err,response,body) {
        body.should.have.property("data").be.a("array");
        expect(body).to.have.property("list").to.be.a("array");
        assert((typeof body.foo)=="object")
    }

if you want to use first response as second request

    var google = {
        "request1" : {
            request     : { 
                method  : "GET",
                url     : "http://google.com",
            },
            response    : {
                statusCode  : 200
            },
            callback    : function(err,res,body) {
                return {
                    body : {
                        status : res.statusCode
                    }
                }
            }
        },
        "request2" : {
            request     : {
                method  : "POST",
                url     : "http://custom.com/getstatus",
                body    : {
                    detail : "status from google"
                }
            },
            response    : {
                statusCode  : 200
            }
        }
    }

    module.exports = google;

Before & After

    var mongoose = require("mongoose");
    mongoose.connect("mongodb://localhost/mydb");
    var user = mongoose.model("users",{},"users);
    var google = {
        "request1" : {
            request     : { 
                method  : "GET",
                url     : "http://google.com",
            },
            response    : {
                statusCode  : 200
            },
            callback    : function(err,res,body) {
            },
            before : function(data,done) {
                var su = new user({name:"yuda"});
                su.save(function(err) {
                    data.name = "yuda";
                    done();
                })
            },
            after : function(data,done) {
                su.remove({name:data.name},function() {
                    done();
                })
            }
        }
    }

    module.exports = google;

then execute them : ivitest
if you want to run test in other folder : ivitest -t /foldername
if you want to know all file to run : ivitest -l
if you want to execute just one file ( not all in one hit ) : ivitest -c 1
( number 1 can change with other number or string file name )

to see help : ivitest -h

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.0

10 years ago

0.9.7

10 years ago

0.9.6

10 years ago

0.9.5

10 years ago

0.9.4

10 years ago

0.9.3

10 years ago

0.9.1

10 years ago

0.9.0

10 years ago

0.5.0

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.0

10 years ago