Comparing version 1.0.1 to 1.0.2
127
bin/index.js
var _ = require('underscore'); | ||
var http = require("http"); | ||
var assert = require("assert"); | ||
var http = require('http'); | ||
var jsonPath = require('JSONPath').eval; | ||
@@ -8,15 +7,18 @@ | ||
// Setup the defaults. | ||
var options = { | ||
method: null, | ||
url: null, | ||
headers: {}, | ||
datatype: null, | ||
data: null, | ||
parse: null, | ||
_hasParse: false, | ||
headers: {}, | ||
method: 'GET', | ||
url: null, | ||
datatype: null, | ||
data: null, | ||
parse: null, | ||
assertions: null, | ||
debug: false, | ||
_query: [] | ||
debug: false, | ||
// Meta Fields. | ||
_query: [], | ||
_hasParse: false | ||
}; | ||
// Defined the hostname. | ||
options.host = function(host) { | ||
@@ -32,3 +34,4 @@ this.hostname = host; | ||
// Methods | ||
// Add to the _query to add to the | ||
// array of options. Supports string, array or object. | ||
options.query = function(opt) { | ||
@@ -44,3 +47,3 @@ this._query.push(opt) | ||
// Methods | ||
// HTTP Methods | ||
options.get = function(query) { | ||
@@ -76,3 +79,2 @@ this.method = 'GET'; | ||
// Object | ||
// If we get { key, value } | ||
if (typeof data == 'object') { | ||
@@ -83,3 +85,2 @@ this.headers[data.key] = data.value; | ||
// Array | ||
// If we get { key, value } | ||
if (typeof data == 'array') { | ||
@@ -121,15 +122,9 @@ this.headers[data[0]] = data[1]; | ||
// Helder Method to handle _assertions. | ||
options.handleAssertions = function(done) { | ||
var that = this; | ||
var jsonResponse = this.result; | ||
for (var path in this.assertions) { | ||
var pathSearchResult = jsonPath(jsonResponse, path); | ||
console.log(path) | ||
if (pathSearchResult.length == 1) | ||
pathSearchResult = pathSearchResult[0]; | ||
if (pathSearchResult.length == 1) pathSearchResult = pathSearchResult[0]; | ||
that.assertions[path](pathSearchResult); | ||
@@ -139,2 +134,3 @@ } | ||
// Helper method to build the Query string field=100&field2=300 | ||
options._getQuery = function() { | ||
@@ -147,3 +143,2 @@ return '?' + _.map(this._query, function(o) { | ||
var t = _.each(o, function(v, k) { return n[k] + '=' + v; }) | ||
console.log('ddddd', t); | ||
return n; | ||
@@ -158,5 +153,6 @@ } | ||
var opts = { | ||
path: this.path + this._getQuery(), | ||
path: this.path + this._getQuery(), | ||
hostname: this.hostname, | ||
method: this.method, | ||
method: this.method, | ||
// Move the API Key to setup. | ||
headers: { | ||
@@ -204,2 +200,3 @@ 'api_key': 'stagingTEMPkey' | ||
// Build the result for testing. | ||
that.result = { | ||
@@ -219,8 +216,5 @@ statusCode: res.statusCode, | ||
call.on('error', function(e) { | ||
console.log('Error: ' + e); | ||
}); | ||
call.on('error', function(e) { console.log('Error: ' + e); }); | ||
// Write data to request body | ||
if (jsonData) call.write(jsonData); | ||
@@ -234,74 +228,1 @@ call.end(); | ||
})(); | ||
api.host('staging-api.formagg.io'); | ||
var test1 = _.clone(api); | ||
describe('/relationship', function(done) { | ||
// it('should retreive a maker', function(done){ | ||
// _.clone(api) | ||
// .path('/maker/510df090da57f2000000011e') | ||
// .json() | ||
// .get() | ||
// .debug(false) | ||
// .assertions( | ||
// { | ||
// '$.name': function(val) { assert.equal(val, 'Lactalis') } | ||
// } | ||
// ) | ||
// .done(done); | ||
// } | ||
// ); | ||
it('should give us the new maker', function(done){ | ||
_.clone(api) | ||
.path('/maker') | ||
.query('a=111') | ||
.query( [ 't=11', 'r4=222']) | ||
.query('b=111') | ||
.json() | ||
.post( | ||
{ | ||
name: 'This little test', | ||
source: 'cow', | ||
texture: 'Blue' | ||
} | ||
) | ||
.debug(true) | ||
.assertions( | ||
{ | ||
'$.statusCode': function(val) { assert.equal(val, 401) }, | ||
'$.data': function(val) { assert.equal(val, 'Unauthorized') }, | ||
'$.raw': function(val) { assert.equal(val, '111') } | ||
} | ||
) | ||
.done(done); | ||
} | ||
); | ||
}); | ||
// .parse( | ||
// function(d) { | ||
// console.log(d.name) | ||
// return d.name | ||
// } | ||
// ) | ||
// test1 | ||
// .url('/maker') | ||
// .post( | ||
// { | ||
// name: 'Bobo Creamery', | ||
// country: 'United States', | ||
// state: 'Vermont' | ||
// } | ||
// ) | ||
// .success( | ||
// { | ||
// t1: 'assert.equal(1, 1)', | ||
// t2: 'assert.equal(1, 1)' | ||
// } | ||
// ) | ||
// .done(); |
@@ -8,22 +8,21 @@ var isAPI = require('./bin'); | ||
var test1 = _.clone(api); | ||
describe('/relationship', function(done) { | ||
// it('should retreive a maker', function(done){ | ||
// _.clone(api) | ||
// .path('/maker/510df090da57f2000000011e') | ||
// .json() | ||
// .get() | ||
// .debug(false) | ||
// .assertions( | ||
// { | ||
// '$.name': function(val) { assert.equal(val, 'Lactalis') } | ||
// } | ||
// ) | ||
// .done(done); | ||
// } | ||
// ); | ||
it('should retreive a maker', function(done){ | ||
_.clone(api) | ||
.path('/maker/510df090da57f2000000011e') | ||
.json() | ||
.get() | ||
.debug(false) | ||
.assertions( | ||
{ | ||
'$.name': function(val) { assert.equal(val, 'Lactalis') } | ||
} | ||
) | ||
.done(done); | ||
} | ||
); | ||
it('should give us the new maker', function(done){ | ||
_.clone(api) | ||
@@ -56,24 +55,1 @@ .path('/maker') | ||
// .parse( | ||
// function(d) { | ||
// console.log(d.name) | ||
// return d.name | ||
// } | ||
// ) | ||
// test1 | ||
// .url('/maker') | ||
// .post( | ||
// { | ||
// name: 'Bobo Creamery', | ||
// country: 'United States', | ||
// state: 'Vermont' | ||
// } | ||
// ) | ||
// .success( | ||
// { | ||
// t1: 'assert.equal(1, 1)', | ||
// t2: 'assert.equal(1, 1)' | ||
// } | ||
// ) | ||
// .done(); |
{ | ||
"name": "isapi.js", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": "Stephan Smith <Stephan.Smith.BC93@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Chained Rest functions for testing API with Mocha or Jasmine.", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
13537
220