mocha-test-url

0.1.17 • Public • Published

mocha-test-url

Easy to test running on Node.js

NPM

Screenshot


Installation

Require Node >= 8
Install through NPM mocha, chai and chai-http

npm install mocha
npm install chai
npm install chai-http

Next step install mocha-test-url

npm install mocha-test-url

In package.json

"scripts"{
    "test-permission": "mocha test/page-permission.js"
}

Usage

 
var testUrl = require('mocha-test-url');
 
/* -------------- Setup Server -------------- */
 
testUrl.setHost('http://localhost:4003');
testUrl.setUrlLogin('/mocha/login');
 
describe("Init Page Permission", function () {
    before(function() {
        this.timeout(150000);
        return new Promise(function (resolve) {
            /* -------------- Setup User -------------- */
            
            // Guest
            testUrl.addUser('Guest');
            
            resolve(true);
        })
 
    });
 
    after(function() {
        // Running check permission
        testUrl.runTest();
        // List status code
        // testUrl.runList();
    });
 
    describe("init", function () {
        it(`Setup Path and Permission`, function (done) {
            
            /* -------------- Setup Route -------------- */
 
            testUrl.setGroup('Page Permission');
            
            testUrl.setURLAndCheck(
                'View Page Product',
                '/page',
                'get'
            );
            
            done();
        });
    });
});
npm run test-permission

Setup

Setup host and path user login

testUrl.setHost(localhost);
testUrl.setUrlLogin(pathLogin); // method post

Setup Header

testUrl.setHeader(name,value);

Setup user login

Setup in before() after testUrl.addUser('Guest');

testUrl.addUser(email, password,name);

Setup group and url

First you will setup group

testUrl.setGroup(groupName);

Next setup url and permission

testUrl.setURLAndCheck(title,path,method,checkStatusCode);

Setup running

Setup in after()

testUrl.runTest();

or

testUrl.runList();

Preference

checkStatusCode

  • checkStatus (status) - Number check the number with status code
  • checkJSON (status, hasValue, value) - Number, String, String check the number with status code, hasValue check key in return type and value (optional) check value
  • checkDataAndStatus (status, hasMessage) - Number, String check the number with status code and hasMessage check text in data return
  • checkCustom (customFunction) - Function use custom function to check data customFunction have 2 parameter headerStatus,dataPageReturn. When error use function assertError(String) to return false

Example

testUrl.setURLAndCheck(
    'View Page',
    '/page/setting',
    'get',
    [
        testUrl.checkDataAndStatus(100, 'Error'), // Guest
        testUrl.checkStatus(200), // Admin
        testUrl.checkStatus(100), // Normal User
    ]
);

Readme

Keywords

Package Sidebar

Install

npm i mocha-test-url

Weekly Downloads

19

Version

0.1.17

License

MIT

Unpacked Size

12.4 kB

Total Files

4

Last publish

Collaborators

  • thenai