Browse Source

tests : apis /dynamic* and listing with where complicated clause

pull/13/head
oof1lab 7 years ago
parent
commit
0d0b63c4a4
  1. 2
      lib/util/cmd.helper.js
  2. 2
      package.json
  3. 102
      tests/tests.js

2
lib/util/cmd.helper.js

@ -11,7 +11,7 @@ program.on('--help', () => {
})
program
.version('0.2.0')
.version('0.2.1')
.option('-h, --host <n>', 'hostname')
.option('-d, --database <n>', 'database schema name')
.option('-u, --user <n>', 'username of database / root by default')

2
package.json

@ -1,6 +1,6 @@
{
"name": "xmysql",
"version": "0.2.0",
"version": "0.2.1",
"description": "One command to generate REST APIs for any MySql database",
"main": "index.js",
"scripts": {

102
tests/tests.js

@ -6,8 +6,9 @@ var mysql = require('mysql')
var Xapi = require('../lib/xapi.js')
var whereClause = require('../lib/util/whereClause.helper.js')
var should = require('should');
var request = require('supertest')
const cmdargs = require('../lib/util/cmd.helper.js');
var args = {}
var app = {}
@ -27,6 +28,8 @@ describe('xmysql : tests', function () {
before(function (done) {
cmdargs.handle(args)
mysqlPool = mysql.createPool(args)
app = express()
@ -456,6 +459,84 @@ describe('xmysql : tests', function () {
});
it('POST /dynamic should PASS', function (done) {
var obj = {};
obj['query'] = 'select * from ?? limit 0,5'
obj['params'] = ['customers']
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//validate response
res.body.length.should.be.equals(5)
return done();
});
});
it('POST /dynamic/abc should PASS', function (done) {
var obj = {};
obj['query'] = 'select * from ?? limit 0,5'
obj['params'] = ['customers']
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//validate response
res.body.length.should.be.equals(5)
return done();
});
});
it('POST /dynamic should PASS', function (done) {
var obj = {};
obj['query'] = 'select * from customers limit 0,5'
obj['params'] = []
//post to an url with data
agent.post('/dynamic') //enter url
.send(obj) //postdata
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//validate response
res.body.length.should.be.equals(5)
return done();
});
});
it('PUT /api/customers/:id should PASS', function (done) {
var obj = {};
@ -608,6 +689,25 @@ describe('xmysql : tests', function () {
});
});
it('GET /api/payments?_where=((checkNumber,eq,JM555205)~or(checkNumber,eq,OM314933)) should PASS', function (done) {
//post to an url with data
agent.get('/api/payments?_where=((checkNumber,eq,JM555205)~or(checkNumber,eq,OM314933))') //enter url
.expect(200)//200 for success 4xx for failure
.end(function (err, res) {
// Handle /api/v error
if (err) {
return done(err);
}
//validate response
res.body.length.should.be.equals(2)
return done();
});
});
it('GET /api/employees/1002/employees should PASS', function (done) {
//post to an url with data

Loading…
Cancel
Save