0.1.17 • Published 6 years ago
mocha-test-url v0.1.17
mocha-test-url
Easy to test running on Node.js
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 codecheckJSON (status, hasValue, value)
- Number, String, String check the number with status code, hasValue check key in return type and value (optional) check valuecheckDataAndStatus (status, hasMessage)
- Number, String check the number with status code and hasMessage check text in data returncheckCustom (customFunction)
- Function use custom function to check data customFunction have 2 parameter headerStatus,dataPageReturn. When error use functionassertError(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
]
);
0.1.17
6 years ago
0.1.16
6 years ago
0.1.15
6 years ago
0.1.14
6 years ago
0.1.13
6 years ago
0.1.12
6 years ago
0.1.11
6 years ago
0.1.10
6 years ago
0.1.9
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.7
6 years ago
0.0.6
6 years ago
0.0.5
6 years ago
0.0.4
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago