Skip to content

Commit

Permalink
Use native promises
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Mar 23, 2018
1 parent 7ad2965 commit 722a12f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
"env": {
"node": true
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
Expand Down
1 change: 0 additions & 1 deletion lib/StripeMethod.basic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var Promise = require('bluebird');
var isPlainObject = require('lodash.isplainobject');
var stripeMethod = require('./StripeMethod');

Expand Down
1 change: 0 additions & 1 deletion lib/StripeMethod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var Promise = require('bluebird');
var utils = require('./utils');
var OPTIONAL_REGEX = /^optional!/;

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
"chai": "~4.1.2",
"chai-as-promised": "~7.1.1",
"coveralls": "^3.0.0",
"eslint": "^4.6.1",
"eslint": "^4.19.1",
"eslint-plugin-chai-friendly": "^0.4.0",
"mocha": "~3.5.3",
"mocha": "~5.0.5",
"nyc": "^11.3.0"
},
"dependencies": {
"bluebird": "^3.5.0",
"lodash.isplainobject": "^4.0.6",
"qs": "~6.5.1",
"safe-buffer": "^5.1.1"
Expand Down
17 changes: 8 additions & 9 deletions test/flows.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var testUtils = require('./testUtils');
var chai = require('chai');
var Promise = require('bluebird');
var stripe = require('../lib/stripe')(
testUtils.getUserStripeKey(),
'latest'
Expand Down Expand Up @@ -37,7 +36,7 @@ describe('Flows', function() {
describe('Plan+Subscription flow', function() {
it('Allows me to: Create a plan and subscribe a customer to it', function() {
return expect(
Promise.join(
Promise.all([
stripe.plans.create({
id: 'plan' + testUtils.getRandomString(),
amount: 1700,
Expand All @@ -49,7 +48,7 @@ describe('Flows', function() {
},
}),
stripe.customers.create(CUSTOMER_DETAILS)
).then(function(j) {
]).then(function(j) {
var plan = j[0];
var customer = j[1];

Expand All @@ -68,7 +67,7 @@ describe('Flows', function() {
function() {
var plan;
return expect(
Promise.join(
Promise.all([
stripe.plans.create({
id: 'plan' + testUtils.getRandomString(),
amount: 1700,
Expand All @@ -80,7 +79,7 @@ describe('Flows', function() {
},
}),
stripe.customers.create(CUSTOMER_DETAILS)
).then(function(j) {
]).then(function(j) {
plan = j[0];
var customer = j[1];

Expand Down Expand Up @@ -122,7 +121,7 @@ describe('Flows', function() {

it('Allows me to: subscribe then cancel with `at_period_end` defined', function() {
return expect(
Promise.join(
Promise.all([
stripe.plans.create({
id: 'plan' + testUtils.getRandomString(),
amount: 1700,
Expand All @@ -134,7 +133,7 @@ describe('Flows', function() {
},
}),
stripe.customers.create(CUSTOMER_DETAILS)
).then(function(j) {
]).then(function(j) {
var plan = j[0];
var customer = j[1];

Expand Down Expand Up @@ -187,13 +186,13 @@ describe('Flows', function() {
describe('When I create a coupon & customer', function() {
it('Does so', function() {
return expect(
Promise.join(
Promise.all([
stripe.coupons.create({
percent_off: 20,
duration: 'once',
}),
stripe.customers.create(CUSTOMER_DETAILS)
).then(function(joined) {
]).then(function(joined) {
coupon = joined[0];
customer = joined[1];
})
Expand Down
1 change: 0 additions & 1 deletion test/resources/Customers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var stripe = require('../testUtils').getSpyableStripe();
var expect = require('chai').expect;
var Promise = require('bluebird');

var TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11';

Expand Down
21 changes: 10 additions & 11 deletions test/stripe.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var testUtils = require('./testUtils');
var Promise = require('bluebird');
var stripe = require('../lib/stripe')(
testUtils.getUserStripeKey(),
'latest'
Expand Down Expand Up @@ -37,20 +36,20 @@ describe('Stripe Module', function() {
describe('GetClientUserAgentSeeded', function() {
it('Should return a user-agent serialized JSON object', function() {
var userAgent = {lang: 'node'};
var d = Promise.defer();
stripe.getClientUserAgentSeeded(userAgent, function(c) {
d.resolve(JSON.parse(c));
});
return expect(d.promise).to.eventually.have.property('lang', 'node');
return expect(new Promise(function(resolve, reject) {
stripe.getClientUserAgentSeeded(userAgent, function(c) {
resolve(JSON.parse(c));
});
})).to.eventually.have.property('lang', 'node');
});

it('Should URI-encode user-agent fields', function() {
var userAgent = {lang: 'ï'};
var d = Promise.defer();
stripe.getClientUserAgentSeeded(userAgent, function(c) {
d.resolve(JSON.parse(c));
});
return expect(d.promise).to.eventually.have.property('lang', '%C3%AF');
return expect(new Promise(function(resolve, reject) {
stripe.getClientUserAgentSeeded(userAgent, function(c) {
resolve(JSON.parse(c));
});
})).to.eventually.have.property('lang', '%C3%AF');
})
});

Expand Down

0 comments on commit 722a12f

Please sign in to comment.