Skip to content

Commit

Permalink
Promise fix (#17)
Browse files Browse the repository at this point in the history
* Update tests.

* Add Node 7 to travis config

* Use bluebird Promise

* Update version.

* Update changelog.
  • Loading branch information
sausman committed Oct 31, 2016
1 parent 9cd18f2 commit 03a03f4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,6 +1,7 @@
language: node_js

node_js:
- '7'
- '6'
- '5'
- '5.1'
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -220,6 +220,7 @@ The gem is available as open source under the terms of the [MIT License](https:/

## Changelog

- **1.2.3** Use Bluebird Promise in Auth to prevent Promise undefined error.
- **1.2.2** Upgrade `node-fetch` dependency to fix `form-data` compatibility ([#15][/Dwolla/dwolla-v2-node/issues/15])
- **1.2.1** Add support for `verified_account` and `dwolla_landing` auth flags
- **1.2.0** Reject promises with Errors instead of plain objects ([#8](/Dwolla/dwolla-v2-node/issues/8))
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "dwolla-v2",
"version": "1.2.2",
"version": "1.2.3",
"description": "Dwolla V2 API client",
"main": "src/index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/dwolla/Auth.js
Expand Up @@ -4,8 +4,9 @@ var assign = require('lodash/assign');
var invariant = require('invariant');
var rejectEmptyKeys = require('../util/rejectEmptyKeys');
var toJson = require('../util/toJson');
var Promise = require('bluebird');

fetch.Promise = require('bluebird');
fetch.Promise = Promise;

function errorFrom(parsedRes) {
var error = new Error(JSON.stringify(parsedRes));
Expand Down
15 changes: 9 additions & 6 deletions test/dwolla/Auth.test.js
Expand Up @@ -95,10 +95,11 @@ describe('Auth', function() {
var code = 'code';
var redirect_uri = 'redirect uri';
var auth = new client.Auth({ redirect_uri: redirect_uri, state: state });
var error = { error: 'error' };
nock(client.tokenUrl, { reqheaders: requestHeaders })
.post('', { client_id: client.id, client_secret: client.secret, grant_type: 'authorization_code', code: code, redirect_uri: redirect_uri })
.reply(200, { error: 'error' });
expect(auth.callback({ state: state, code: code })).to.be.rejected.and.notify(done);
.reply(200, error);
expect(auth.callback({ state: state, code: code })).to.be.rejectedWith(error).and.notify(done);
});

it('auth.client successful response', function(done) {
Expand All @@ -109,10 +110,11 @@ describe('Auth', function() {
});

it('auth.client error response', function(done) {
var error = { error: 'error' }
nock(client.tokenUrl, { reqheaders: requestHeaders })
.post('', { client_id: client.id, client_secret: client.secret, grant_type: 'client_credentials' })
.reply(200, { error: 'error' });
expect(client.auth.client()).to.be.rejected.and.notify(done);
.reply(200, error);
expect(client.auth.client()).to.be.rejectedWith(error).and.notify(done);
});

it('auth.refresh successful response', function(done) {
Expand All @@ -124,11 +126,12 @@ describe('Auth', function() {
});

it('auth.refresh error response', function(done) {
var error = { error: 'error' };
var token = new client.Token({ refresh_token: 'refresh token' });
nock(client.tokenUrl, { reqheaders: requestHeaders })
.post('', { client_id: client.id, client_secret: client.secret, grant_type: 'refresh_token', refresh_token: token.refresh_token })
.reply(200, { error: 'error' });
expect(client.auth.refresh(token)).to.be.rejected.and.notify(done);
.reply(200, error);
expect(client.auth.refresh(token)).to.be.rejectedWith(error).and.notify(done);
});

it('calls onGrant', function(done) {
Expand Down

0 comments on commit 03a03f4

Please sign in to comment.