Skip to content

Commit

Permalink
version 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rob schieber committed Oct 13, 2012
1 parent bd23f77 commit cd2c1a1
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ lib-cov
*.out
*.pid
*.gz
*.idea
*.iml

pids
logs
results

node_modules
npm-debug.log
npm-debug.log
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (C) 2012 Rob Schieber

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
90 changes: 90 additions & 0 deletions lib/mockey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(function (module) {
var request = require('request'),
qs = require('qs');

module.exports = {
configureService:function (config, callbackFn) {

var self = this,
parms = qs.stringify(config);

request('http://127.0.0.1:8080/config/service?' + parms,
function (error, response, body) {
if (response && response.statusCode === 200) {
var temp = JSON.parse(body);
callbackFn && callbackFn.call(self, temp.result);
}
else {
console.log('error: ' + response.statusCode);
console.log(body);
}
});
},
getServiceDefinitions:function (params, callbackFn) {
var self = this;

request('http://127.0.0.1:8080/definitions?' + qs.stringify(params),
function (error, response, body) {
if (response && response.statusCode === 200) {
var temp = JSON.parse(body);
callbackFn && callbackFn.call(self, temp);
}
else {
console.log('error: ' + response.statusCode);
console.log(body);
}
});
},
setPlan:function (params, callbackFn) {
var self = this;
params.action = 'set_plan';
params.type = 'json';

request('http://127.0.0.1:8080/plan/setup?' + qs.stringify(params),
function (error, response, body) {
if (response && response.statusCode === 200) {
var temp = JSON.parse(body);
callbackFn && callbackFn.call(self, temp);
}
else {
console.log('error: ' + response.statusCode);
console.log(body);
}
});
},
deletePlan:function (params, callbackFn) {
var self = this;
params.action = 'delete_plan';
params.type = 'json';

request('http://127.0.0.1:8080/plan/setup?' + qs.stringify(params),
function (error, response, body) {
if (response && response.statusCode === 200) {
var temp = JSON.parse(body);
callbackFn && callbackFn.call(self, temp);
}
else {
console.log('error: ' + response.statusCode);
console.log(body);
}
});
},
savePlan:function (params, callbackFn) {
var self = this;
params.action = 'save_plan';
params.type = 'json';

request('http://127.0.0.1:8080/plan/setup?' + qs.stringify(params),
function (error, response, body) {
if (response && response.statusCode === 200) {
var temp = JSON.parse(body);
callbackFn && callbackFn.call(self, temp);
}
else {
console.log('error: ' + response.statusCode);
console.log(body);
}
});
}
};
}(module));
47 changes: 47 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
describe('mockey', function () {
var should = require("should"),
assert = require('assert'),
colors = require('colors'),
mockey = require('../index');
describe('#configureService()', function () {

it('should return a response', function (done) {
this.timeout(1000);
mockey.configureService({
serviceName:'Auth',
scenerioName:'invalid',
serviceResponseType:'static'
//serviceId:0,
//scenerioId:0,
//hangTime:0,
//transientState:true,

}, function (response) {
assert.equal(response.serviceName, 'Auth');
done();
});
});
});
describe('#getServiceDefinitions()', function () {

it('should return a response', function (done) {
this.timeout(1000);
mockey.getServiceDefinitions({serviceName:'Auth'}, function (response) {
should.exist(response.serviceDefinitions);
done();
});
});
});
describe('#savePlan()', function () {

it('should return a response', function (done) {
this.timeout(1000);
mockey.savePlan({service_plan_name:'planA'}, function (response) {
should.exist(response);
done();
});
});
});
});


0 comments on commit cd2c1a1

Please sign in to comment.