gangway
Advanced tools
Comparing version 2.0.0 to 2.1.0
# Changelog | ||
## 2.1.0 | ||
- Upgrade superagent to 1.8.x | ||
- Add `buildQuery` option to define custom query string behavior | ||
## 2.0.0 | ||
@@ -4,0 +9,0 @@ |
# Gangway Documentation | ||
1. [Guides](#guides) | ||
2. [API](#api) | ||
## Guides | ||
@@ -4,0 +7,0 @@ |
{ | ||
"name": "gangway", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A client-side API abstraction layer", | ||
@@ -22,3 +22,3 @@ "engines": { | ||
"dependencies": { | ||
"superagent": "~1.7" | ||
"superagent": "~1.8" | ||
}, | ||
@@ -25,0 +25,0 @@ "devDependencies": { |
@@ -135,2 +135,3 @@ # Gangway | ||
onError : Run before rejecting a request to preprocessing errors | ||
buildQuery : Run before a query string stringifies. | ||
params : Populate bindings in paths and are sent as request bodies. Defaults to body. | ||
@@ -144,2 +145,16 @@ Promise : The Promise implementation. Defaults to global.Promise. | ||
### Responses | ||
Gangway wraps around superagent, leaning on it to build a response | ||
object. [This object is documented within superagent](https://visionmedia.github.io/superagent/#response-properties), | ||
however the important parts are: | ||
```javascript | ||
{ | ||
"text": "...", // The unparsed response body string | ||
"body": {}, // The parsed response body | ||
"status": 200 // The HTTP status code for the request | ||
} | ||
``` | ||
*** | ||
@@ -146,0 +161,0 @@ |
@@ -23,3 +23,3 @@ var Mock = require('./mock') | ||
.send(options.body) | ||
.query(options.query) | ||
.query(options.buildQuery(options.query)) | ||
.set(options.headers) | ||
@@ -26,0 +26,0 @@ .timeout(options.timeout) |
@@ -21,2 +21,3 @@ /** | ||
type : 'application/json', | ||
buildQuery : function(query) { return query }, | ||
beforeSend : function(ajax) { return ajax }, | ||
@@ -23,0 +24,0 @@ onResponse : function(response) { return response.body }, |
@@ -191,2 +191,89 @@ var ajax = require('../src/ajax') | ||
}) | ||
it ('can configure how query parameters are stringified', function () { | ||
var message = ajax({ | ||
baseURL : baseURL, | ||
buildQuery : function (query) { | ||
return 'foo=bar' | ||
} | ||
}) | ||
assert.deepEqual(message.qsRaw, [ 'foo=bar' ]) | ||
}) | ||
describe('Promise decoration', function() { | ||
it ('can chain off of requests', function (done) { | ||
var message = ajax({ | ||
baseURL : baseURL, | ||
path : '/base/test/response.json' | ||
}) | ||
message.then(function() { | ||
done() | ||
}) | ||
}) | ||
it ('can catch rejected promises', function (done) { | ||
var message = ajax({ | ||
baseURL : baseURL, | ||
path : '/base/test/404.json' | ||
}) | ||
message.catch(function (error) { | ||
done() | ||
}) | ||
}) | ||
it ('supports the done() Promise method', function (done) { | ||
var message = ajax({ | ||
baseURL : baseURL, | ||
path : '/base/test/response.json' | ||
}) | ||
message.done(function (error) { | ||
done() | ||
}) | ||
}) | ||
context('when done() raises an error', function() { | ||
beforeEach(function() { | ||
this.originalTimeout = global.setTimeout | ||
}) | ||
afterEach(function() { | ||
global.setTimeout = this.originalTimeout | ||
}) | ||
it ('done errors bubble out', function (done) { | ||
var message = ajax({ | ||
baseURL : baseURL, | ||
path : '/base/test/response.json' | ||
}) | ||
message.done(function (error) { | ||
global.setTimeout = function(fn) { | ||
assert.throws(fn, /This should fail/) | ||
done() | ||
} | ||
throw new Error('This should fail') | ||
}) | ||
}) | ||
it ('done errors bubble out if given no callback', function (done) { | ||
var message = ajax({ | ||
baseURL : baseURL, | ||
path : '/base/test/response.json' | ||
}) | ||
global.setTimeout = function(fn) { | ||
assert.throws(fn) | ||
done() | ||
} | ||
message.done() | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -122,2 +122,12 @@ var API = require('../src/api') | ||
context('When given a basePath option', function() { | ||
beforeEach(function() { | ||
this.api = API({ basePath: 'test' }) | ||
}) | ||
it ('adds that path to the segment', function() { | ||
assert.deepEqual(this.api.segments, [ 'test' ]) | ||
}) | ||
}) | ||
context('when a route is executed', function() { | ||
@@ -124,0 +134,0 @@ var api = API({ |
52442
971
165
+ Addedasync@1.5.2(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@1.0.0-rc3(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedsuperagent@1.8.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedform-data@0.2.0(transitive)
- Removedmime-db@1.12.0(transitive)
- Removedmime-types@2.0.14(transitive)
- Removedsuperagent@1.7.2(transitive)
Updatedsuperagent@~1.8