diff --git a/.eslintrc.js b/.eslintrc.js index 2b21ed9160..6d8aa70f17 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,7 +7,6 @@ module.exports = { 'accessor-pairs': 'error', 'array-bracket-spacing': ['error', 'never'], 'array-callback-return': 'off', - 'arrow-body-style': 'error', 'arrow-parens': 'error', 'arrow-spacing': 'error', 'block-scoped-var': 'off', @@ -43,7 +42,7 @@ module.exports = { 'func-call-spacing': 'error', 'func-name-matching': 'error', 'func-names': 'off', - 'func-style': ['error', 'declaration'], + 'func-style': ['error', 'declaration', {allowArrowFunctions: true}], 'generator-star-spacing': 'error', 'global-require': 'off', 'guard-for-in': 'off', diff --git a/examples/webhook-signing/express.js b/examples/webhook-signing/express.js index f011e631ca..9317c86f7d 100644 --- a/examples/webhook-signing/express.js +++ b/examples/webhook-signing/express.js @@ -37,6 +37,6 @@ app.post( } ); -app.listen(3000, function() { +app.listen(3000, () => { console.log('Example app listening on port 3000!'); }); diff --git a/lib/Error.js b/lib/Error.js index cc7a0d18df..6e5bd43e67 100644 --- a/lib/Error.js +++ b/lib/Error.js @@ -1,6 +1,6 @@ 'use strict'; -var utils = require('./utils'); +const utils = require('./utils'); module.exports = _Error; @@ -8,7 +8,7 @@ module.exports = _Error; * Generic Error klass to wrap any errors returned by stripe-node */ function _Error(raw) { - this.populate.apply(this, arguments); + this.populate(...arguments); this.stack = new Error(this.message).stack; } @@ -27,9 +27,9 @@ _Error.extend = utils.protoExtend; * Create subclass of internal Error klass * (Specifically for errors returned from Stripe's REST API) */ -var StripeError = (_Error.StripeError = _Error.extend({ +const StripeError = (_Error.StripeError = _Error.extend({ type: 'StripeError', - populate: function(raw) { + populate(raw) { // Move from prototype def (so it appears in stringified obj) this.type = this.type; @@ -49,7 +49,7 @@ var StripeError = (_Error.StripeError = _Error.extend({ /** * Helper factory which takes raw stripe errors and outputs wrapping instances */ -StripeError.generate = function(rawStripeError) { +StripeError.generate = (rawStripeError) => { switch (rawStripeError.type) { case 'card_error': return new _Error.StripeCardError(rawStripeError); diff --git a/lib/MultipartDataGenerator.js b/lib/MultipartDataGenerator.js index dbdc0e22ba..76b8cb2962 100644 --- a/lib/MultipartDataGenerator.js +++ b/lib/MultipartDataGenerator.js @@ -1,21 +1,21 @@ 'use strict'; -var Buffer = require('safe-buffer').Buffer; -var utils = require('./utils'); +const Buffer = require('safe-buffer').Buffer; +const utils = require('./utils'); // Method for formatting HTTP body for the multipart/form-data specification // Mostly taken from Fermata.js // https://github.com/natevw/fermata/blob/5d9732a33d776ce925013a265935facd1626cc88/fermata.js#L315-L343 function multipartDataGenerator(method, data, headers) { - var segno = ( + const segno = ( Math.round(Math.random() * 1e16) + Math.round(Math.random() * 1e16) ).toString(); - headers['Content-Type'] = 'multipart/form-data; boundary=' + segno; - var buffer = Buffer.alloc(0); + headers['Content-Type'] = `multipart/form-data; boundary=${segno}`; + let buffer = Buffer.alloc(0); function push(l) { - var prevBuffer = buffer; - var newBuffer = l instanceof Buffer ? l : Buffer.from(l); + const prevBuffer = buffer; + const newBuffer = l instanceof Buffer ? l : Buffer.from(l); buffer = Buffer.alloc(prevBuffer.length + newBuffer.length + 2); prevBuffer.copy(buffer); newBuffer.copy(buffer, prevBuffer.length); @@ -23,29 +23,28 @@ function multipartDataGenerator(method, data, headers) { } function q(s) { - return '"' + s.replace(/"|"/g, '%22').replace(/\r\n|\r|\n/g, ' ') + '"'; + return `"${s.replace(/"|"/g, '%22').replace(/\r\n|\r|\n/g, ' ')}"`; } - for (var k in utils.flattenAndStringify(data)) { - var v = data[k]; - push('--' + segno); + for (const k in utils.flattenAndStringify(data)) { + const v = data[k]; + push(`--${segno}`); if (v.hasOwnProperty('data')) { push( - 'Content-Disposition: form-data; name=' + - q(k) + - '; filename=' + - q(v.name || 'blob') + `Content-Disposition: form-data; name=${q(k)}; filename=${q( + v.name || 'blob' + )}` ); - push('Content-Type: ' + (v.type || 'application/octet-stream')); + push(`Content-Type: ${v.type || 'application/octet-stream'}`); push(''); push(v.data); } else { - push('Content-Disposition: form-data; name=' + q(k)); + push(`Content-Disposition: form-data; name=${q(k)}`); push(''); push(v); } } - push('--' + segno + '--'); + push(`--${segno}--`); return buffer; } diff --git a/lib/ResourceNamespace.js b/lib/ResourceNamespace.js index 2f0c053669..0d76787d81 100644 --- a/lib/ResourceNamespace.js +++ b/lib/ResourceNamespace.js @@ -4,10 +4,10 @@ // It also works recursively, so you could do i.e. `stripe.billing.invoicing.pay`. function ResourceNamespace(stripe, resources) { - for (var name in resources) { - var camelCaseName = name[0].toLowerCase() + name.substring(1); + for (const name in resources) { + const camelCaseName = name[0].toLowerCase() + name.substring(1); - var resource = new resources[name](stripe); + const resource = new resources[name](stripe); this[camelCaseName] = resource; } diff --git a/lib/StripeMethod.basic.js b/lib/StripeMethod.basic.js index a863c38151..1db6b8efbf 100644 --- a/lib/StripeMethod.basic.js +++ b/lib/StripeMethod.basic.js @@ -1,8 +1,8 @@ 'use strict'; -var isPlainObject = require('lodash.isplainobject'); -var stripeMethod = require('./StripeMethod'); -var utils = require('./utils'); +const isPlainObject = require('lodash.isplainobject'); +const stripeMethod = require('./StripeMethod'); +const utils = require('./utils'); module.exports = { create: stripeMethod({ @@ -33,12 +33,12 @@ module.exports = { urlParams: ['id'], }), - setMetadata: function(id, key, value, auth, cb) { - var self = this; - var data = key; - var isObject = isPlainObject(key); + setMetadata(id, key, value, auth, cb) { + const self = this; + const data = key; + const isObject = isPlainObject(key); // We assume null for an empty object - var isNull = data === null || (isObject && !Object.keys(data).length); + const isNull = data === null || (isObject && !Object.keys(data).length); // Allow optional passing of auth & cb: if ((isNull || isObject) && typeof value == 'string') { @@ -50,85 +50,78 @@ module.exports = { auth = null; } - var urlData = this.createUrlData(); - var path = this.createFullPath('/' + id, urlData); + const urlData = this.createUrlData(); + const path = this.createFullPath(`/${id}`, urlData); return utils.callbackifyPromiseWithTimeout( - new Promise( - function(resolve, reject) { - if (isNull) { - // Reset metadata: - sendMetadata(null, auth); - } else if (!isObject) { - // Set individual metadata property: - var metadata = {}; - metadata[key] = value; - sendMetadata(metadata, auth); - } else { - // Set entire metadata object after resetting it: - this._request( - 'POST', - null, - path, - {metadata: null}, - auth, - {}, - function(err, response) { - if (err) { - return reject(err); - } - sendMetadata(data, auth); + new Promise((resolve, reject) => { + if (isNull) { + // Reset metadata: + sendMetadata(null, auth); + } else if (!isObject) { + // Set individual metadata property: + const metadata = {}; + metadata[key] = value; + sendMetadata(metadata, auth); + } else { + // Set entire metadata object after resetting it: + this._request( + 'POST', + null, + path, + {metadata: null}, + auth, + {}, + (err, response) => { + if (err) { + return reject(err); } - ); - } + sendMetadata(data, auth); + } + ); + } - function sendMetadata(metadata, auth) { - self._request( - 'POST', - null, - path, - {metadata: metadata}, - auth, - {}, - function(err, response) { - if (err) { - reject(err); - } else { - resolve(response.metadata); - } + function sendMetadata(metadata, auth) { + self._request( + 'POST', + null, + path, + {metadata}, + auth, + {}, + (err, response) => { + if (err) { + reject(err); + } else { + resolve(response.metadata); } - ); - } - }.bind(this) - ), + } + ); + } + }), cb ); }, - getMetadata: function(id, auth, cb) { + getMetadata(id, auth, cb) { if (!cb && typeof auth == 'function') { cb = auth; auth = null; } - var urlData = this.createUrlData(); - var path = this.createFullPath('/' + id, urlData); + const urlData = this.createUrlData(); + const path = this.createFullPath(`/${id}`, urlData); return utils.callbackifyPromiseWithTimeout( - new Promise( - function(resolve, reject) { - this._request('GET', null, path, {}, auth, {}, function( - err, - response - ) { - if (err) { - reject(err); - } else { - resolve(response.metadata); - } - }); - }.bind(this) - ), + new Promise((resolve, reject) => { + this._request('GET', null, path, {}, auth, {}, (err, response) => { + if (err) { + reject(err); + } else { + resolve(response.metadata); + } + }); + }), cb ); }, diff --git a/lib/StripeMethod.js b/lib/StripeMethod.js index 461cee3756..99f18426a7 100644 --- a/lib/StripeMethod.js +++ b/lib/StripeMethod.js @@ -1,8 +1,8 @@ 'use strict'; -var utils = require('./utils'); -var makeRequest = require('./makeRequest'); -var makeAutoPaginationMethods = require('./autoPagination') +const utils = require('./utils'); +const makeRequest = require('./makeRequest'); +const makeAutoPaginationMethods = require('./autoPagination') .makeAutoPaginationMethods; /** @@ -21,18 +21,18 @@ var makeAutoPaginationMethods = require('./autoPagination') */ function stripeMethod(spec) { return function() { - var self = this; - var args = [].slice.call(arguments); + const self = this; + const args = [].slice.call(arguments); - var callback = typeof args[args.length - 1] == 'function' && args.pop(); + const callback = typeof args[args.length - 1] == 'function' && args.pop(); - var requestPromise = utils.callbackifyPromiseWithTimeout( + const requestPromise = utils.callbackifyPromiseWithTimeout( makeRequest(self, args, spec, {}), callback ); if (spec.methodType === 'list') { - var autoPaginationMethods = makeAutoPaginationMethods( + const autoPaginationMethods = makeAutoPaginationMethods( self, args, spec, diff --git a/lib/StripeResource.js b/lib/StripeResource.js index e6f39bdd18..a252123451 100644 --- a/lib/StripeResource.js +++ b/lib/StripeResource.js @@ -1,17 +1,17 @@ 'use strict'; -var http = require('http'); -var https = require('https'); -var path = require('path'); -var uuid = require('uuid/v4'); +const http = require('http'); +const https = require('https'); +const path = require('path'); +const uuid = require('uuid/v4'); -var utils = require('./utils'); -var Error = require('./Error'); +const utils = require('./utils'); +const Error = require('./Error'); -var hasOwn = {}.hasOwnProperty; +const hasOwn = {}.hasOwnProperty; -var defaultHttpAgent = new http.Agent({keepAlive: true}); -var defaultHttpsAgent = new https.Agent({keepAlive: true}); +const defaultHttpAgent = new http.Agent({keepAlive: true}); +const defaultHttpsAgent = new https.Agent({keepAlive: true}); // Provide extension mechanism for Stripe Resource Sub-Classes StripeResource.extend = utils.protoExtend; @@ -41,7 +41,7 @@ function StripeResource(stripe, urlData) { }, this); } - this.initialize.apply(this, arguments); + this.initialize(...arguments); } StripeResource.prototype = { @@ -50,7 +50,7 @@ StripeResource.prototype = { // Methods that don't use the API's default '/v1' path can override it with this setting. basePath: null, - initialize: function() {}, + initialize() {}, // Function to override the default data processor. This allows full control // over how a StripeResource's request data will get converted into an HTTP @@ -62,7 +62,7 @@ StripeResource.prototype = { // be thrown, and they will be passed to the callback/promise. validateRequest: null, - createFullPath: function(commandPath, urlData) { + createFullPath(commandPath, urlData) { return path .join( this.basePath(urlData), @@ -75,17 +75,16 @@ StripeResource.prototype = { // Creates a relative resource path with symbols left in (unlike // createFullPath which takes some data to replace them with). For example it // might produce: /invoices/{id} - createResourcePathWithSymbols: function(pathWithSymbols) { - return ( - '/' + - path.join(this.resourcePath, pathWithSymbols || '').replace(/\\/g, '/') - ); // ugly workaround for Windows + createResourcePathWithSymbols(pathWithSymbols) { + return `/${path + .join(this.resourcePath, pathWithSymbols || '') + .replace(/\\/g, '/')}`; // ugly workaround for Windows }, - createUrlData: function() { - var urlData = {}; + createUrlData() { + const urlData = {}; // Merge in baseData - for (var i in this._urlData) { + for (const i in this._urlData) { if (hasOwn.call(this._urlData, i)) { urlData[i] = this._urlData[i]; } @@ -96,10 +95,10 @@ StripeResource.prototype = { // DEPRECATED: Here for backcompat in case users relied on this. wrapTimeout: utils.callbackifyPromiseWithTimeout, - _timeoutHandler: function(timeout, req, callback) { - var self = this; - return function() { - var timeoutErr = new Error('ETIMEDOUT'); + _timeoutHandler(timeout, req, callback) { + const self = this; + return () => { + const timeoutErr = new Error('ETIMEDOUT'); timeoutErr.code = 'ETIMEDOUT'; req._isAborted = true; @@ -108,8 +107,7 @@ StripeResource.prototype = { callback.call( self, new Error.StripeConnectionError({ - message: - 'Request aborted due to timeout being reached (' + timeout + 'ms)', + message: `Request aborted due to timeout being reached (${timeout}ms)`, detail: timeoutErr, }), null @@ -117,26 +115,26 @@ StripeResource.prototype = { }; }, - _responseHandler: function(req, callback) { - var self = this; - return function(res) { - var response = ''; + _responseHandler(req, callback) { + const self = this; + return (res) => { + let response = ''; res.setEncoding('utf8'); - res.on('data', function(chunk) { + res.on('data', (chunk) => { response += chunk; }); - res.on('end', function() { - var headers = res.headers || {}; + res.on('end', () => { + const headers = res.headers || {}; // NOTE: Stripe responds with lowercase header names/keys. // For convenience, make Request-Id easily accessible on // lastResponse. res.requestId = headers['request-id']; - var requestDurationMs = Date.now() - req._requestStart; + const requestDurationMs = Date.now() - req._requestStart; - var responseEvent = utils.removeEmpty({ + const responseEvent = utils.removeEmpty({ api_version: headers['stripe-version'], account: headers['stripe-account'], idempotency_key: headers['idempotency-key'], @@ -153,7 +151,7 @@ StripeResource.prototype = { response = JSON.parse(response); if (response.error) { - var err; + let err; // Convert OAuth error responses into a standard format // so that the rest of the error logic can be shared @@ -184,7 +182,7 @@ StripeResource.prototype = { self, new Error.StripeAPIError({ message: 'Invalid JSON received from the Stripe API', - response: response, + response, exception: e, requestId: headers['request-id'], }), @@ -205,18 +203,15 @@ StripeResource.prototype = { }; }, - _generateConnectionErrorMessage: function(requestRetries) { - return ( - 'An error occurred with our connection to Stripe.' + - (requestRetries > 0 - ? ' Request was retried ' + requestRetries + ' times.' - : '') - ); + _generateConnectionErrorMessage(requestRetries) { + return `An error occurred with our connection to Stripe.${ + requestRetries > 0 ? ` Request was retried ${requestRetries} times.` : '' + }`; }, - _errorHandler: function(req, requestRetries, callback) { - var self = this; - return function(error) { + _errorHandler(req, requestRetries, callback) { + const self = this; + return (error) => { if (req._isAborted) { // already handled return; @@ -232,7 +227,7 @@ StripeResource.prototype = { }; }, - _shouldRetry: function(res, numRetries) { + _shouldRetry(res, numRetries) { // Do not retry if we are out of retries. if (numRetries >= this._stripe.getMaxNetworkRetries()) { return false; @@ -257,14 +252,14 @@ StripeResource.prototype = { return false; }, - _getSleepTimeInMS: function(numRetries) { - var initialNetworkRetryDelay = this._stripe.getInitialNetworkRetryDelay(); - var maxNetworkRetryDelay = this._stripe.getMaxNetworkRetryDelay(); + _getSleepTimeInMS(numRetries) { + const initialNetworkRetryDelay = this._stripe.getInitialNetworkRetryDelay(); + const maxNetworkRetryDelay = this._stripe.getMaxNetworkRetryDelay(); // Apply exponential backoff with initialNetworkRetryDelay on the // number of numRetries so far as inputs. Do not allow the number to exceed // maxNetworkRetryDelay. - var sleepSeconds = Math.min( + let sleepSeconds = Math.min( initialNetworkRetryDelay * Math.pow(numRetries - 1, 2), maxNetworkRetryDelay ); @@ -279,17 +274,18 @@ StripeResource.prototype = { return sleepSeconds * 1000; }, - _defaultHeaders: function(auth, contentLength, apiVersion) { - var userAgentString = - 'Stripe/v1 NodeBindings/' + this._stripe.getConstant('PACKAGE_VERSION'); + _defaultHeaders(auth, contentLength, apiVersion) { + let userAgentString = `Stripe/v1 NodeBindings/${this._stripe.getConstant( + 'PACKAGE_VERSION' + )}`; if (this._stripe._appInfo) { - userAgentString += ' ' + this._stripe.getAppInfoAsString(); + userAgentString += ` ${this._stripe.getAppInfoAsString()}`; } - var headers = { + const headers = { // Use specified auth token or use default from this stripe instance: - Authorization: auth ? 'Bearer ' + auth : this._stripe.getApiField('auth'), + Authorization: auth ? `Bearer ${auth}` : this._stripe.getApiField('auth'), Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': contentLength, @@ -303,19 +299,19 @@ StripeResource.prototype = { return headers; }, - _addTelemetryHeader: function(headers) { + _addTelemetryHeader(headers) { if ( this._stripe.getTelemetryEnabled() && this._stripe._prevRequestMetrics.length > 0 ) { - var metrics = this._stripe._prevRequestMetrics.shift(); + const metrics = this._stripe._prevRequestMetrics.shift(); headers['X-Stripe-Client-Telemetry'] = JSON.stringify({ last_request_metrics: metrics, }); } }, - _recordRequestMetrics: function(requestId, requestDurationMs) { + _recordRequestMetrics(requestId, requestDurationMs) { if (this._stripe.getTelemetryEnabled() && requestId) { if ( this._stripe._prevRequestMetrics.length > @@ -333,23 +329,24 @@ StripeResource.prototype = { } }, - _request: function(method, host, path, data, auth, options, callback) { - var self = this; - var requestData; + _request(method, host, path, data, auth, options, callback) { + const self = this; + let requestData; function makeRequestWithData(error, data) { - var apiVersion; - var headers; - if (error) { return callback(error); } - apiVersion = self._stripe.getApiField('version'); + const apiVersion = self._stripe.getApiField('version'); requestData = data; - headers = self._defaultHeaders(auth, requestData.length, apiVersion); + const headers = self._defaultHeaders( + auth, + requestData.length, + apiVersion + ); - self._stripe.getClientUserAgent(function(cua) { + self._stripe.getClientUserAgent((cua) => { headers['X-Stripe-Client-User-Agent'] = cua; if (options.headers) { @@ -386,20 +383,21 @@ StripeResource.prototype = { } function makeRequest(apiVersion, headers, numRetries) { - var timeout = self._stripe.getApiField('timeout'); - var isInsecureConnection = self._stripe.getApiField('protocol') == 'http'; - var agent = self._stripe.getApiField('agent'); + const timeout = self._stripe.getApiField('timeout'); + const isInsecureConnection = + self._stripe.getApiField('protocol') == 'http'; + let agent = self._stripe.getApiField('agent'); if (agent == null) { agent = isInsecureConnection ? defaultHttpAgent : defaultHttpsAgent; } - var req = (isInsecureConnection ? http : https).request({ + const req = (isInsecureConnection ? http : https).request({ host: host || self._stripe.getApiField('host'), port: self._stripe.getApiField('port'), - path: path, - method: method, - agent: agent, - headers: headers, + path, + method, + agent, + headers, ciphers: 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5', }); @@ -411,15 +409,15 @@ StripeResource.prototype = { } } - var requestEvent = utils.removeEmpty({ + const requestEvent = utils.removeEmpty({ api_version: apiVersion, account: headers['Stripe-Account'], idempotency_key: headers['Idempotency-Key'], - method: method, - path: path, + method, + path, }); - var requestRetries = numRetries || 0; + const requestRetries = numRetries || 0; req._requestEvent = requestEvent; @@ -429,7 +427,7 @@ StripeResource.prototype = { req.setTimeout(timeout, self._timeoutHandler(timeout, req, callback)); - req.on('response', function(res) { + req.on('response', (res) => { if (self._shouldRetry(res, requestRetries)) { return retryRequest(makeRequest, apiVersion, headers, requestRetries); } else { @@ -437,7 +435,7 @@ StripeResource.prototype = { } }); - req.on('error', function(error) { + req.on('error', (error) => { if (self._shouldRetry(null, requestRetries)) { return retryRequest(makeRequest, apiVersion, headers, requestRetries); } else { @@ -445,16 +443,13 @@ StripeResource.prototype = { } }); - req.on('socket', function(socket) { + req.on('socket', (socket) => { if (socket.connecting) { - socket.on( - isInsecureConnection ? 'connect' : 'secureConnect', - function() { - // Send payload; we're safe: - req.write(requestData); - req.end(); - } - ); + socket.on(isInsecureConnection ? 'connect' : 'secureConnect', () => { + // Send payload; we're safe: + req.write(requestData); + req.end(); + }); } else { // we're already connected req.write(requestData); diff --git a/lib/Webhooks.js b/lib/Webhooks.js index 2543761b87..cfe16f3e84 100644 --- a/lib/Webhooks.js +++ b/lib/Webhooks.js @@ -1,15 +1,15 @@ 'use strict'; -var Buffer = require('safe-buffer').Buffer; -var crypto = require('crypto'); +const Buffer = require('safe-buffer').Buffer; +const crypto = require('crypto'); -var utils = require('./utils'); -var Error = require('./Error'); +const utils = require('./utils'); +const Error = require('./Error'); -var Webhook = { +const Webhook = { DEFAULT_TOLERANCE: 300, // 5 minutes - constructEvent: function(payload, header, secret, tolerance) { + constructEvent(payload, header, secret, tolerance) { this.signature.verifyHeader( payload, header, @@ -17,33 +17,33 @@ var Webhook = { tolerance || Webhook.DEFAULT_TOLERANCE ); - var jsonPayload = JSON.parse(payload); + const jsonPayload = JSON.parse(payload); return jsonPayload; }, }; -var signature = { +const signature = { EXPECTED_SCHEME: 'v1', - _computeSignature: function(payload, secret) { + _computeSignature: (payload, secret) => { return crypto .createHmac('sha256', secret) .update(payload, 'utf8') .digest('hex'); }, - verifyHeader: function(payload, header, secret, tolerance) { + verifyHeader(payload, header, secret, tolerance) { payload = Buffer.isBuffer(payload) ? payload.toString('utf8') : payload; header = Buffer.isBuffer(header) ? header.toString('utf8') : header; - var details = parseHeader(header, this.EXPECTED_SCHEME); + const details = parseHeader(header, this.EXPECTED_SCHEME); if (!details || details.timestamp === -1) { throw new Error.StripeSignatureVerificationError({ message: 'Unable to extract timestamp and signatures from header', detail: { - header: header, - payload: payload, + header, + payload, }, }); } @@ -52,18 +52,18 @@ var signature = { throw new Error.StripeSignatureVerificationError({ message: 'No signatures found with expected scheme', detail: { - header: header, - payload: payload, + header, + payload, }, }); } - var expectedSignature = this._computeSignature( - details.timestamp + '.' + payload, + const expectedSignature = this._computeSignature( + `${details.timestamp}.${payload}`, secret ); - var signatureFound = !!details.signatures.filter( + const signatureFound = !!details.signatures.filter( utils.secureCompare.bind(utils, expectedSignature) ).length; @@ -74,20 +74,20 @@ var signature = { ' Are you passing the raw request body you received from Stripe?' + ' https://github.com/stripe/stripe-node#webhook-signing', detail: { - header: header, - payload: payload, + header, + payload, }, }); } - var timestampAge = Math.floor(Date.now() / 1000) - details.timestamp; + const timestampAge = Math.floor(Date.now() / 1000) - details.timestamp; if (tolerance > 0 && timestampAge > tolerance) { throw new Error.StripeSignatureVerificationError({ message: 'Timestamp outside the tolerance zone', detail: { - header: header, - payload: payload, + header, + payload, }, }); } @@ -102,8 +102,8 @@ function parseHeader(header, scheme) { } return header.split(',').reduce( - function(accum, item) { - var kv = item.split('='); + (accum, item) => { + const kv = item.split('='); if (kv[0] === 't') { accum.timestamp = kv[1]; diff --git a/lib/autoPagination.js b/lib/autoPagination.js index f54d5504dd..c3f052169b 100644 --- a/lib/autoPagination.js +++ b/lib/autoPagination.js @@ -1,12 +1,12 @@ 'use strict'; -var makeRequest = require('./makeRequest'); -var utils = require('./utils'); +const makeRequest = require('./makeRequest'); +const utils = require('./utils'); function makeAutoPaginationMethods(self, requestArgs, spec, firstPagePromise) { - var promiseCache = {currentPromise: null}; - var listPromise = firstPagePromise; - var i = 0; + const promiseCache = {currentPromise: null}; + let listPromise = firstPagePromise; + let i = 0; function iterate(listResult) { if ( @@ -22,13 +22,13 @@ function makeAutoPaginationMethods(self, requestArgs, spec, firstPagePromise) { } if (i < listResult.data.length) { - var value = listResult.data[i]; + const value = listResult.data[i]; i += 1; - return {value: value, done: false}; + return {value, done: false}; } else if (listResult.has_more) { // Reset counter, request next page, and recurse. i = 0; - var lastId = getLastId(listResult); + const lastId = getLastId(listResult); listPromise = makeRequest(self, requestArgs, spec, { starting_after: lastId, }); @@ -38,7 +38,7 @@ function makeAutoPaginationMethods(self, requestArgs, spec, firstPagePromise) { } function asyncIteratorNext() { - return memoizedPromise(promiseCache, function(resolve, reject) { + return memoizedPromise(promiseCache, (resolve, reject) => { return listPromise .then(iterate) .then(resolve) @@ -46,20 +46,20 @@ function makeAutoPaginationMethods(self, requestArgs, spec, firstPagePromise) { }); } - var autoPagingEach = makeAutoPagingEach(asyncIteratorNext); - var autoPagingToArray = makeAutoPagingToArray(autoPagingEach); + const autoPagingEach = makeAutoPagingEach(asyncIteratorNext); + const autoPagingToArray = makeAutoPagingToArray(autoPagingEach); - var autoPaginationMethods = { - autoPagingEach: autoPagingEach, - autoPagingToArray: autoPagingToArray, + const autoPaginationMethods = { + autoPagingEach, + autoPagingToArray, // Async iterator functions: next: asyncIteratorNext, - return: function() { + return: () => { // This is required for `break`. return {}; }, - [getAsyncIteratorSymbol()]: function() { + [getAsyncIteratorSymbol()]: () => { return autoPaginationMethods; }, }; @@ -86,11 +86,10 @@ function getDoneCallback(args) { if (args.length < 2) { return undefined; } - var onDone = args[1]; + const onDone = args[1]; if (typeof onDone !== 'function') { throw Error( - 'The second argument to autoPagingEach, if present, must be a callback function; receieved ' + - typeof onDone + `The second argument to autoPagingEach, if present, must be a callback function; receieved ${typeof onDone}` ); } return onDone; @@ -111,11 +110,10 @@ function getItemCallback(args) { if (args.length === 0) { return undefined; } - var onItem = args[0]; + const onItem = args[0]; if (typeof onItem !== 'function') { throw Error( - 'The first argument to autoPagingEach, if present, must be a callback function; receieved ' + - typeof onItem + `The first argument to autoPagingEach, if present, must be a callback function; receieved ${typeof onItem}` ); } @@ -126,8 +124,7 @@ function getItemCallback(args) { if (onItem.length > 2) { throw Error( - 'The `onItem` callback function passed to autoPagingEach must accept at most two arguments; got ' + - onItem + `The \`onItem\` callback function passed to autoPagingEach must accept at most two arguments; got ${onItem}` ); } @@ -136,15 +133,15 @@ function getItemCallback(args) { // 2. `.autoPagingEach(async (item) => { await doSomething(item); return false; });` // 3. `.autoPagingEach((item) => doSomething(item).then(() => false));` return function _onItem(item, next) { - var shouldContinue = onItem(item); + const shouldContinue = onItem(item); next(shouldContinue); }; } function getLastId(listResult) { - var lastIdx = listResult.data.length - 1; - var lastItem = listResult.data[lastIdx]; - var lastId = lastItem && lastItem.id; + const lastIdx = listResult.data.length - 1; + const lastItem = listResult.data[lastIdx]; + const lastId = lastItem && lastItem.id; if (!lastId) { throw Error( 'Unexpected: No `id` found on the last item while auto-paging a list.' @@ -162,7 +159,7 @@ function memoizedPromise(promiseCache, cb) { if (promiseCache.currentPromise) { return promiseCache.currentPromise; } - promiseCache.currentPromise = new Promise(cb).then(function(ret) { + promiseCache.currentPromise = new Promise(cb).then((ret) => { promiseCache.currentPromise = undefined; return ret; }); @@ -171,14 +168,14 @@ function memoizedPromise(promiseCache, cb) { function makeAutoPagingEach(asyncIteratorNext) { return function autoPagingEach(/* onItem?, onDone? */) { - var args = [].slice.call(arguments); - var onItem = getItemCallback(args); - var onDone = getDoneCallback(args); + const args = [].slice.call(arguments); + const onItem = getItemCallback(args); + const onDone = getDoneCallback(args); if (args.length > 2) { throw Error('autoPagingEach takes up to two arguments; received:', args); } - var autoPagePromise = wrapAsyncIteratorWithCallback( + const autoPagePromise = wrapAsyncIteratorWithCallback( asyncIteratorNext, onItem ); @@ -188,7 +185,7 @@ function makeAutoPagingEach(asyncIteratorNext) { function makeAutoPagingToArray(autoPagingEach) { return function autoPagingToArray(opts, onDone) { - var limit = opts && opts.limit; + const limit = opts && opts.limit; if (!limit) { throw Error( 'You must pass a `limit` option to autoPagingToArray, eg; `autoPagingToArray({limit: 1000});`.' @@ -199,15 +196,15 @@ function makeAutoPagingToArray(autoPagingEach) { 'You cannot specify a limit of more than 10,000 items to fetch in `autoPagingToArray`; use `autoPagingEach` to iterate through longer lists.' ); } - var promise = new Promise(function(resolve, reject) { - var items = []; - autoPagingEach(function(item) { + const promise = new Promise((resolve, reject) => { + const items = []; + autoPagingEach((item) => { items.push(item); if (items.length >= limit) { return false; } }) - .then(function() { + .then(() => { resolve(items); }) .catch(reject); @@ -217,20 +214,20 @@ function makeAutoPagingToArray(autoPagingEach) { } function wrapAsyncIteratorWithCallback(asyncIteratorNext, onItem) { - return new Promise(function(resolve, reject) { + return new Promise((resolve, reject) => { function handleIteration(iterResult) { if (iterResult.done) { resolve(); return; } - var item = iterResult.value; - return new Promise(function(next) { + const item = iterResult.value; + return new Promise((next) => { // Bit confusing, perhaps; we pass a `resolve` fn // to the user, so they can decide when and if to continue. // They can return false, or a promise which resolves to false, to break. onItem(item, next); - }).then(function(shouldContinue) { + }).then((shouldContinue) => { if (shouldContinue === false) { return handleIteration({done: true}); } else { diff --git a/lib/makeRequest.js b/lib/makeRequest.js index 1f5ea60664..cb49d4c2ed 100644 --- a/lib/makeRequest.js +++ b/lib/makeRequest.js @@ -1,50 +1,40 @@ 'use strict'; -var utils = require('./utils'); -var OPTIONAL_REGEX = /^optional!/; +const utils = require('./utils'); +const OPTIONAL_REGEX = /^optional!/; function getRequestOpts(self, requestArgs, spec, overrideData) { // Extract spec values with defaults. - var commandPath = + const commandPath = typeof spec.path == 'function' ? spec.path : utils.makeURLInterpolator(spec.path || ''); - var requestMethod = (spec.method || 'GET').toUpperCase(); - var urlParams = spec.urlParams || []; - var encode = - spec.encode || - function(data) { - return data; - }; - var host = spec.host; + const requestMethod = (spec.method || 'GET').toUpperCase(); + const urlParams = spec.urlParams || []; + const encode = spec.encode || ((data) => data); + const host = spec.host; // Don't mutate args externally. - var args = [].slice.call(requestArgs); + const args = [].slice.call(requestArgs); // Generate and validate url params. - var urlData = self.createUrlData(); - for (var i = 0, l = urlParams.length; i < l; ++i) { + const urlData = self.createUrlData(); + for (let i = 0, l = urlParams.length; i < l; ++i) { var path; // Note that we shift the args array after every iteration so this just // grabs the "next" argument for use as a URL parameter. - var arg = args[0]; + const arg = args[0]; - var param = urlParams[i]; + let param = urlParams[i]; - var isOptional = OPTIONAL_REGEX.test(param); + const isOptional = OPTIONAL_REGEX.test(param); param = param.replace(OPTIONAL_REGEX, ''); if (param == 'id' && typeof arg !== 'string') { path = self.createResourcePathWithSymbols(spec.path); throw new Error( - 'Stripe: "id" must be a string, but got: ' + - typeof arg + - ' (on API request to `' + - requestMethod + - ' ' + - path + - '`)' + `Stripe: "id" must be a string, but got: ${typeof arg} (on API request to \`${requestMethod} ${path}\`)` ); } @@ -56,15 +46,9 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { path = self.createResourcePathWithSymbols(spec.path); throw new Error( - 'Stripe: Argument "' + - urlParams[i] + - '" required, but got: ' + - arg + - ' (on API request to `' + - requestMethod + - ' ' + - path + - '`)' + `Stripe: Argument "${ + urlParams[i] + }" required, but got: ${arg} (on API request to \`${requestMethod} ${path}\`)` ); } @@ -72,45 +56,37 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { } // Pull request data and options (headers, auth) from args. - var dataFromArgs = utils.getDataFromArgs(args); - var data = encode(Object.assign({}, dataFromArgs, overrideData)); - var options = utils.getOptionsFromArgs(args); + const dataFromArgs = utils.getDataFromArgs(args); + const data = encode(Object.assign({}, dataFromArgs, overrideData)); + const options = utils.getOptionsFromArgs(args); // Validate that there are no more args. if (args.length) { path = self.createResourcePathWithSymbols(spec.path); throw new Error( - 'Stripe: Unknown arguments (' + - args + - '). Did you mean to pass an options ' + - 'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' + - ' (on API request to ' + - requestMethod + - ' `' + - path + - '`)' + `Stripe: Unknown arguments (${args}). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options. (on API request to ${requestMethod} \`${path}\`)` ); } - var requestPath = self.createFullPath(commandPath, urlData); - var headers = Object.assign(options.headers, spec.headers); + const requestPath = self.createFullPath(commandPath, urlData); + const headers = Object.assign(options.headers, spec.headers); if (spec.validator) { - spec.validator(data, {headers: headers}); + spec.validator(data, {headers}); } return { - requestMethod: requestMethod, - requestPath: requestPath, - data: data, + requestMethod, + requestPath, + data, auth: options.auth, - headers: headers, - host: host, + headers, + host, }; } function makeRequest(self, requestArgs, spec, overrideData) { - return new Promise(function(resolve, reject) { + return new Promise((resolve, reject) => { try { var opts = getRequestOpts(self, requestArgs, spec, overrideData); } catch (err) { diff --git a/lib/resources/Accounts.js b/lib/resources/Accounts.js index 7e8b4b8781..75e25acf1d 100644 --- a/lib/resources/Accounts.js +++ b/lib/resources/Accounts.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ // Since path can either be `account` or `accounts`, support both through stripeMethod path @@ -36,7 +36,7 @@ module.exports = StripeResource.extend({ urlParams: ['id'], }), - retrieve: function(id) { + retrieve(id) { // No longer allow an api key to be passed as the first string to this function due to ambiguity between // old account ids and api keys. To request the account for an api key, send null as the id if (typeof id === 'string') { diff --git a/lib/resources/ApplicationFeeRefunds.js b/lib/resources/ApplicationFeeRefunds.js index e73a018cd4..616d1d60fe 100644 --- a/lib/resources/ApplicationFeeRefunds.js +++ b/lib/resources/ApplicationFeeRefunds.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); /** * ApplicationFeeRefunds is a unique resource in that, upon instantiation, diff --git a/lib/resources/ApplicationFees.js b/lib/resources/ApplicationFees.js index ec41ed3171..d3261bf216 100644 --- a/lib/resources/ApplicationFees.js +++ b/lib/resources/ApplicationFees.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'application_fees', diff --git a/lib/resources/Balance.js b/lib/resources/Balance.js index 7e8adb9116..1a351806dd 100644 --- a/lib/resources/Balance.js +++ b/lib/resources/Balance.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'balance', diff --git a/lib/resources/BitcoinReceivers.js b/lib/resources/BitcoinReceivers.js index 5e430d3632..2642e1e9b3 100644 --- a/lib/resources/BitcoinReceivers.js +++ b/lib/resources/BitcoinReceivers.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'bitcoin/receivers', diff --git a/lib/resources/ChargeRefunds.js b/lib/resources/ChargeRefunds.js index f6de00306d..693a79b0db 100644 --- a/lib/resources/ChargeRefunds.js +++ b/lib/resources/ChargeRefunds.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); /** * ChargeRefunds is a unique resource in that, upon instantiation, diff --git a/lib/resources/Charges.js b/lib/resources/Charges.js index 8f326b7a44..4702bc5bf5 100644 --- a/lib/resources/Charges.js +++ b/lib/resources/Charges.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'charges', @@ -68,11 +68,11 @@ module.exports = StripeResource.extend({ urlParams: ['chargeId', 'refundId'], }), - markAsSafe: function(chargeId) { + markAsSafe(chargeId) { return this.update(chargeId, {fraud_details: {user_report: 'safe'}}); }, - markAsFraudulent: function(chargeId) { + markAsFraudulent(chargeId) { return this.update(chargeId, {fraud_details: {user_report: 'fraudulent'}}); }, }); diff --git a/lib/resources/Checkout/Sessions.js b/lib/resources/Checkout/Sessions.js index 936377c45a..dd47cf7add 100644 --- a/lib/resources/Checkout/Sessions.js +++ b/lib/resources/Checkout/Sessions.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'checkout/sessions', diff --git a/lib/resources/CountrySpecs.js b/lib/resources/CountrySpecs.js index 690b77cd12..b6d5477afe 100644 --- a/lib/resources/CountrySpecs.js +++ b/lib/resources/CountrySpecs.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'country_specs', diff --git a/lib/resources/CreditNotes.js b/lib/resources/CreditNotes.js index ba7d15f45c..5baf5b53f3 100644 --- a/lib/resources/CreditNotes.js +++ b/lib/resources/CreditNotes.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'credit_notes', diff --git a/lib/resources/CustomerCards.js b/lib/resources/CustomerCards.js index 059c403de2..194d85bec0 100644 --- a/lib/resources/CustomerCards.js +++ b/lib/resources/CustomerCards.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); /** * CustomerCard is a unique resource in that, upon instantiation, diff --git a/lib/resources/CustomerSubscriptions.js b/lib/resources/CustomerSubscriptions.js index 3082d84049..6cde760a2f 100644 --- a/lib/resources/CustomerSubscriptions.js +++ b/lib/resources/CustomerSubscriptions.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; /** * CustomerSubscription is a unique resource in that, upon instantiation, diff --git a/lib/resources/Customers.js b/lib/resources/Customers.js index d70f3302b9..7cce50e42c 100644 --- a/lib/resources/Customers.js +++ b/lib/resources/Customers.js @@ -1,8 +1,8 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var utils = require('../utils'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const utils = require('../utils'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'customers', @@ -63,21 +63,21 @@ module.exports = StripeResource.extend({ urlParams: ['customerId', 'subscriptionId'], }), - updateSubscription: function(customerId, subscriptionId) { + updateSubscription(customerId, subscriptionId) { if (typeof subscriptionId == 'string') { - return this._newstyleUpdateSubscription.apply(this, arguments); + return this._newstyleUpdateSubscription(...arguments); } else { - return this._legacyUpdateSubscription.apply(this, arguments); + return this._legacyUpdateSubscription(...arguments); } }, - cancelSubscription: function(customerId, subscriptionId) { + cancelSubscription(customerId, subscriptionId) { // This is a hack, but it lets us maximize our overloading. // Precarious assumption: If it's not an auth key it _could_ be a sub id: if (typeof subscriptionId == 'string' && !utils.isAuthKey(subscriptionId)) { - return this._newstyleCancelSubscription.apply(this, arguments); + return this._newstyleCancelSubscription(...arguments); } else { - return this._legacyCancelSubscription.apply(this, arguments); + return this._legacyCancelSubscription(...arguments); } }, diff --git a/lib/resources/Disputes.js b/lib/resources/Disputes.js index 4a60c73eab..83c5526c25 100644 --- a/lib/resources/Disputes.js +++ b/lib/resources/Disputes.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'disputes', diff --git a/lib/resources/EphemeralKeys.js b/lib/resources/EphemeralKeys.js index 7280a69fda..96cee89368 100644 --- a/lib/resources/EphemeralKeys.js +++ b/lib/resources/EphemeralKeys.js @@ -1,12 +1,12 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ create: stripeMethod({ method: 'POST', - validator: function(data, options) { + validator: (data, options) => { if (!options.headers || !options.headers['Stripe-Version']) { throw new Error( 'stripe_version must be specified to create an ephemeral key' diff --git a/lib/resources/ExchangeRates.js b/lib/resources/ExchangeRates.js index b97e82eae8..7a314cadca 100644 --- a/lib/resources/ExchangeRates.js +++ b/lib/resources/ExchangeRates.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'exchange_rates', diff --git a/lib/resources/FileLinks.js b/lib/resources/FileLinks.js index a07235a5a5..8c264d061a 100644 --- a/lib/resources/FileLinks.js +++ b/lib/resources/FileLinks.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'file_links', diff --git a/lib/resources/Files.js b/lib/resources/Files.js index 4fd258fea4..b400d002fe 100644 --- a/lib/resources/Files.js +++ b/lib/resources/Files.js @@ -1,14 +1,14 @@ 'use strict'; -var Buffer = require('safe-buffer').Buffer; -var utils = require('../utils'); -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; -var multipartDataGenerator = require('../MultipartDataGenerator'); -var Error = require('../Error'); +const Buffer = require('safe-buffer').Buffer; +const utils = require('../utils'); +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; +const multipartDataGenerator = require('../MultipartDataGenerator'); +const Error = require('../Error'); module.exports = StripeResource.extend({ - requestDataProcessor: function(method, data, headers, callback) { + requestDataProcessor(method, data, headers, callback) { data = data || {}; if (method === 'POST') { @@ -18,43 +18,43 @@ module.exports = StripeResource.extend({ } function getProcessorForSourceType(data) { - var isStream = utils.checkForStream(data); + const isStream = utils.checkForStream(data); if (isStream) { return streamProcessor(multipartDataGenerator); } else { - var buffer = multipartDataGenerator(method, data, headers); + const buffer = multipartDataGenerator(method, data, headers); return callback(null, buffer); } } function streamProcessor(fn) { - var bufferArray = []; + const bufferArray = []; data.file.data - .on('data', function(line) { + .on('data', (line) => { bufferArray.push(line); }) - .on('end', function() { - var bufferData = Object.assign({}, data); + .on('end', () => { + const bufferData = Object.assign({}, data); bufferData.file.data = Buffer.concat(bufferArray); - var buffer = fn(method, bufferData, headers); + const buffer = fn(method, bufferData, headers); callback(null, buffer); }) - .on('error', function(err) { - var errorHandler = streamError(callback); + .on('error', (err) => { + const errorHandler = streamError(callback); errorHandler(err); }); } function streamError(callback) { - var StreamProcessingError = Error.extend({ + const StreamProcessingError = Error.extend({ type: 'StreamProcessingError', - populate: function(raw) { + populate(raw) { this.type = this.type; this.message = raw.message; this.detail = raw.detail; }, }); - return function(error) { + return (error) => { callback( new StreamProcessingError({ message: diff --git a/lib/resources/Invoices.js b/lib/resources/Invoices.js index 86e0c9c819..39f1dea8f3 100644 --- a/lib/resources/Invoices.js +++ b/lib/resources/Invoices.js @@ -1,8 +1,8 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; -var utils = require('../utils'); +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; +const utils = require('../utils'); module.exports = StripeResource.extend({ path: 'invoices', @@ -34,9 +34,9 @@ module.exports = StripeResource.extend({ retrieveUpcoming: stripeMethod({ method: 'GET', - path: function(urlData) { - var url = 'upcoming?'; - var hasParam = false; + path(urlData) { + let url = 'upcoming?'; + let hasParam = false; // If you pass just a hash with the relevant parameters, including customer id inside. if ( @@ -53,7 +53,7 @@ module.exports = StripeResource.extend({ urlData.invoiceOptionsOrCustomerId && typeof urlData.invoiceOptionsOrCustomerId === 'string' ) { - url = url + 'customer=' + urlData.invoiceOptionsOrCustomerId; + url = `${url}customer=${urlData.invoiceOptionsOrCustomerId}`; hasParam = true; } @@ -62,12 +62,9 @@ module.exports = StripeResource.extend({ urlData.invoiceOptionsOrSubscriptionId && typeof urlData.invoiceOptionsOrSubscriptionId === 'string' ) { - return ( - url + - (hasParam ? '&' : '') + - 'subscription=' + + return `${url + (hasParam ? '&' : '')}subscription=${ urlData.invoiceOptionsOrSubscriptionId - ); + }`; } else if ( urlData.invoiceOptionsOrSubscriptionId && typeof urlData.invoiceOptionsOrSubscriptionId === 'object' diff --git a/lib/resources/IssuerFraudRecords.js b/lib/resources/IssuerFraudRecords.js index 76c1e1e4d0..97d38fd133 100644 --- a/lib/resources/IssuerFraudRecords.js +++ b/lib/resources/IssuerFraudRecords.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'issuer_fraud_records', diff --git a/lib/resources/Issuing/Authorizations.js b/lib/resources/Issuing/Authorizations.js index a17deec892..85756a6935 100644 --- a/lib/resources/Issuing/Authorizations.js +++ b/lib/resources/Issuing/Authorizations.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'issuing/authorizations', diff --git a/lib/resources/Issuing/Cardholders.js b/lib/resources/Issuing/Cardholders.js index 0e6e5a8bfe..58dd2630b9 100644 --- a/lib/resources/Issuing/Cardholders.js +++ b/lib/resources/Issuing/Cardholders.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'issuing/cardholders', diff --git a/lib/resources/Issuing/Cards.js b/lib/resources/Issuing/Cards.js index 5f5664b88f..f8026ab5fc 100644 --- a/lib/resources/Issuing/Cards.js +++ b/lib/resources/Issuing/Cards.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'issuing/cards', diff --git a/lib/resources/Issuing/Disputes.js b/lib/resources/Issuing/Disputes.js index 096ba8eb43..a26015a3ca 100644 --- a/lib/resources/Issuing/Disputes.js +++ b/lib/resources/Issuing/Disputes.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'issuing/disputes', diff --git a/lib/resources/Issuing/Transactions.js b/lib/resources/Issuing/Transactions.js index f7f004bbd8..789292ff2a 100644 --- a/lib/resources/Issuing/Transactions.js +++ b/lib/resources/Issuing/Transactions.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'issuing/transactions', diff --git a/lib/resources/LoginLinks.js b/lib/resources/LoginLinks.js index ac82bc71c9..b76439e000 100644 --- a/lib/resources/LoginLinks.js +++ b/lib/resources/LoginLinks.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'accounts/{accountId}/login_links', diff --git a/lib/resources/OAuth.js b/lib/resources/OAuth.js index 7258b8c371..70ce4a2358 100644 --- a/lib/resources/OAuth.js +++ b/lib/resources/OAuth.js @@ -1,23 +1,23 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; -var utils = require('../utils'); +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; +const utils = require('../utils'); -var oAuthHost = 'connect.stripe.com'; +const oAuthHost = 'connect.stripe.com'; module.exports = StripeResource.extend({ basePath: '/', - authorizeUrl: function(params, options) { + authorizeUrl(params, options) { params = params || {}; options = options || {}; - var path = 'oauth/authorize'; + let path = 'oauth/authorize'; // For Express accounts, the path changes if (options.express) { - path = 'express/' + path; + path = `express/${path}`; } if (!params.response_type) { @@ -32,14 +32,7 @@ module.exports = StripeResource.extend({ params.scope = 'read_write'; } - return ( - 'https://' + - oAuthHost + - '/' + - path + - '?' + - utils.stringifyRequestData(params) - ); + return `https://${oAuthHost}/${path}?${utils.stringifyRequestData(params)}`; }, token: stripeMethod({ @@ -48,7 +41,7 @@ module.exports = StripeResource.extend({ host: oAuthHost, }), - deauthorize: function(spec) { + deauthorize(spec) { if (!spec.client_id) { spec.client_id = this._stripe.getClientId(); } diff --git a/lib/resources/OrderReturns.js b/lib/resources/OrderReturns.js index b0e1be62e3..058c702c87 100644 --- a/lib/resources/OrderReturns.js +++ b/lib/resources/OrderReturns.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'order_returns', diff --git a/lib/resources/Orders.js b/lib/resources/Orders.js index c59ea450aa..371c3ec486 100644 --- a/lib/resources/Orders.js +++ b/lib/resources/Orders.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'orders', diff --git a/lib/resources/PaymentIntents.js b/lib/resources/PaymentIntents.js index 86128201da..7093b21ee7 100644 --- a/lib/resources/PaymentIntents.js +++ b/lib/resources/PaymentIntents.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'payment_intents', diff --git a/lib/resources/PaymentMethods.js b/lib/resources/PaymentMethods.js index 55c1495e32..cc6201749e 100644 --- a/lib/resources/PaymentMethods.js +++ b/lib/resources/PaymentMethods.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'payment_methods', diff --git a/lib/resources/Payouts.js b/lib/resources/Payouts.js index 9c41679c12..8cd32d9c9c 100644 --- a/lib/resources/Payouts.js +++ b/lib/resources/Payouts.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'payouts', diff --git a/lib/resources/Persons.js b/lib/resources/Persons.js index 6429dd0d26..8de5bacd0b 100644 --- a/lib/resources/Persons.js +++ b/lib/resources/Persons.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); /** * Persons is a unique resource in that, upon instantiation, diff --git a/lib/resources/Products.js b/lib/resources/Products.js index 3777c567ca..02da55d5da 100644 --- a/lib/resources/Products.js +++ b/lib/resources/Products.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'products', diff --git a/lib/resources/Radar/ValueListItems.js b/lib/resources/Radar/ValueListItems.js index d6776fd764..055ea00004 100644 --- a/lib/resources/Radar/ValueListItems.js +++ b/lib/resources/Radar/ValueListItems.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'radar/value_list_items', diff --git a/lib/resources/Radar/ValueLists.js b/lib/resources/Radar/ValueLists.js index fdec19aba0..63d4134239 100644 --- a/lib/resources/Radar/ValueLists.js +++ b/lib/resources/Radar/ValueLists.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'radar/value_lists', diff --git a/lib/resources/RecipientCards.js b/lib/resources/RecipientCards.js index 2986003798..0dc675bdcc 100644 --- a/lib/resources/RecipientCards.js +++ b/lib/resources/RecipientCards.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); /** * RecipientCard is similar to CustomerCard in that, upon instantiation, it diff --git a/lib/resources/Recipients.js b/lib/resources/Recipients.js index b4a97cf19c..e9adaec076 100644 --- a/lib/resources/Recipients.js +++ b/lib/resources/Recipients.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'recipients', diff --git a/lib/resources/Refunds.js b/lib/resources/Refunds.js index a1351a27d2..76373c92c0 100644 --- a/lib/resources/Refunds.js +++ b/lib/resources/Refunds.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'refunds', diff --git a/lib/resources/Reporting/ReportRuns.js b/lib/resources/Reporting/ReportRuns.js index 46d8a989d6..9cf3cbc6df 100644 --- a/lib/resources/Reporting/ReportRuns.js +++ b/lib/resources/Reporting/ReportRuns.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'reporting/report_runs', diff --git a/lib/resources/Reporting/ReportTypes.js b/lib/resources/Reporting/ReportTypes.js index 576c2aad4b..ff3dee3167 100644 --- a/lib/resources/Reporting/ReportTypes.js +++ b/lib/resources/Reporting/ReportTypes.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'reporting/report_types', diff --git a/lib/resources/Reviews.js b/lib/resources/Reviews.js index 6d3fb2c4f1..40a150512d 100644 --- a/lib/resources/Reviews.js +++ b/lib/resources/Reviews.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'reviews', diff --git a/lib/resources/SKUs.js b/lib/resources/SKUs.js index 36f7445dfd..9fd01cf439 100644 --- a/lib/resources/SKUs.js +++ b/lib/resources/SKUs.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'skus', diff --git a/lib/resources/Sigma/ScheduledQueryRuns.js b/lib/resources/Sigma/ScheduledQueryRuns.js index bc80b40040..0714497062 100644 --- a/lib/resources/Sigma/ScheduledQueryRuns.js +++ b/lib/resources/Sigma/ScheduledQueryRuns.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'sigma/scheduled_query_runs', diff --git a/lib/resources/Sources.js b/lib/resources/Sources.js index d0e103509e..78e7a87675 100644 --- a/lib/resources/Sources.js +++ b/lib/resources/Sources.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'sources', diff --git a/lib/resources/SubscriptionItems.js b/lib/resources/SubscriptionItems.js index fad2894f7c..4c159e0ced 100644 --- a/lib/resources/SubscriptionItems.js +++ b/lib/resources/SubscriptionItems.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: 'subscription_items', diff --git a/lib/resources/SubscriptionScheduleRevisions.js b/lib/resources/SubscriptionScheduleRevisions.js index 591f64fc62..8998b7007a 100644 --- a/lib/resources/SubscriptionScheduleRevisions.js +++ b/lib/resources/SubscriptionScheduleRevisions.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); /** * SubscriptionScheduleRevisions is a unique resource in that, upon instantiation, diff --git a/lib/resources/SubscriptionSchedules.js b/lib/resources/SubscriptionSchedules.js index 6045fd093f..f135a0ef2a 100644 --- a/lib/resources/SubscriptionSchedules.js +++ b/lib/resources/SubscriptionSchedules.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'subscription_schedules', diff --git a/lib/resources/Subscriptions.js b/lib/resources/Subscriptions.js index 4deb1b9262..5bb1d5f784 100644 --- a/lib/resources/Subscriptions.js +++ b/lib/resources/Subscriptions.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'subscriptions', diff --git a/lib/resources/TaxIds.js b/lib/resources/TaxIds.js index bc8d860452..301782eda2 100644 --- a/lib/resources/TaxIds.js +++ b/lib/resources/TaxIds.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); /** * TaxIds is a unique resource in that, upon instantiation, diff --git a/lib/resources/Terminal/ConnectionTokens.js b/lib/resources/Terminal/ConnectionTokens.js index 3b52fc93d1..76195dda70 100644 --- a/lib/resources/Terminal/ConnectionTokens.js +++ b/lib/resources/Terminal/ConnectionTokens.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'terminal/connection_tokens', diff --git a/lib/resources/Terminal/Locations.js b/lib/resources/Terminal/Locations.js index 7066d48e2b..0748bbd0cb 100644 --- a/lib/resources/Terminal/Locations.js +++ b/lib/resources/Terminal/Locations.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'terminal/locations', diff --git a/lib/resources/Terminal/Readers.js b/lib/resources/Terminal/Readers.js index 4263dbf21c..b5dddc3929 100644 --- a/lib/resources/Terminal/Readers.js +++ b/lib/resources/Terminal/Readers.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../../StripeResource'); +const StripeResource = require('../../StripeResource'); module.exports = StripeResource.extend({ path: 'terminal/readers', diff --git a/lib/resources/ThreeDSecure.js b/lib/resources/ThreeDSecure.js index 5756019b49..96248d1ea9 100644 --- a/lib/resources/ThreeDSecure.js +++ b/lib/resources/ThreeDSecure.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); module.exports = StripeResource.extend({ path: '3d_secure', diff --git a/lib/resources/Topups.js b/lib/resources/Topups.js index 41d755b48b..ef57d1ff3f 100644 --- a/lib/resources/Topups.js +++ b/lib/resources/Topups.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'topups', diff --git a/lib/resources/TransferReversals.js b/lib/resources/TransferReversals.js index 6794fde77f..4eb4603796 100644 --- a/lib/resources/TransferReversals.js +++ b/lib/resources/TransferReversals.js @@ -1,6 +1,6 @@ 'use strict'; -var StripeResource = require('../StripeResource'); +const StripeResource = require('../StripeResource'); /** * TransferReversals is a unique resource in that, upon instantiation, diff --git a/lib/resources/Transfers.js b/lib/resources/Transfers.js index 04f4dc2386..2a0cb92ddf 100644 --- a/lib/resources/Transfers.js +++ b/lib/resources/Transfers.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'transfers', diff --git a/lib/resources/UsageRecordSummaries.js b/lib/resources/UsageRecordSummaries.js index f0f438f33e..8a59a43ef6 100644 --- a/lib/resources/UsageRecordSummaries.js +++ b/lib/resources/UsageRecordSummaries.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'subscription_items', diff --git a/lib/resources/UsageRecords.js b/lib/resources/UsageRecords.js index 697539aa14..26829eccd3 100644 --- a/lib/resources/UsageRecords.js +++ b/lib/resources/UsageRecords.js @@ -1,7 +1,7 @@ 'use strict'; -var StripeResource = require('../StripeResource'); -var stripeMethod = StripeResource.method; +const StripeResource = require('../StripeResource'); +const stripeMethod = StripeResource.method; module.exports = StripeResource.extend({ path: 'subscription_items', diff --git a/lib/stripe.js b/lib/stripe.js index 46ed677b63..2ce637fa17 100644 --- a/lib/stripe.js +++ b/lib/stripe.js @@ -24,14 +24,14 @@ Stripe.USER_AGENT_SERIALIZED = null; Stripe.MAX_NETWORK_RETRY_DELAY_SEC = 2; Stripe.INITIAL_NETWORK_RETRY_DELAY_SEC = 0.5; -var APP_INFO_PROPERTIES = ['name', 'version', 'url', 'partner_id']; +const APP_INFO_PROPERTIES = ['name', 'version', 'url', 'partner_id']; -var EventEmitter = require('events').EventEmitter; -var utils = require('./utils'); +const EventEmitter = require('events').EventEmitter; +const utils = require('./utils'); -var resourceNamespace = require('./ResourceNamespace'); +const resourceNamespace = require('./ResourceNamespace'); -var resources = { +const resources = { // Support Accounts for consistency, Account for backwards compat Account: require('./resources/Accounts'), Accounts: require('./resources/Accounts'), @@ -168,7 +168,7 @@ Stripe.errors = require('./Error'); Stripe.webhooks = require('./Webhooks'); Stripe.prototype = { - setHost: function(host, port, protocol) { + setHost(host, port, protocol) { this._setApiField('host', host); if (port) { this.setPort(port); @@ -178,34 +178,34 @@ Stripe.prototype = { } }, - setProtocol: function(protocol) { + setProtocol(protocol) { this._setApiField('protocol', protocol.toLowerCase()); }, - setPort: function(port) { + setPort(port) { this._setApiField('port', port); }, - setApiVersion: function(version) { + setApiVersion(version) { if (version) { this._setApiField('version', version); } }, - setApiKey: function(key) { + setApiKey(key) { if (key) { - this._setApiField('auth', 'Bearer ' + key); + this._setApiField('auth', `Bearer ${key}`); } }, - setTimeout: function(timeout) { + setTimeout(timeout) { this._setApiField( 'timeout', timeout == null ? Stripe.DEFAULT_TIMEOUT : timeout ); }, - setAppInfo: function(info) { + setAppInfo(info) { if (info && typeof info !== 'object') { throw new Error('AppInfo must be an object.'); } @@ -216,7 +216,7 @@ Stripe.prototype = { info = info || {}; - var appInfo = APP_INFO_PROPERTIES.reduce(function(accum, prop) { + const appInfo = APP_INFO_PROPERTIES.reduce((accum, prop) => { if (typeof info[prop] == 'string') { accum = accum || {}; @@ -232,35 +232,35 @@ Stripe.prototype = { this._appInfo = appInfo; }, - setHttpAgent: function(agent) { + setHttpAgent(agent) { this._setApiField('agent', agent); }, - _setApiField: function(key, value) { + _setApiField(key, value) { this._api[key] = value; }, - getApiField: function(key) { + getApiField(key) { return this._api[key]; }, - setClientId: function(clientId) { + setClientId(clientId) { this._clientId = clientId; }, - getClientId: function() { + getClientId() { return this._clientId; }, - getConstant: function(c) { + getConstant: (c) => { return Stripe[c]; }, - getMaxNetworkRetries: function() { + getMaxNetworkRetries() { return this.getApiField('maxNetworkRetries'); }, - setMaxNetworkRetries: function(maxNetworkRetries) { + setMaxNetworkRetries(maxNetworkRetries) { if ( (maxNetworkRetries && typeof maxNetworkRetries !== 'number') || arguments.length < 1 @@ -271,21 +271,21 @@ Stripe.prototype = { this._setApiField('maxNetworkRetries', maxNetworkRetries); }, - getMaxNetworkRetryDelay: function() { + getMaxNetworkRetryDelay() { return this.getConstant('MAX_NETWORK_RETRY_DELAY_SEC'); }, - getInitialNetworkRetryDelay: function() { + getInitialNetworkRetryDelay() { return this.getConstant('INITIAL_NETWORK_RETRY_DELAY_SEC'); }, // Gets a JSON version of a User-Agent and uses a cached version for a slight // speed advantage. - getClientUserAgent: function(cb) { + getClientUserAgent(cb) { if (Stripe.USER_AGENT_SERIALIZED) { return cb(Stripe.USER_AGENT_SERIALIZED); } - this.getClientUserAgentSeeded(Stripe.USER_AGENT, function(cua) { + this.getClientUserAgentSeeded(Stripe.USER_AGENT, (cua) => { Stripe.USER_AGENT_SERIALIZED = cua; cb(Stripe.USER_AGENT_SERIALIZED); }); @@ -293,12 +293,12 @@ Stripe.prototype = { // Gets a JSON version of a User-Agent by encoding a seeded object and // fetching a uname from the system. - getClientUserAgentSeeded: function(seed, cb) { - var self = this; + getClientUserAgentSeeded(seed, cb) { + const self = this; - utils.safeExec('uname -a', function(err, uname) { - var userAgent = {}; - for (var field in seed) { + utils.safeExec('uname -a', (err, uname) => { + const userAgent = {}; + for (const field in seed) { userAgent[field] = encodeURIComponent(seed[field]); } @@ -313,34 +313,34 @@ Stripe.prototype = { }); }, - getAppInfoAsString: function() { + getAppInfoAsString() { if (!this._appInfo) { return ''; } - var formatted = this._appInfo.name; + let formatted = this._appInfo.name; if (this._appInfo.version) { - formatted += '/' + this._appInfo.version; + formatted += `/${this._appInfo.version}`; } if (this._appInfo.url) { - formatted += ' (' + this._appInfo.url + ')'; + formatted += ` (${this._appInfo.url})`; } return formatted; }, - setTelemetryEnabled: function(enableTelemetry) { + setTelemetryEnabled(enableTelemetry) { this._enableTelemetry = enableTelemetry; }, - getTelemetryEnabled: function() { + getTelemetryEnabled() { return this._enableTelemetry; }, - _prepResources: function() { - for (var name in resources) { + _prepResources() { + for (const name in resources) { this[utils.pascalToCamelCase(name)] = new resources[name](this); } }, diff --git a/lib/utils.js b/lib/utils.js index 9cbfe9b918..ae8ddfd778 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,46 +1,39 @@ 'use strict'; -var Buffer = require('safe-buffer').Buffer; -var EventEmitter = require('events').EventEmitter; -var exec = require('child_process').exec; -var qs = require('qs'); -var crypto = require('crypto'); +const Buffer = require('safe-buffer').Buffer; +const EventEmitter = require('events').EventEmitter; +const exec = require('child_process').exec; +const qs = require('qs'); +const crypto = require('crypto'); -var hasOwn = {}.hasOwnProperty; -var isPlainObject = require('lodash.isplainobject'); +const hasOwn = {}.hasOwnProperty; +const isPlainObject = require('lodash.isplainobject'); -var OPTIONS_KEYS = [ +const OPTIONS_KEYS = [ 'api_key', 'idempotency_key', 'stripe_account', 'stripe_version', ]; -var utils = (module.exports = { - isAuthKey: function(key) { +const utils = (module.exports = { + isAuthKey: (key) => { return typeof key == 'string' && /^(?:[a-z]{2}_)?[A-z0-9]{32}$/.test(key); }, - isOptionsHash: function(o) { - return ( - isPlainObject(o) && - OPTIONS_KEYS.some(function(key) { - return hasOwn.call(o, key); - }) - ); + isOptionsHash: (o) => { + return isPlainObject(o) && OPTIONS_KEYS.some((key) => hasOwn.call(o, key)); }, /** * Stringifies an Object, accommodating nested objects * (forming the conventional key 'parent[child]=value') */ - stringifyRequestData: function(data) { + stringifyRequestData: (data) => { return ( qs .stringify(data, { - serializeDate: function(d) { - return Math.floor(d.getTime() / 1000); - }, + serializeDate: (d) => Math.floor(d.getTime() / 1000), }) // Don't use strict form encoding by changing the square bracket control // characters back to their literals. This is fine by the server, and @@ -56,21 +49,19 @@ var utils = (module.exports = { * var fn = makeURLInterpolator('some/url/{param1}/{param2}'); * fn({ param1: 123, param2: 456 }); // => 'some/url/123/456' */ - makeURLInterpolator: (function() { - var rc = { + makeURLInterpolator: (() => { + const rc = { '\n': '\\n', '"': '\\"', '\u2028': '\\u2028', '\u2029': '\\u2029', }; - return function makeURLInterpolator(str) { - var cleanString = str.replace(/["\n\r\u2028\u2029]/g, function($0) { - return rc[$0]; - }); - return function(outputs) { - return cleanString.replace(/\{([\s\S]+?)\}/g, function($0, $1) { - return encodeURIComponent(outputs[$1] || ''); - }); + return (str) => { + const cleanString = str.replace(/["\n\r\u2028\u2029]/g, ($0) => rc[$0]); + return (outputs) => { + return cleanString.replace(/\{([\s\S]+?)\}/g, ($0, $1) => + encodeURIComponent(outputs[$1] || '') + ); }; }; })(), @@ -78,7 +69,7 @@ var utils = (module.exports = { /** * Return the data argument from a list of arguments */ - getDataFromArgs: function(args) { + getDataFromArgs: (args) => { if (args.length < 1 || !isPlainObject(args[0])) { return {}; } @@ -87,11 +78,11 @@ var utils = (module.exports = { return args.shift(); } - var argKeys = Object.keys(args[0]); + const argKeys = Object.keys(args[0]); - var optionKeysInArgs = argKeys.filter(function(key) { - return OPTIONS_KEYS.indexOf(key) > -1; - }); + const optionKeysInArgs = argKeys.filter((key) => + OPTIONS_KEYS.includes(key) + ); // In some cases options may be the provided as the first argument. // Here we're detecting a case where there are two distinct arguments @@ -102,10 +93,9 @@ var utils = (module.exports = { optionKeysInArgs.length !== argKeys.length ) { emitWarning( - 'Options found in arguments (' + - optionKeysInArgs.join(', ') + - '). Did you mean to pass an options ' + - 'object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' + `Options found in arguments (${optionKeysInArgs.join( + ', ' + )}). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.` ); } @@ -115,25 +105,25 @@ var utils = (module.exports = { /** * Return the options hash from a list of arguments */ - getOptionsFromArgs: function(args) { - var opts = { + getOptionsFromArgs: (args) => { + const opts = { auth: null, headers: {}, }; if (args.length > 0) { - var arg = args[args.length - 1]; + const arg = args[args.length - 1]; if (utils.isAuthKey(arg)) { opts.auth = args.pop(); } else if (utils.isOptionsHash(arg)) { - var params = args.pop(); + const params = args.pop(); - var extraKeys = Object.keys(params).filter(function(key) { - return OPTIONS_KEYS.indexOf(key) == -1; - }); + const extraKeys = Object.keys(params).filter( + (key) => !OPTIONS_KEYS.includes(key) + ); if (extraKeys.length) { emitWarning( - 'Invalid options found (' + extraKeys.join(', ') + '); ignoring.' + `Invalid options found (${extraKeys.join(', ')}); ignoring.` ); } @@ -157,12 +147,12 @@ var utils = (module.exports = { /** * Provide simple "Class" extension mechanism */ - protoExtend: function(sub) { - var Super = this; - var Constructor = hasOwn.call(sub, 'constructor') + protoExtend(sub) { + const Super = this; + const Constructor = hasOwn.call(sub, 'constructor') ? sub.constructor - : function() { - Super.apply(this, arguments); + : function(...args) { + Super.apply(this, args); }; // This initialization logic is somewhat sensitive to be compatible with @@ -180,7 +170,7 @@ var utils = (module.exports = { /** * Secure compare, from https://github.com/freewil/scmp */ - secureCompare: function(a, b) { + secureCompare: (a, b) => { a = Buffer.from(a); b = Buffer.from(b); @@ -196,10 +186,10 @@ var utils = (module.exports = { return crypto.timingSafeEqual(a, b); } - var len = a.length; - var result = 0; + const len = a.length; + let result = 0; - for (var i = 0; i < len; ++i) { + for (let i = 0; i < len; ++i) { result |= a[i] ^ b[i]; } return result === 0; @@ -208,12 +198,12 @@ var utils = (module.exports = { /** * Remove empty values from an object */ - removeEmpty: function(obj) { + removeEmpty: (obj) => { if (typeof obj !== 'object') { throw new Error('Argument must be an object'); } - Object.keys(obj).forEach(function(key) { + Object.keys(obj).forEach((key) => { if (obj[key] === null || obj[key] === undefined) { delete obj[key]; } @@ -226,24 +216,24 @@ var utils = (module.exports = { * Determine if file data is a derivative of EventEmitter class. * https://nodejs.org/api/events.html#events_events */ - checkForStream: function(obj) { + checkForStream: (obj) => { if (obj.file && obj.file.data) { return obj.file.data instanceof EventEmitter; } return false; }, - callbackifyPromiseWithTimeout: function(promise, callback) { + callbackifyPromiseWithTimeout: (promise, callback) => { if (callback) { // Ensure callback is called outside of promise stack. return promise.then( - function(res) { - setTimeout(function() { + (res) => { + setTimeout(() => { callback(null, res); }, 0); }, - function(err) { - setTimeout(function() { + (err) => { + setTimeout(() => { callback(err, null); }, 0); } @@ -256,7 +246,7 @@ var utils = (module.exports = { /** * Allow for special capitalization cases (such as OAuth) */ - pascalToCamelCase: function(name) { + pascalToCamelCase: (name) => { if (name === 'OAuth') { return 'oauth'; } else { @@ -264,7 +254,7 @@ var utils = (module.exports = { } }, - emitWarning: emitWarning, + emitWarning, /** * Node's built in `exec` function sometimes throws outright, @@ -273,7 +263,7 @@ var utils = (module.exports = { * * This unifies that interface. */ - safeExec: function safeExec(cmd, cb) { + safeExec: (cmd, cb) => { try { utils._exec(cmd, cb); } catch (e) { @@ -284,20 +274,20 @@ var utils = (module.exports = { // For mocking in tests. _exec: exec, - isObject: function isObject(obj) { - var type = typeof obj; + isObject: (obj) => { + const type = typeof obj; return (type === 'function' || type === 'object') && !!obj; }, // For use in multipart requests - flattenAndStringify: function flattenAndStringify(data) { - var result = {}; + flattenAndStringify: (data) => { + const result = {}; - function step(obj, prevKey) { - Object.keys(obj).forEach(function(key) { - var value = obj[key]; + const step = (obj, prevKey) => { + Object.keys(obj).forEach((key) => { + const value = obj[key]; - var newKey = prevKey ? `${prevKey}[${key}]` : key; + const newKey = prevKey ? `${prevKey}[${key}]` : key; if (utils.isObject(value)) { if (!Buffer.isBuffer(value) && !value.hasOwnProperty('data')) { @@ -312,7 +302,7 @@ var utils = (module.exports = { result[newKey] = String(value); } }); - } + }; step(data); @@ -323,7 +313,7 @@ var utils = (module.exports = { function emitWarning(warning) { if (typeof process.emitWarning !== 'function') { return console.warn( - 'Stripe: ' + warning + `Stripe: ${warning}` ); /* eslint-disable-line no-console */ } diff --git a/package.json b/package.json index b13849700c..b9dbceb2c1 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "bugs:": "https://github.com/stripe/stripe-node/issues", "engines": { - "node": "6 || >=8" + "node": "6 || >=8.1" }, "main": "lib/stripe.js", "devDependencies": { @@ -50,10 +50,11 @@ "scripts": { "clean": "rm -rf ./.nyc_output ./node_modules/.cache ./coverage", "mocha": "nyc mocha", + "mocha-only": "mocha", "test": "npm run lint && npm run mocha", "lint": "eslint --ext .js,.jsx .", "fix": "yarn lint --fix", "report": "nyc -r text -r lcov report", "coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" } -} +} \ No newline at end of file diff --git a/test/Error.spec.js b/test/Error.spec.js index 54c3bc5703..91b7ad9bc6 100644 --- a/test/Error.spec.js +++ b/test/Error.spec.js @@ -2,19 +2,19 @@ require('../testUtils'); -var Error = require('../lib/Error'); -var expect = require('chai').expect; +const Error = require('../lib/Error'); +const expect = require('chai').expect; -describe('Error', function() { - it('Populates with type and message params', function() { - var e = new Error('FooError', 'Foo happened'); +describe('Error', () => { + it('Populates with type and message params', () => { + const e = new Error('FooError', 'Foo happened'); expect(e).to.have.property('type', 'FooError'); expect(e).to.have.property('message', 'Foo happened'); expect(e).to.have.property('stack'); }); - describe('StripeError', function() { - it('Generates specific instance depending on error-type', function() { + describe('StripeError', () => { + it('Generates specific instance depending on error-type', () => { expect(Error.StripeError.generate({type: 'card_error'})).to.be.instanceOf( Error.StripeCardError ); @@ -29,25 +29,25 @@ describe('Error', function() { ).to.be.instanceOf(Error.StripeIdempotencyError); }); - it('Pulls in headers', function() { - var headers = {'Request-Id': '123'}; - var e = Error.StripeError.generate({ + it('Pulls in headers', () => { + const headers = {'Request-Id': '123'}; + const e = Error.StripeError.generate({ type: 'card_error', - headers: headers, + headers, }); expect(e).to.have.property('headers', headers); }); - it('Pulls in request IDs', function() { - var e = Error.StripeError.generate({ + it('Pulls in request IDs', () => { + const e = Error.StripeError.generate({ type: 'card_error', requestId: 'foo', }); expect(e).to.have.property('requestId', 'foo'); }); - it('Pulls in HTTP status code', function() { - var e = Error.StripeError.generate({ + it('Pulls in HTTP status code', () => { + const e = Error.StripeError.generate({ type: 'card_error', statusCode: 400, }); diff --git a/test/StripeResource.spec.js b/test/StripeResource.spec.js index 9b30bbb779..9290bcc304 100644 --- a/test/StripeResource.spec.js +++ b/test/StripeResource.spec.js @@ -1,56 +1,56 @@ 'use strict'; -var utils = require('../testUtils'); -var uuid = require('uuid/v4'); +const utils = require('../testUtils'); +const uuid = require('uuid/v4'); -var nock = require('nock'); +const nock = require('nock'); -var stripe = require('../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('StripeResource', function() { - describe('createResourcePathWithSymbols', function() { - it('Generates a path', function() { +describe('StripeResource', () => { + describe('createResourcePathWithSymbols', () => { + it('Generates a path', () => { stripe.invoices.create({}); - var path = stripe.invoices.createResourcePathWithSymbols('{id}'); + const path = stripe.invoices.createResourcePathWithSymbols('{id}'); expect(path).to.equal('/invoices/{id}'); }); }); - describe('_defaultHeaders', function() { - it('sets the Authorization header with Bearer auth using the global API key', function() { - var headers = stripe.invoices._defaultHeaders(null, 0, null); + describe('_defaultHeaders', () => { + it('sets the Authorization header with Bearer auth using the global API key', () => { + const headers = stripe.invoices._defaultHeaders(null, 0, null); expect(headers.Authorization).to.equal('Bearer fakeAuthToken'); }); - it('sets the Authorization header with Bearer auth using the specified API key', function() { - var headers = stripe.invoices._defaultHeaders( + it('sets the Authorization header with Bearer auth using the specified API key', () => { + const headers = stripe.invoices._defaultHeaders( 'anotherFakeAuthToken', 0, null ); expect(headers.Authorization).to.equal('Bearer anotherFakeAuthToken'); }); - it('sets the Stripe-Version header if an API version is provided', function() { - var headers = stripe.invoices._defaultHeaders(null, 0, '1970-01-01'); + it('sets the Stripe-Version header if an API version is provided', () => { + const headers = stripe.invoices._defaultHeaders(null, 0, '1970-01-01'); expect(headers['Stripe-Version']).to.equal('1970-01-01'); }); - it('does not the set the Stripe-Version header if no API version is provided', function() { - var headers = stripe.invoices._defaultHeaders(null, 0, null); + it('does not the set the Stripe-Version header if no API version is provided', () => { + const headers = stripe.invoices._defaultHeaders(null, 0, null); expect(headers).to.not.include.keys('Stripe-Version'); }); }); - describe('Parameter encoding', function() { + describe('Parameter encoding', () => { // Use a real instance of stripe as we're mocking the http.request responses. - var realStripe = require('../lib/stripe')(utils.getUserStripeKey()); + const realStripe = require('../lib/stripe')(utils.getUserStripeKey()); - after(function() { + after(() => { nock.cleanAll(); }); - describe('_request', function() { - it('encodes the query string in GET requests', function(done) { - var options = { + describe('_request', () => { + it('encodes the query string in GET requests', (done) => { + const options = { host: stripe.getConstant('DEFAULT_HOST'), path: '/v1/invoices/upcoming', data: { @@ -61,22 +61,23 @@ describe('StripeResource', function() { }, }; - const scope = nock('https://' + options.host) + const scope = nock(`https://${options.host}`) .get(options.path) .query(Object.assign({customer: 'cus_123'}, options.data)) .reply(200, '{}'); - realStripe.invoices.retrieveUpcoming('cus_123', options.data, function( - err, - response - ) { - done(); - scope.done(); - }); + realStripe.invoices.retrieveUpcoming( + 'cus_123', + options.data, + (err, response) => { + done(); + scope.done(); + } + ); }); - it('encodes the body in POST requests', function(done) { - var options = { + it('encodes the body in POST requests', (done) => { + const options = { host: stripe.getConstant('DEFAULT_HOST'), path: '/v1/subscriptions/sub_123', data: { @@ -87,31 +88,30 @@ describe('StripeResource', function() { 'customer=cus_123&items[0][plan]=foo&items[0][quantity]=2&items[1][id]=si_123&items[1][deleted]=true', }; - const scope = nock('https://' + options.host) + const scope = nock(`https://${options.host}`) .post(options.path, options.body) .reply(200, '{}'); - realStripe.subscriptions.update('sub_123', options.data, function( - err, - response - ) { - done(); - scope.done(); - }); + realStripe.subscriptions.update( + 'sub_123', + options.data, + (err, response) => { + done(); + scope.done(); + } + ); }); }); }); - describe('Retry Network Requests', function() { + describe('Retry Network Requests', () => { // Use a real instance of stripe as we're mocking the http.request responses. - var realStripe = require('../lib/stripe')(utils.getUserStripeKey()); + const realStripe = require('../lib/stripe')(utils.getUserStripeKey()); // Override the sleep timer to speed up tests - realStripe.charges._getSleepTimeInMS = function() { - return 0; - }; + realStripe.charges._getSleepTimeInMS = () => 0; - var options = { + const options = { host: stripe.getConstant('DEFAULT_HOST'), path: '/v1/charges', data: { @@ -123,30 +123,30 @@ describe('StripeResource', function() { params: 'amount=1000¤cy=usd&source=tok_visa&description=test', }; - afterEach(function() { + afterEach(() => { realStripe.setMaxNetworkRetries(0); stripe.setMaxNetworkRetries(0); }); - after(function() { + after(() => { nock.cleanAll(); }); - describe('_request', function() { - it('throws an error on connection failure', function(done) { + describe('_request', () => { + it('throws an error on connection failure', (done) => { // Mock the connection error. - nock('https://' + options.host) + nock(`https://${options.host}`) .post(options.path, options.params) .replyWithError('bad stuff'); - realStripe.charges.create(options.data, function(err) { + realStripe.charges.create(options.data, (err) => { expect(err.detail.message).to.deep.equal('bad stuff'); done(); }); }); - it('should retry the request if max retries are set', function(done) { - nock('https://' + options.host) + it('should retry the request if max retries are set', (done) => { + nock(`https://${options.host}`) .post(options.path, options.params) .replyWithError('bad stuff') .post(options.path, options.params) @@ -154,8 +154,8 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.create(options.data, function(err) { - var errorMessage = realStripe.invoices._generateConnectionErrorMessage( + realStripe.charges.create(options.data, (err) => { + const errorMessage = realStripe.invoices._generateConnectionErrorMessage( 1 ); expect(err.message).to.equal(errorMessage); @@ -164,8 +164,8 @@ describe('StripeResource', function() { }); }); - it('should stop retrying after a successful retry', function(done) { - nock('https://' + options.host) + it('should stop retrying after a successful retry', (done) => { + nock(`https://${options.host}`) .post(options.path, options.params) .replyWithError('bad stuff') .post(options.path, options.params) @@ -177,14 +177,14 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(2); - realStripe.charges.create(options.data, function(err, charge) { + realStripe.charges.create(options.data, (err, charge) => { expect(charge.id).to.equal('ch_123'); done(); }); }); - it('should retry on a 409 error', function(done) { - nock('https://' + options.host) + it('should retry on a 409 error', (done) => { + nock(`https://${options.host}`) .post(options.path, options.params) .reply(409, { error: { @@ -200,14 +200,14 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.create(options.data, function(err, charge) { + realStripe.charges.create(options.data, (err, charge) => { expect(charge.id).to.equal('ch_123'); done(); }); }); - it('should not retry on a 400 error', function(done) { - nock('https://' + options.host) + it('should not retry on a 400 error', (done) => { + nock(`https://${options.host}`) .post(options.path, options.params) .reply(400, { error: { @@ -217,14 +217,14 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.create(options.data, function(err) { + realStripe.charges.create(options.data, (err) => { expect(err.type).to.equal('StripeCardError'); done(); }); }); - it('should not retry on a 500 error when the method is POST', function(done) { - nock('https://' + options.host) + it('should not retry on a 500 error when the method is POST', (done) => { + nock(`https://${options.host}`) .post(options.path, options.params) .reply(500, { error: { @@ -234,13 +234,13 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.create(options.data, function(err) { + realStripe.charges.create(options.data, (err) => { expect(err.type).to.equal('StripeAPIError'); done(); }); }); - it('should handle OAuth errors gracefully', function(done) { + it('should handle OAuth errors gracefully', (done) => { nock('https://connect.stripe.com') .post('/oauth/token') .reply(400, { @@ -251,14 +251,14 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.oauth.token(options.data, function(err) { + realStripe.oauth.token(options.data, (err) => { expect(err.type).to.equal('StripeInvalidGrantError'); done(); }); }); - it('should retry on a 503 error when the method is POST', function(done) { - nock('https://' + options.host) + it('should retry on a 503 error when the method is POST', (done) => { + nock(`https://${options.host}`) .post(options.path, options.params) .reply(503, { error: { @@ -274,21 +274,21 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.create(options.data, function(err, charge) { + realStripe.charges.create(options.data, (err, charge) => { expect(charge.id).to.equal('ch_123'); done(); }); }); - it('should retry on a 500 error when the method is GET', function(done) { - nock('https://' + options.host) - .get(options.path + '/ch_123') + it('should retry on a 500 error when the method is GET', (done) => { + nock(`https://${options.host}`) + .get(`${options.path}/ch_123`) .reply(500, { error: { type: 'api_error', }, }) - .get(options.path + '/ch_123') + .get(`${options.path}/ch_123`) .reply(200, { id: 'ch_123', object: 'charge', @@ -297,17 +297,17 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.retrieve('ch_123', function(err, charge) { + realStripe.charges.retrieve('ch_123', (err, charge) => { expect(charge.id).to.equal('ch_123'); done(); }); }); - it('should add an idempotency key for retries using the POST method', function(done) { - var headers; + it('should add an idempotency key for retries using the POST method', (done) => { + let headers; // Fail the first request but succeed on the 2nd. - nock('https://' + options.host) + nock(`https://${options.host}`) .post(options.path, options.params) .replyWithError('bad stuff') .post(options.path, options.params) @@ -326,19 +326,19 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.create(options.data, function() { + realStripe.charges.create(options.data, () => { expect(headers).to.have.property('idempotency-key'); done(); }); }); - it('should not add idempotency key for retries using the GET method', function(done) { - var headers; + it('should not add idempotency key for retries using the GET method', (done) => { + let headers; - nock('https://' + options.host) - .get(options.path + '/ch_123') + nock(`https://${options.host}`) + .get(`${options.path}/ch_123`) .replyWithError('bad stuff') - .get(options.path + '/ch_123') + .get(`${options.path}/ch_123`) .reply(function(uri, requestBody, cb) { headers = this.req.headers; @@ -354,17 +354,17 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.retrieve('ch_123', function() { + realStripe.charges.retrieve('ch_123', () => { expect(headers).to.not.have.property('idempotency-key'); done(); }); }); - it('should reuse the given idempotency key provided for retries', function(done) { - var key = uuid(); - var headers; + it('should reuse the given idempotency key provided for retries', (done) => { + const key = uuid(); + let headers; - nock('https://' + options.host) + nock(`https://${options.host}`) .post(options.path, options.params) .replyWithError('bad stuff') .post(options.path, options.params) @@ -383,21 +383,17 @@ describe('StripeResource', function() { realStripe.setMaxNetworkRetries(1); - realStripe.charges.create( - options.data, - {idempotency_key: key}, - function() { - expect(headers['idempotency-key']).to.equal(key); - done(); - } - ); + realStripe.charges.create(options.data, {idempotency_key: key}, () => { + expect(headers['idempotency-key']).to.equal(key); + done(); + }); }); }); - describe('_shouldRetry', function() { - it("should return false if we've reached maximum retries", function() { + describe('_shouldRetry', () => { + it("should return false if we've reached maximum retries", () => { stripe.setMaxNetworkRetries(1); - var res = stripe.invoices._shouldRetry( + const res = stripe.invoices._shouldRetry( { statusCode: 409, }, @@ -407,9 +403,9 @@ describe('StripeResource', function() { expect(res).to.equal(false); }); - it('should return true if we have more retries available', function() { + it('should return true if we have more retries available', () => { stripe.setMaxNetworkRetries(1); - var res = stripe.invoices._shouldRetry( + const res = stripe.invoices._shouldRetry( { statusCode: 409, }, @@ -419,9 +415,9 @@ describe('StripeResource', function() { expect(res).to.equal(true); }); - it('should return true if the error code is either 409 or 503', function() { + it('should return true if the error code is either 409 or 503', () => { stripe.setMaxNetworkRetries(1); - var res = stripe.invoices._shouldRetry( + let res = stripe.invoices._shouldRetry( { statusCode: 409, }, @@ -440,11 +436,11 @@ describe('StripeResource', function() { expect(res).to.equal(true); }); - it('should return false if the status is 200', function() { + it('should return false if the status is 200', () => { stripe.setMaxNetworkRetries(2); // mocking that we're on our 2nd request - var res = stripe.invoices._shouldRetry( + const res = stripe.invoices._shouldRetry( { statusCode: 200, req: {_requestEvent: {method: 'POST'}}, @@ -456,13 +452,13 @@ describe('StripeResource', function() { }); }); - describe('_getSleepTimeInMS', function() { - it('should not exceed the maximum or minimum values', function() { - var sleepSeconds; - var max = stripe.getMaxNetworkRetryDelay(); - var min = stripe.getInitialNetworkRetryDelay(); + describe('_getSleepTimeInMS', () => { + it('should not exceed the maximum or minimum values', () => { + let sleepSeconds; + const max = stripe.getMaxNetworkRetryDelay(); + const min = stripe.getInitialNetworkRetryDelay(); - for (var i = 0; i < 10; i++) { + for (let i = 0; i < 10; i++) { sleepSeconds = stripe.invoices._getSleepTimeInMS(i) / 1000; expect(sleepSeconds).to.be.at.most(max); diff --git a/test/Webhook.spec.js b/test/Webhook.spec.js index 2ba87061a9..23344013c0 100644 --- a/test/Webhook.spec.js +++ b/test/Webhook.spec.js @@ -1,25 +1,25 @@ 'use strict'; -var stripe = require('../testUtils').getSpyableStripe(); -var expect = require('chai').expect; -var Buffer = require('safe-buffer').Buffer; +const stripe = require('../testUtils').getSpyableStripe(); +const expect = require('chai').expect; +const Buffer = require('safe-buffer').Buffer; -var EVENT_PAYLOAD = { +const EVENT_PAYLOAD = { id: 'evt_test_webhook', object: 'event', }; -var EVENT_PAYLOAD_STRING = JSON.stringify(EVENT_PAYLOAD, null, 2); +const EVENT_PAYLOAD_STRING = JSON.stringify(EVENT_PAYLOAD, null, 2); -var SECRET = 'whsec_test_secret'; +const SECRET = 'whsec_test_secret'; -describe('Webhooks', function() { - describe('.constructEvent', function() { - it('should return an Event instance from a valid JSON payload and valid signature header', function() { - var header = generateHeaderString({ +describe('Webhooks', () => { + describe('.constructEvent', () => { + it('should return an Event instance from a valid JSON payload and valid signature header', () => { + const header = generateHeaderString({ payload: EVENT_PAYLOAD_STRING, }); - var event = stripe.webhooks.constructEvent( + const event = stripe.webhooks.constructEvent( EVENT_PAYLOAD_STRING, header, SECRET @@ -28,11 +28,11 @@ describe('Webhooks', function() { expect(event.id).to.equal(EVENT_PAYLOAD.id); }); - it('should raise a JSON error from invalid JSON payload', function() { - var header = generateHeaderString({ + it('should raise a JSON error from invalid JSON payload', () => { + const header = generateHeaderString({ payload: '} I am not valid JSON; 123][', }); - expect(function() { + expect(() => { stripe.webhooks.constructEvent( '} I am not valid JSON; 123][', header, @@ -41,22 +41,22 @@ describe('Webhooks', function() { }).to.throw(/Unexpected token/); }); - it('should raise a SignatureVerificationError from a valid JSON payload and an invalid signature header', function() { - var header = 'bad_header'; + it('should raise a SignatureVerificationError from a valid JSON payload and an invalid signature header', () => { + const header = 'bad_header'; - expect(function() { + expect(() => { stripe.webhooks.constructEvent(EVENT_PAYLOAD_STRING, header, SECRET); }).to.throw(/Unable to extract timestamp and signatures from header/); }); }); - describe('.verifySignatureHeader', function() { - it('should raise a SignatureVerificationError when the header does not have the expected format', function() { - var header = "I'm not even a real signature header"; + describe('.verifySignatureHeader', () => { + it('should raise a SignatureVerificationError when the header does not have the expected format', () => { + const header = "I'm not even a real signature header"; - var expectedMessage = /Unable to extract timestamp and signatures from header/; + const expectedMessage = /Unable to extract timestamp and signatures from header/; - expect(function() { + expect(() => { stripe.webhooks.signature.verifyHeader( EVENT_PAYLOAD_STRING, header, @@ -64,7 +64,7 @@ describe('Webhooks', function() { ); }).to.throw(expectedMessage); - expect(function() { + expect(() => { stripe.webhooks.signature.verifyHeader( EVENT_PAYLOAD_STRING, null, @@ -72,7 +72,7 @@ describe('Webhooks', function() { ); }).to.throw(expectedMessage); - expect(function() { + expect(() => { stripe.webhooks.signature.verifyHeader( EVENT_PAYLOAD_STRING, undefined, @@ -80,7 +80,7 @@ describe('Webhooks', function() { ); }).to.throw(expectedMessage); - expect(function() { + expect(() => { stripe.webhooks.signature.verifyHeader( EVENT_PAYLOAD_STRING, '', @@ -89,12 +89,12 @@ describe('Webhooks', function() { }).to.throw(expectedMessage); }); - it('should raise a SignatureVerificationError when there are no signatures with the expected scheme', function() { - var header = generateHeaderString({ + it('should raise a SignatureVerificationError when there are no signatures with the expected scheme', () => { + const header = generateHeaderString({ scheme: 'v0', }); - expect(function() { + expect(() => { stripe.webhooks.signature.verifyHeader( EVENT_PAYLOAD_STRING, header, @@ -103,12 +103,12 @@ describe('Webhooks', function() { }).to.throw(/No signatures found with expected scheme/); }); - it('should raise a SignatureVerificationError when there are no valid signatures for the payload', function() { - var header = generateHeaderString({ + it('should raise a SignatureVerificationError when there are no valid signatures for the payload', () => { + const header = generateHeaderString({ signature: 'bad_signature', }); - expect(function() { + expect(() => { stripe.webhooks.signature.verifyHeader( EVENT_PAYLOAD_STRING, header, @@ -119,12 +119,12 @@ describe('Webhooks', function() { ); }); - it('should raise a SignatureVerificationError when the timestamp is not within the tolerance', function() { - var header = generateHeaderString({ + it('should raise a SignatureVerificationError when the timestamp is not within the tolerance', () => { + const header = generateHeaderString({ timestamp: Date.now() / 1000 - 15, }); - expect(function() { + expect(() => { stripe.webhooks.signature.verifyHeader( EVENT_PAYLOAD_STRING, header, @@ -137,8 +137,8 @@ describe('Webhooks', function() { it( 'should return true when the header contains a valid signature and ' + 'the timestamp is within the tolerance', - function() { - var header = generateHeaderString({ + () => { + const header = generateHeaderString({ timestamp: Date.now() / 1000, }); @@ -153,8 +153,8 @@ describe('Webhooks', function() { } ); - it('should return true when the header contains at least one valid signature', function() { - var header = generateHeaderString({ + it('should return true when the header contains at least one valid signature', () => { + let header = generateHeaderString({ timestamp: Date.now() / 1000, }); @@ -173,8 +173,8 @@ describe('Webhooks', function() { it( 'should return true when the header contains a valid signature ' + 'and the timestamp is off but no tolerance is provided', - function() { - var header = generateHeaderString({ + () => { + const header = generateHeaderString({ timestamp: 12345, }); @@ -188,8 +188,8 @@ describe('Webhooks', function() { } ); - it('should accept Buffer instances for the payload and header', function() { - var header = generateHeaderString({ + it('should accept Buffer instances for the payload and header', () => { + const header = generateHeaderString({ timestamp: Date.now() / 1000, }); @@ -216,13 +216,13 @@ function generateHeaderString(opts) { opts.signature = opts.signature || stripe.webhooks.signature._computeSignature( - opts.timestamp + '.' + opts.payload, + `${opts.timestamp}.${opts.payload}`, opts.secret ); - var generatedHeader = [ - 't=' + opts.timestamp, - opts.scheme + '=' + opts.signature, + const generatedHeader = [ + `t=${opts.timestamp}`, + `${opts.scheme}=${opts.signature}`, ].join(','); return generatedHeader; diff --git a/test/autoPagination.spec.js b/test/autoPagination.spec.js index 8aa204b129..3cc3d9e35c 100644 --- a/test/autoPagination.spec.js +++ b/test/autoPagination.spec.js @@ -2,55 +2,51 @@ /* eslint-disable callback-return */ -var testUtils = require('../testUtils'); -var stripe = require('../lib/stripe')(testUtils.getUserStripeKey(), 'latest'); +const testUtils = require('../testUtils'); +const stripe = require('../lib/stripe')(testUtils.getUserStripeKey(), 'latest'); -var expect = require('chai').expect; +const expect = require('chai').expect; -var LIMIT = 7; -var TOTAL_OBJECTS = 8; +const LIMIT = 7; +const TOTAL_OBJECTS = 8; describe('auto pagination', function() { this.timeout(20000); - var email = 'test.' + Date.now() + '@example.com'; - var realCustomerIds; - before(function() { - return new Promise(function(resolve) { - var createReqs = []; - for (var i = 0; i < TOTAL_OBJECTS; i++) { - createReqs.push(stripe.customers.create({email: email})); - } - return Promise.all(createReqs) - .then(function() { - // re-fetch to ensure correct order - return stripe.customers - .list({email: email}) - .then(function(customers) { - realCustomerIds = customers.data.map(function(customer) { - return customer.id; - }); - }); - }) - .then(resolve); - }); - }); - - after(function() { - return new Promise(function(resolve) { - Promise.all( - realCustomerIds.map(function(customerId) { - return stripe.customers.del(customerId); - }) - ).then(resolve); - }); - }); - - describe('callbacks', function() { - it('lets you call `next()` to iterate and `next(false)` to break', function() { - return expect( - new Promise(function(resolve, reject) { - var customerIds = []; + const email = `test.${Date.now()}@example.com`; + let realCustomerIds; + before( + () => + new Promise((resolve) => { + const createReqs = []; + for (let i = 0; i < TOTAL_OBJECTS; i++) { + createReqs.push(stripe.customers.create({email})); + } + return Promise.all(createReqs) + .then(() => + // re-fetch to ensure correct order + stripe.customers.list({email}).then((customers) => { + realCustomerIds = customers.data.map((customer) => customer.id); + }) + ) + .then(resolve); + }) + ); + + after( + () => + new Promise((resolve) => { + Promise.all( + realCustomerIds.map((customerId) => stripe.customers.del(customerId)) + ).then(resolve); + }) + ); + + describe('callbacks', () => { + it('lets you call `next()` to iterate and `next(false)` to break', () => + expect( + new Promise((resolve, reject) => { + const customerIds = []; function onCustomer(customer, next) { customerIds.push(customer.id); if (customerIds.length === LIMIT) { @@ -69,16 +65,15 @@ describe('auto pagination', function() { } stripe.customers - .list({limit: 3, email: email}) + .list({limit: 3, email}) .autoPagingEach(onCustomer, onDone); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT))); - it('lets you ignore the second arg and `return false` to break', function() { - return expect( - new Promise(function(resolve, reject) { - var customerIds = []; + it('lets you ignore the second arg and `return false` to break', () => + expect( + new Promise((resolve, reject) => { + const customerIds = []; function onCustomer(customer) { customerIds.push(customer.id); if (customerIds.length === LIMIT) { @@ -96,16 +91,15 @@ describe('auto pagination', function() { } stripe.customers - .list({limit: 3, email: email}) + .list({limit: 3, email}) .autoPagingEach(onCustomer, onDone); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT))); - it('lets you ignore the second arg and return a Promise which returns `false` to break', function() { - return expect( - new Promise(function(resolve, reject) { - var customerIds = []; + it('lets you ignore the second arg and return a Promise which returns `false` to break', () => + expect( + new Promise((resolve, reject) => { + const customerIds = []; function onCustomer(customer) { customerIds.push(customer.id); if (customerIds.length === LIMIT) { @@ -124,16 +118,15 @@ describe('auto pagination', function() { } stripe.customers - .list({limit: 3, email: email}) + .list({limit: 3, email}) .autoPagingEach(onCustomer, onDone); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT))); - it('can use a promise instead of a callback for onDone', function() { - return expect( - new Promise(function(resolve, reject) { - var customerIds = []; + it('can use a promise instead of a callback for onDone', () => + expect( + new Promise((resolve, reject) => { + const customerIds = []; function onCustomer(customer) { customerIds.push(customer.id); } @@ -142,69 +135,65 @@ describe('auto pagination', function() { } stripe.customers - .list({limit: 3, email: email}) + .list({limit: 3, email}) .autoPagingEach(onCustomer) .then(onDone) .catch(reject); }) - ).to.eventually.deep.equal(realCustomerIds); - }); + ).to.eventually.deep.equal(realCustomerIds)); - it('handles the end of a list properly when the last page is full', function() { - return expect( - new Promise(function(resolve, reject) { - var customerIds = []; + it('handles the end of a list properly when the last page is full', () => + expect( + new Promise((resolve, reject) => { + const customerIds = []; return stripe.customers - .list({email: email, limit: TOTAL_OBJECTS / 2}) - .autoPagingEach(function(customer) { + .list({email, limit: TOTAL_OBJECTS / 2}) + .autoPagingEach((customer) => { customerIds.push(customer.id); }) .catch(reject) - .then(function() { + .then(() => { resolve(customerIds); }); }) - ).to.eventually.deep.equal(realCustomerIds); - }); + ).to.eventually.deep.equal(realCustomerIds)); - it('handles the end of a list properly when the last page is not full', function() { - return expect( - new Promise(function(resolve, reject) { - var customerIds = []; + it('handles the end of a list properly when the last page is not full', () => + expect( + new Promise((resolve, reject) => { + const customerIds = []; return stripe.customers - .list({email: email, limit: TOTAL_OBJECTS - 2}) - .autoPagingEach(function(customer) { + .list({email, limit: TOTAL_OBJECTS - 2}) + .autoPagingEach((customer) => { customerIds.push(customer.id); }) .catch(reject) - .then(function() { + .then(() => { resolve(customerIds); }); }) - ).to.eventually.deep.equal(realCustomerIds); - }); + ).to.eventually.deep.equal(realCustomerIds)); - it('handles a list which is shorter than the page size properly', function() { - return expect( - new Promise(function(resolve, reject) { - var customerIds = []; + it('handles a list which is shorter than the page size properly', () => + expect( + new Promise((resolve, reject) => { + const customerIds = []; return stripe.customers - .list({email: email, limit: TOTAL_OBJECTS + 2}) - .autoPagingEach(function(customer) { + .list({email, limit: TOTAL_OBJECTS + 2}) + .autoPagingEach((customer) => { customerIds.push(customer.id); }) .catch(reject) - .then(function() { + .then(() => { resolve(customerIds); }); }) - ).to.eventually.deep.equal(realCustomerIds); - }); + ).to.eventually.deep.equal(realCustomerIds)); - it('handles errors after the first page correctly (callback)', function() { - return expect( - new Promise(function(resolve, reject) { - var i = 0; + it('handles errors after the first page correctly (callback)', () => + expect( + new Promise((resolve, reject) => { + let i = 0; function onCustomer() { i += 1; if (i > 4) { @@ -212,8 +201,8 @@ describe('auto pagination', function() { } } return stripe.customers - .list({email: email, limit: 3}) - .autoPagingEach(onCustomer, function(err) { + .list({email, limit: 3}) + .autoPagingEach(onCustomer, (err) => { if (err) { resolve(err.message); } else { @@ -221,13 +210,12 @@ describe('auto pagination', function() { } }); }) - ).to.eventually.deep.equal('Simulated error'); - }); + ).to.eventually.deep.equal('Simulated error')); - it('handles errors after the first page correctly (promise)', function() { - return expect( - new Promise(function(resolve, reject) { - var i = 0; + it('handles errors after the first page correctly (promise)', () => + expect( + new Promise((resolve, reject) => { + let i = 0; function onCustomer() { i += 1; if (i > 4) { @@ -235,91 +223,73 @@ describe('auto pagination', function() { } } return stripe.customers - .list({email: email, limit: 3}) + .list({email, limit: 3}) .autoPagingEach(onCustomer) - .then(function() { + .then(() => { reject(Error('Expected an error, did not get one.')); }) - .catch(function(err) { + .catch((err) => { resolve(err.message); }); }) - ).to.eventually.deep.equal('Simulated error'); - }); + ).to.eventually.deep.equal('Simulated error')); }); - describe('async iterators', function() { + describe('async iterators', () => { if (testUtils.envSupportsForAwait()) { // `for await` throws a syntax error everywhere but node 10, // so we must conditionally require it. - var forAwaitUntil = require('../testUtils/forAwait.node10').forAwaitUntil; - - it('works with `for await` when that feature exists (user break)', function() { - return expect( - new Promise(function(resolve, reject) { - forAwaitUntil( - stripe.customers.list({limit: 3, email: email}), - LIMIT - ) - .then(function(customers) { - resolve( - customers.map(function(customer) { - return customer.id; - }) - ); + const forAwaitUntil = require('../testUtils/forAwait.node10') + .forAwaitUntil; + + it('works with `for await` when that feature exists (user break)', () => + expect( + new Promise((resolve, reject) => { + forAwaitUntil(stripe.customers.list({limit: 3, email}), LIMIT) + .then((customers) => { + resolve(customers.map((customer) => customer.id)); }) .catch(reject); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT))); - it('works with `for await` when that feature exists (end of list)', function() { - return expect( - new Promise(function(resolve, reject) { + it('works with `for await` when that feature exists (end of list)', () => + expect( + new Promise((resolve, reject) => { forAwaitUntil( - stripe.customers.list({limit: 3, email: email}), + stripe.customers.list({limit: 3, email}), TOTAL_OBJECTS + 1 ) - .then(function(customers) { - resolve( - customers.map(function(customer) { - return customer.id; - }) - ); + .then((customers) => { + resolve(customers.map((customer) => customer.id)); }) .catch(reject); }) - ).to.eventually.deep.equal(realCustomerIds); - }); + ).to.eventually.deep.equal(realCustomerIds)); } if (testUtils.envSupportsAwait()) { // Similarly, `await` throws a syntax error below Node 7.6. - var awaitUntil = require('../testUtils/await.node7').awaitUntil; - - it('works with `await` and a while loop when await exists', function() { - return expect( - new Promise(function(resolve, reject) { - awaitUntil(stripe.customers.list({limit: 3, email: email}), LIMIT) - .then(function(customers) { - resolve( - customers.map(function(customer) { - return customer.id; - }) - ); + const awaitUntil = require('../testUtils/await.node7').awaitUntil; + + it('works with `await` and a while loop when await exists', () => + expect( + new Promise((resolve, reject) => { + awaitUntil(stripe.customers.list({limit: 3, email}), LIMIT) + .then((customers) => { + resolve(customers.map((customer) => customer.id)); }) .catch(reject); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT))); } - it('returns an empty object from .return() so that `break;` works in for-await', function() { - return expect( - new Promise(function(resolve, reject) { - var iter = stripe.customers.list({limit: 3, email: email}); + it('returns an empty object from .return() so that `break;` works in for-await', () => + expect( + new Promise((resolve, reject) => { + const iter = stripe.customers.list({limit: 3, email}); - var customerIds = []; + const customerIds = []; function handleIter(result) { customerIds.push(result.value.id); expect(iter.return()).to.deep.equal({}); @@ -328,20 +298,19 @@ describe('auto pagination', function() { iter .next() .then(handleIter) - .then(function() { + .then(() => { resolve(customerIds); }) .catch(reject); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, 1)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, 1))); - it('works when you call it sequentially', function() { - return expect( - new Promise(function(resolve, reject) { - var iter = stripe.customers.list({limit: 3, email: email}); + it('works when you call it sequentially', () => + expect( + new Promise((resolve, reject) => { + const iter = stripe.customers.list({limit: 3, email}); - var customerIds = []; + const customerIds = []; function handleIter(result) { customerIds.push(result.value.id); if (customerIds.length < 7) { @@ -351,20 +320,19 @@ describe('auto pagination', function() { iter .next() .then(handleIter) - .then(function() { + .then(() => { resolve(customerIds); }) .catch(reject); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT))); - it('gives you the same result each time when you call it multiple times in parallel', function() { - return expect( - new Promise(function(resolve, reject) { - var iter = stripe.customers.list({limit: 3, email: email}); + it('gives you the same result each time when you call it multiple times in parallel', () => + expect( + new Promise((resolve, reject) => { + const iter = stripe.customers.list({limit: 3, email}); - var customerIds = []; + const customerIds = []; function handleIter(result) { customerIds.push(result.value.id); } @@ -374,102 +342,86 @@ describe('auto pagination', function() { iter .next() .then(handleIter) - .then(function() { - return Promise.all([ + .then(() => + Promise.all([ iter.next().then(handleIter), iter.next().then(handleIter), - ]); - }) - .then(function() { - return Promise.all([ + ]) + ) + .then(() => + Promise.all([ iter.next().then(handleIter), iter.next().then(handleIter), - ]); - }) - .then(function() { - return Promise.all([ + ]) + ) + .then(() => + Promise.all([ iter.next().then(handleIter), iter.next().then(handleIter), - ]); - }), + ]) + ), ]) - .then(function() { + .then(() => { resolve(customerIds); }) .catch(reject); }) ).to.eventually.deep.equal( - realCustomerIds.slice(0, 4).reduce(function(acc, x) { + realCustomerIds.slice(0, 4).reduce((acc, x) => { acc.push(x); acc.push(x); return acc; }, []) - ); - }); + )); }); - describe('autoPagingToArray', function() { - it('can go to the end', function() { - return expect( - new Promise(function(resolve, reject) { + describe('autoPagingToArray', () => { + it('can go to the end', () => + expect( + new Promise((resolve, reject) => { stripe.customers - .list({limit: 3, email: email}) + .list({limit: 3, email}) .autoPagingToArray({limit: TOTAL_OBJECTS + 1}) - .then(function(customers) { - return customers.map(function(customer) { - return customer.id; - }); - }) + .then((customers) => customers.map((customer) => customer.id)) .then(resolve) .catch(reject); }) - ).to.eventually.deep.equal(realCustomerIds); - }); + ).to.eventually.deep.equal(realCustomerIds)); - it('returns a promise of an array', function() { - return expect( - new Promise(function(resolve, reject) { + it('returns a promise of an array', () => + expect( + new Promise((resolve, reject) => { stripe.customers - .list({limit: 3, email: email}) + .list({limit: 3, email}) .autoPagingToArray({limit: LIMIT}) - .then(function(customers) { - return customers.map(function(customer) { - return customer.id; - }); - }) + .then((customers) => customers.map((customer) => customer.id)) .then(resolve) .catch(reject); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT))); - it('accepts an onDone callback, passing an array', function() { - return expect( - new Promise(function(resolve, reject) { + it('accepts an onDone callback, passing an array', () => + expect( + new Promise((resolve, reject) => { function onDone(err, customers) { if (err) { reject(err); } else { - resolve( - customers.map(function(customer) { - return customer.id; - }) - ); + resolve(customers.map((customer) => customer.id)); } } stripe.customers - .list({limit: 3, email: email}) + .list({limit: 3, email}) .autoPagingToArray({limit: LIMIT}, onDone); }) - ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT)); - }); + ).to.eventually.deep.equal(realCustomerIds.slice(0, LIMIT))); - it('enforces a `limit` arg', function() { - return expect( - new Promise(function(resolve, reject) { + it('enforces a `limit` arg', () => + expect( + new Promise((resolve, reject) => { try { - stripe.customers.list({limit: 3, email: email}).autoPagingToArray(); + stripe.customers.list({limit: 3, email}).autoPagingToArray(); reject(Error('Should have thrown.')); } catch (err) { resolve(err.message); @@ -477,15 +429,14 @@ describe('auto pagination', function() { }) ).to.eventually.equal( 'You must pass a `limit` option to autoPagingToArray, eg; `autoPagingToArray({limit: 1000});`.' - ); - }); + )); - it('caps the `limit` arg to a reasonable ceiling', function() { - return expect( - new Promise(function(resolve, reject) { + it('caps the `limit` arg to a reasonable ceiling', () => + expect( + new Promise((resolve, reject) => { try { stripe.customers - .list({limit: 3, email: email}) + .list({limit: 3, email}) .autoPagingToArray({limit: 1000000}); reject(Error('Should have thrown.')); } catch (err) { @@ -494,37 +445,34 @@ describe('auto pagination', function() { }) ).to.eventually.equal( 'You cannot specify a limit of more than 10,000 items to fetch in `autoPagingToArray`; use `autoPagingEach` to iterate through longer lists.' - ); - }); + )); }); - describe('api compat edge cases', function() { - it('lets you listen to the first request as its own promise, and separately each item, but only sends one request for the first page.', function() { - return expect( - new Promise(function(resolve, reject) { + describe('api compat edge cases', () => { + it('lets you listen to the first request as its own promise, and separately each item, but only sends one request for the first page.', () => + expect( + new Promise((resolve, reject) => { // Count requests: we want one for the first page (not two), and then one for the second page. - var reqCount = 0; + let reqCount = 0; function onRequest() { reqCount += 1; } stripe.on('request', onRequest); - var customerIds = []; - var p = stripe.customers.list({email: email, limit: 4}); + const customerIds = []; + const p = stripe.customers.list({email, limit: 4}); Promise.all([ p, - p.autoPagingEach(function(customer) { + p.autoPagingEach((customer) => { customerIds.push(customer.id); }), ]) - .then(function(results) { + .then((results) => { stripe.off('request', onRequest); expect(reqCount).to.equal(2); // not 3. resolve({ - firstReq: results[0].data.map(function(customer) { - return customer.id; - }), + firstReq: results[0].data.map((customer) => customer.id), paginated: customerIds, }); }) @@ -533,7 +481,6 @@ describe('auto pagination', function() { ).to.eventually.deep.equal({ firstReq: realCustomerIds.slice(0, 4), paginated: realCustomerIds, - }); - }); + })); }); }); diff --git a/test/flows.spec.js b/test/flows.spec.js index e577bcc90c..5df1029065 100644 --- a/test/flows.spec.js +++ b/test/flows.spec.js @@ -1,54 +1,53 @@ 'use strict'; -var testUtils = require('../testUtils'); -var chai = require('chai'); -var stripe = require('../lib/stripe')(testUtils.getUserStripeKey(), 'latest'); -var fs = require('fs'); -var path = require('path'); -var stream = require('stream'); -var expect = chai.expect; - -var CUSTOMER_DETAILS = { +const testUtils = require('../testUtils'); +const chai = require('chai'); +const stripe = require('../lib/stripe')(testUtils.getUserStripeKey(), 'latest'); +const fs = require('fs'); +const path = require('path'); +const stream = require('stream'); +const expect = chai.expect; + +const CUSTOMER_DETAILS = { description: 'Some customer', card: 'tok_visa', }; -var CURRENCY = '_DEFAULT_CURRENCY_NOT_YET_GOTTEN_'; +let CURRENCY = '_DEFAULT_CURRENCY_NOT_YET_GOTTEN_'; describe('Flows', function() { // Note: These tests must be run as one so we can retrieve the // default_currency (required in subsequent tests); - var cleanup = new testUtils.CleanupUtility(); + const cleanup = new testUtils.CleanupUtility(); this.timeout(30000); - it('Allows me to retrieve default_currency', function() { - return expect( - stripe.account.retrieve().then(function(acct) { + it('Allows me to retrieve default_currency', () => + expect( + stripe.account.retrieve().then((acct) => { CURRENCY = acct.default_currency; return acct; }) - ).to.eventually.have.property('default_currency'); - }); + ).to.eventually.have.property('default_currency')); - describe('Plan+Subscription flow', function() { - it('Allows me to: Create a plan and subscribe a customer to it', function() { - return expect( + describe('Plan+Subscription flow', () => { + it('Allows me to: Create a plan and subscribe a customer to it', () => + expect( Promise.all([ stripe.plans.create({ - id: 'plan' + testUtils.getRandomString(), + id: `plan${testUtils.getRandomString()}`, amount: 1700, currency: CURRENCY, interval: 'month', nickname: 'Gold Super Amazing Tier', product: { - name: 'product' + testUtils.getRandomString(), + name: `product${testUtils.getRandomString()}`, }, }), stripe.customers.create(CUSTOMER_DETAILS), - ]).then(function(j) { - var plan = j[0]; - var customer = j[1]; + ]).then((j) => { + const plan = j[0]; + const customer = j[1]; cleanup.deleteCustomer(customer.id); cleanup.deletePlan(plan.id); @@ -57,28 +56,27 @@ describe('Flows', function() { plan: plan.id, }); }) - ).to.eventually.have.property('status', 'active'); - }); + ).to.eventually.have.property('status', 'active')); - it('Allows me to: Create a plan and subscribe a customer to it, and update subscription (multi-subs API)', function() { - var plan; + it('Allows me to: Create a plan and subscribe a customer to it, and update subscription (multi-subs API)', () => { + let plan; return expect( Promise.all([ stripe.plans.create({ - id: 'plan' + testUtils.getRandomString(), + id: `plan${testUtils.getRandomString()}`, amount: 1700, currency: CURRENCY, interval: 'month', nickname: 'Gold Super Amazing Tier', product: { - name: 'product' + testUtils.getRandomString(), + name: `product${testUtils.getRandomString()}`, }, }), stripe.customers.create(CUSTOMER_DETAILS), ]) - .then(function(j) { + .then((j) => { plan = j[0]; - var customer = j[1]; + const customer = j[1]; cleanup.deleteCustomer(customer.id); cleanup.deletePlan(plan.id); @@ -87,61 +85,59 @@ describe('Flows', function() { plan: plan.id, }); }) - .then(function(subscription) { - return stripe.customers.updateSubscription( + .then((subscription) => + stripe.customers.updateSubscription( subscription.customer, subscription.id, { plan: plan.id, quantity: '3', } - ); - }) - .then(function(subscription) { - return [subscription.status, subscription.quantity]; - }) + ) + ) + .then((subscription) => [subscription.status, subscription.quantity]) ).to.eventually.deep.equal(['active', 3]); }); - it('Errors when I attempt to subscribe a customer to a non-existent plan', function() { - return expect( - stripe.customers.create(CUSTOMER_DETAILS).then(function(customer) { + it('Errors when I attempt to subscribe a customer to a non-existent plan', () => + expect( + stripe.customers.create(CUSTOMER_DETAILS).then((customer) => { cleanup.deleteCustomer(customer.id); return stripe.customers .updateSubscription(customer.id, { - plan: 'someNonExistentPlan' + testUtils.getRandomString(), + plan: `someNonExistentPlan${testUtils.getRandomString()}`, }) - .then(null, function(err) { - // Resolve with the error so we can inspect it below - return err; - }); + .then( + null, + (err) => + // Resolve with the error so we can inspect it below + err + ); }) - ).to.eventually.satisfy(function(err) { - return ( + ).to.eventually.satisfy( + (err) => err.type === 'StripeInvalidRequestError' && err.rawType === 'invalid_request_error' - ); - }); - }); + )); - it('Allows me to: subscribe then update with `cancel_at_period_end` defined', function() { - return expect( + it('Allows me to: subscribe then update with `cancel_at_period_end` defined', () => + expect( Promise.all([ stripe.plans.create({ - id: 'plan' + testUtils.getRandomString(), + id: `plan${testUtils.getRandomString()}`, amount: 1700, currency: CURRENCY, interval: 'month', nickname: 'Silver Super Amazing Tier', product: { - name: 'product' + testUtils.getRandomString(), + name: `product${testUtils.getRandomString()}`, }, }), stripe.customers.create(CUSTOMER_DETAILS), - ]).then(function(j) { - var plan = j[0]; - var customer = j[1]; + ]).then((j) => { + const plan = j[0]; + const customer = j[1]; cleanup.deleteCustomer(customer.id); cleanup.deletePlan(plan.id); @@ -151,235 +147,186 @@ describe('Flows', function() { cancel_at_period_end: true, }); }) - ).to.eventually.have.property('cancel_at_period_end', true); - }); + ).to.eventually.have.property('cancel_at_period_end', true)); - describe('Plan name variations', function() { + describe('Plan name variations', () => { [ - '34535_355453' + testUtils.getRandomString(), - 'TEST_239291' + testUtils.getRandomString(), - 'TEST_a-i' + testUtils.getRandomString(), - 'foobarbazteston___etwothree' + testUtils.getRandomString(), - ].forEach(function(planID) { - it( - 'Allows me to create and retrieve plan with ID: ' + planID, - function() { - return expect( - stripe.plans - .create({ - id: planID, - amount: 1700, - currency: CURRENCY, - interval: 'month', - nickname: 'generic', - product: { - name: 'product' + testUtils.getRandomString(), - }, - }) - .then(function() { - cleanup.deletePlan(planID); - return stripe.plans.retrieve(planID); - }) - ).to.eventually.have.property('id', planID); - } - ); + `34535_355453${testUtils.getRandomString()}`, + `TEST_239291${testUtils.getRandomString()}`, + `TEST_a-i${testUtils.getRandomString()}`, + `foobarbazteston___etwothree${testUtils.getRandomString()}`, + ].forEach((planID) => { + it(`Allows me to create and retrieve plan with ID: ${planID}`, () => + expect( + stripe.plans + .create({ + id: planID, + amount: 1700, + currency: CURRENCY, + interval: 'month', + nickname: 'generic', + product: { + name: `product${testUtils.getRandomString()}`, + }, + }) + .then(() => { + cleanup.deletePlan(planID); + return stripe.plans.retrieve(planID); + }) + ).to.eventually.have.property('id', planID)); }); }); }); - describe('Coupon flow', function() { - var customer; - var coupon; + describe('Coupon flow', () => { + let customer; + let coupon; - describe('When I create a coupon & customer', function() { - it('Does so', function() { - return expect( + describe('When I create a coupon & customer', () => { + it('Does so', () => + expect( Promise.all([ stripe.coupons.create({ percent_off: 20, duration: 'once', }), stripe.customers.create(CUSTOMER_DETAILS), - ]).then(function(joined) { + ]).then((joined) => { coupon = joined[0]; customer = joined[1]; }) - ).to.not.be.eventually.rejected; - }); - describe('And I apply the coupon to the customer', function() { - it('Does so', function() { - return expect( + ).to.not.be.eventually.rejected); + describe('And I apply the coupon to the customer', () => { + it('Does so', () => + expect( stripe.customers.update(customer.id, { coupon: coupon.id, }) - ).to.not.be.eventually.rejected; - }); - it('Can be retrieved from that customer', function() { - return expect( + ).to.not.be.eventually.rejected); + it('Can be retrieved from that customer', () => + expect( stripe.customers.retrieve(customer.id) - ).to.eventually.have.nested.property('discount.coupon.id', coupon.id); - }); - describe('The resulting discount', function() { - it('Can be removed', function() { - return expect( + ).to.eventually.have.nested.property( + 'discount.coupon.id', + coupon.id + )); + describe('The resulting discount', () => { + it('Can be removed', () => + expect( stripe.customers.deleteDiscount(customer.id) - ).to.eventually.have.property('deleted', true); - }); - describe('Re-querying it', function() { - it('Does indeed indicate that it is deleted', function() { - return expect( + ).to.eventually.have.property('deleted', true)); + describe('Re-querying it', () => { + it('Does indeed indicate that it is deleted', () => + expect( stripe.customers.retrieve(customer.id) - ).to.eventually.have.property('discount', null); - }); + ).to.eventually.have.property('discount', null)); }); }); }); }); }); - describe('Metadata flow', function() { - it('Can save and retrieve metadata', function() { - var customer; + describe('Metadata flow', () => { + it('Can save and retrieve metadata', () => { + let customer; return expect( stripe.customers .create(CUSTOMER_DETAILS) - .then(function(cust) { + .then((cust) => { customer = cust; cleanup.deleteCustomer(cust.id); return stripe.customers.setMetadata(cust.id, {foo: '123'}); }) - .then(function() { - return stripe.customers.getMetadata(customer.id); - }) + .then(() => stripe.customers.getMetadata(customer.id)) ).to.eventually.deep.equal({foo: '123'}); }); - it('Can reset metadata', function() { - var customer; + it('Can reset metadata', () => { + let customer; return expect( stripe.customers .create(CUSTOMER_DETAILS) - .then(function(cust) { + .then((cust) => { customer = cust; cleanup.deleteCustomer(cust.id); return stripe.customers.setMetadata(cust.id, {baz: '123'}); }) - .then(function() { - return stripe.customers.setMetadata(customer.id, null); - }) - .then(function() { - return stripe.customers.getMetadata(customer.id); - }) + .then(() => stripe.customers.setMetadata(customer.id, null)) + .then(() => stripe.customers.getMetadata(customer.id)) ).to.eventually.deep.equal({}); }); - it('Resets metadata when setting new metadata', function() { - var customer; + it('Resets metadata when setting new metadata', () => { + let customer; return expect( stripe.customers .create(CUSTOMER_DETAILS) - .then(function(cust) { + .then((cust) => { customer = cust; cleanup.deleteCustomer(cust.id); return stripe.customers.setMetadata(cust.id, {foo: '123'}); }) - .then(function() { - return stripe.customers.setMetadata(customer.id, {baz: '456'}); - }) + .then(() => stripe.customers.setMetadata(customer.id, {baz: '456'})) ).to.eventually.deep.equal({baz: '456'}); }); - it('Can set individual key/value pairs', function() { - var customer; + it('Can set individual key/value pairs', () => { + let customer; return expect( stripe.customers .create(CUSTOMER_DETAILS) - .then(function(cust) { + .then((cust) => { customer = cust; cleanup.deleteCustomer(cust.id); }) - .then(function() { - return stripe.customers.setMetadata(customer.id, 'baz', 456); - }) - .then(function() { - return stripe.customers.setMetadata(customer.id, '_other_', 999); - }) - .then(function() { - return stripe.customers.setMetadata(customer.id, 'foo', 123); - }) - .then(function() { + .then(() => stripe.customers.setMetadata(customer.id, 'baz', 456)) + .then(() => stripe.customers.setMetadata(customer.id, '_other_', 999)) + .then(() => stripe.customers.setMetadata(customer.id, 'foo', 123)) + .then(() => // Change foo - return stripe.customers.setMetadata(customer.id, 'foo', 222); - }) - .then(function() { + stripe.customers.setMetadata(customer.id, 'foo', 222) + ) + .then(() => // Delete baz - return stripe.customers.setMetadata(customer.id, 'baz', null); - }) - .then(function() { - return stripe.customers.getMetadata(customer.id); - }) + stripe.customers.setMetadata(customer.id, 'baz', null) + ) + .then(() => stripe.customers.getMetadata(customer.id)) ).to.eventually.deep.equal({_other_: '999', foo: '222'}); }); - it('Can set individual key/value pairs [with per request token]', function() { - var customer; - var authToken = testUtils.getUserStripeKey(); + it('Can set individual key/value pairs [with per request token]', () => { + let customer; + const authToken = testUtils.getUserStripeKey(); return expect( stripe.customers .create(CUSTOMER_DETAILS) - .then(function(cust) { + .then((cust) => { customer = cust; cleanup.deleteCustomer(cust.id); }) - .then(function() { - return stripe.customers.setMetadata( - customer.id, - {baz: 456}, - authToken - ); - }) - .then(function() { - return stripe.customers.setMetadata( - customer.id, - '_other_', - 999, - authToken - ); - }) - .then(function() { - return stripe.customers.setMetadata( - customer.id, - 'foo', - 123, - authToken - ); - }) - .then(function() { + .then(() => + stripe.customers.setMetadata(customer.id, {baz: 456}, authToken) + ) + .then(() => + stripe.customers.setMetadata(customer.id, '_other_', 999, authToken) + ) + .then(() => + stripe.customers.setMetadata(customer.id, 'foo', 123, authToken) + ) + .then(() => // Change foo - return stripe.customers.setMetadata( - customer.id, - 'foo', - 222, - authToken - ); - }) - .then(function() { + stripe.customers.setMetadata(customer.id, 'foo', 222, authToken) + ) + .then(() => // Delete baz - return stripe.customers.setMetadata( - customer.id, - 'baz', - null, - authToken - ); - }) - .then(function() { - return stripe.customers.getMetadata(customer.id, authToken); - }) + stripe.customers.setMetadata(customer.id, 'baz', null, authToken) + ) + .then(() => stripe.customers.getMetadata(customer.id, authToken)) ).to.eventually.deep.equal({_other_: '999', foo: '222'}); }); }); - describe('Expanding', function() { - describe('A customer within a charge', function() { - it('Allows you to expand a customer object', function() { - return expect( - stripe.customers.create(CUSTOMER_DETAILS).then(function(cust) { + describe('Expanding', () => { + describe('A customer within a charge', () => { + it('Allows you to expand a customer object', () => + expect( + stripe.customers.create(CUSTOMER_DETAILS).then((cust) => { cleanup.deleteCustomer(cust.id); return stripe.charges.create({ customer: cust.id, @@ -388,31 +335,29 @@ describe('Flows', function() { expand: ['customer'], }); }) - ).to.eventually.have.nested.property('customer.created'); - }); + ).to.eventually.have.nested.property('customer.created')); }); - describe("A customer's default source", function() { - it('Allows you to expand a default_source', function() { - return expect( + describe("A customer's default source", () => { + it('Allows you to expand a default_source', () => + expect( stripe.customers .create({ description: 'Some customer', source: 'tok_visa', expand: ['default_source'], }) - .then(function(cust) { + .then((cust) => { cleanup.deleteCustomer(cust.id); return cust; }) // Confirm it's expanded by checking that some prop (e.g. exp_year) exists: - ).to.eventually.have.nested.property('default_source.exp_year'); - }); + ).to.eventually.have.nested.property('default_source.exp_year')); }); }); - describe('Charge', function() { - it('Allows you to create a charge', function() { - return expect( + describe('Charge', () => { + it('Allows you to create a charge', () => + expect( stripe.charges .create({ amount: 1234, @@ -425,37 +370,32 @@ describe('Flows', function() { }, }, }) - .then(null, function(error) { - return error; - }) - ).to.eventually.have.nested.property('raw.charge'); - }); + .then(null, (error) => error) + ).to.eventually.have.nested.property('raw.charge')); }); - describe('Getting balance', function() { - it('Allows me to do so', function() { - return expect(stripe.balance.retrieve()).to.eventually.have.property( + describe('Getting balance', () => { + it('Allows me to do so', () => + expect(stripe.balance.retrieve()).to.eventually.have.property( 'object', 'balance' - ); - }); - it('Allows me to do so with specified auth key', function() { - return expect( + )); + it('Allows me to do so with specified auth key', () => + expect( stripe.balance.retrieve(testUtils.getUserStripeKey()) - ).to.eventually.have.property('object', 'balance'); - }); + ).to.eventually.have.property('object', 'balance')); }); - describe('Request/Response Events', function() { - var connectedAccountId; + describe('Request/Response Events', () => { + let connectedAccountId; - before(function(done) { + before((done) => { // Pick a random connected account to use in the `Stripe-Account` header stripe.accounts .list({ limit: 1, }) - .then(function(accounts) { + .then((accounts) => { if (accounts.data.length < 1) { return done( new Error( @@ -470,9 +410,9 @@ describe('Flows', function() { }); }); - it('should emit a `request` event to listeners on request', function(done) { - var apiVersion = '2017-06-05'; - var idempotencyKey = Math.random() + it('should emit a `request` event to listeners on request', (done) => { + const apiVersion = '2017-06-05'; + const idempotencyKey = Math.random() .toString(36) .slice(2); @@ -505,14 +445,14 @@ describe('Flows', function() { stripe_account: connectedAccountId, } ) - .then(null, function() { + .then(null, () => { // I expect there to be an error here. }); }); - it('should emit a `response` event to listeners on response', function(done) { - var apiVersion = '2017-06-05'; - var idempotencyKey = Math.random() + it('should emit a `response` event to listeners on response', (done) => { + const apiVersion = '2017-06-05'; + const idempotencyKey = Math.random() .toString(36) .slice(2); @@ -552,12 +492,12 @@ describe('Flows', function() { stripe_account: connectedAccountId, } ) - .then(null, function() { + .then(null, () => { // I expect there to be an error here. }); }); - it('should not emit a `response` event to removed listeners on response', function(done) { + it('should not emit a `response` event to removed listeners on response', (done) => { function onResponse(response) { done(new Error('How did you get here?')); } @@ -571,16 +511,16 @@ describe('Flows', function() { currency: 'usd', card: 'tok_visa', }) - .then(function() { + .then(() => { done(); }); }); }); - describe('FileUpload', function() { - it('Allows you to upload a file as a stream', function() { - var testFilename = path.join(__dirname, 'resources/data/minimal.pdf'); - var f = fs.createReadStream(testFilename); + describe('FileUpload', () => { + it('Allows you to upload a file as a stream', () => { + const testFilename = path.join(__dirname, 'resources/data/minimal.pdf'); + const f = fs.createReadStream(testFilename); return expect( stripe.fileUploads @@ -592,15 +532,13 @@ describe('Flows', function() { type: 'application/octet-stream', }, }) - .then(null, function(error) { - return error; - }) + .then(null, (error) => error) ).to.eventually.have.nested.property('size', 739); }); - it('Allows you to upload a file synchronously', function() { - var testFilename = path.join(__dirname, 'resources/data/minimal.pdf'); - var f = fs.readFileSync(testFilename); + it('Allows you to upload a file synchronously', () => { + const testFilename = path.join(__dirname, 'resources/data/minimal.pdf'); + const f = fs.readFileSync(testFilename); return expect( stripe.fileUploads @@ -612,19 +550,17 @@ describe('Flows', function() { type: 'application/octet-stream', }, }) - .then(null, function(error) { - return error; - }) + .then(null, (error) => error) ).to.eventually.have.nested.property('size', 739); }); - it('Surfaces stream errors correctly', function(done) { - var mockedStream = new stream.Readable(); - mockedStream._read = function() {}; + it('Surfaces stream errors correctly', (done) => { + const mockedStream = new stream.Readable(); + mockedStream._read = () => {}; - var fakeError = new Error('I am a fake error'); + const fakeError = new Error('I am a fake error'); - process.nextTick(function() { + process.nextTick(() => { mockedStream.emit('error', fakeError); }); @@ -637,7 +573,7 @@ describe('Flows', function() { type: 'application/octet-stream', }, }) - .catch(function(error) { + .catch((error) => { expect(error.message).to.equal( 'An error occurred while attempting to process the file for upload.' ); diff --git a/test/resources/Account.spec.js b/test/resources/Account.spec.js index 5eaef72394..e09d6f2c06 100644 --- a/test/resources/Account.spec.js +++ b/test/resources/Account.spec.js @@ -1,17 +1,17 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; +const TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; -describe('Account Resource', function() { +describe('Account Resource', () => { function uniqueEmail() { - return Math.random() + 'bob@example.com'; + return `${Math.random()}bob@example.com`; } - describe('create', function() { - it('Sends the correct request', function() { - var data = { + describe('create', () => { + it('Sends the correct request', () => { + const data = { managed: false, country: 'US', email: uniqueEmail(), @@ -20,14 +20,14 @@ describe('Account Resource', function() { expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', url: '/v1/accounts', - data: data, + data, headers: {}, }); }); }); - describe('delete', function() { - it('deletes an account successfully', function() { + describe('delete', () => { + it('deletes an account successfully', () => { stripe.account.del('acct_16Tzq6DBahdM4C8s'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -38,8 +38,8 @@ describe('Account Resource', function() { }); }); - describe('reject', function() { - it('rejects an account successfully', function() { + describe('reject', () => { + it('rejects an account successfully', () => { stripe.account.reject('acct_16Tzq6DBahdM4C8s', {reason: 'fraud'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -50,8 +50,8 @@ describe('Account Resource', function() { }); }); - describe('retrieve', function() { - it('Sends the correct request with no params', function() { + describe('retrieve', () => { + it('Sends the correct request with no params', () => { stripe.account.retrieve(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -61,7 +61,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request with ID param', function() { + it('Sends the correct request with ID param', () => { stripe.account.retrieve('foo'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -71,8 +71,8 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request with secret key', function() { - var key = 'sk_12345678901234567890123456789012'; + it('Sends the correct request with secret key', () => { + const key = 'sk_12345678901234567890123456789012'; stripe.account.retrieve(null, key); expect(stripe.LAST_REQUEST).to.deep.equal({ auth: key, @@ -83,8 +83,8 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request with secret key as first object', function() { - var params = {api_key: 'sk_12345678901234567890123456789012'}; + it('Sends the correct request with secret key as first object', () => { + const params = {api_key: 'sk_12345678901234567890123456789012'}; stripe.account.retrieve(params); expect(stripe.LAST_REQUEST).to.deep.equal({ auth: params.api_key, @@ -95,8 +95,8 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request with a callback', function() { - stripe.account.retrieve(function(err, account) {}); + it('Sends the correct request with a callback', () => { + stripe.account.retrieve((err, account) => {}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: '/v1/account', @@ -106,9 +106,9 @@ describe('Account Resource', function() { }); }); - describe('External account methods', function() { - describe('retrieveExternalAccount', function() { - it('Sends the correct request', function() { + describe('External account methods', () => { + describe('retrieveExternalAccount', () => { + it('Sends the correct request', () => { stripe.account.retrieveExternalAccount( 'accountIdFoo321', 'externalAccountIdFoo456' @@ -122,7 +122,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.retrieveExternalAccount( 'accountIdFoo321', 'externalAccountIdFoo456', @@ -139,8 +139,8 @@ describe('Account Resource', function() { }); }); - describe('createExternalAccount', function() { - it('Sends the correct request', function() { + describe('createExternalAccount', () => { + it('Sends the correct request', () => { stripe.account.createExternalAccount('accountIdFoo321', { number: '123456', currency: 'usd', @@ -154,7 +154,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.createExternalAccount( 'accountIdFoo321', { @@ -174,8 +174,8 @@ describe('Account Resource', function() { }); }); - describe('updateExternalAccount', function() { - it('Sends the correct request', function() { + describe('updateExternalAccount', () => { + it('Sends the correct request', () => { stripe.account.updateExternalAccount( 'accountIdFoo321', 'externalAccountIdFoo456', @@ -193,8 +193,8 @@ describe('Account Resource', function() { }); }); - describe('deleteExternalAccount', function() { - it('Sends the correct request', function() { + describe('deleteExternalAccount', () => { + it('Sends the correct request', () => { stripe.account.deleteExternalAccount( 'accountIdFoo321', 'externalAccountIdFoo456' @@ -208,7 +208,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.deleteExternalAccount( 'accountIdFoo321', 'externalAccountIdFoo456', @@ -225,8 +225,8 @@ describe('Account Resource', function() { }); }); - describe('listExternalAccounts', function() { - it('Sends the correct request', function() { + describe('listExternalAccounts', () => { + it('Sends the correct request', () => { stripe.account.listExternalAccounts('accountIdFoo321'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -236,7 +236,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.listExternalAccounts('accountIdFoo321', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -249,9 +249,9 @@ describe('Account Resource', function() { }); }); - describe('LoginLink methods', function() { - describe('createLoginLink', function() { - it('Sends the correct request', function() { + describe('LoginLink methods', () => { + describe('createLoginLink', () => { + it('Sends the correct request', () => { stripe.account.createLoginLink('acct_EXPRESS'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -263,9 +263,9 @@ describe('Account Resource', function() { }); }); - describe('Person methods', function() { - describe('retrievePerson', function() { - it('Sends the correct request', function() { + describe('Person methods', () => { + describe('retrievePerson', () => { + it('Sends the correct request', () => { stripe.account.retrievePerson('acct_123', 'person_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -275,7 +275,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.retrievePerson('acct_123', 'person_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -287,8 +287,8 @@ describe('Account Resource', function() { }); }); - describe('createPerson', function() { - it('Sends the correct request', function() { + describe('createPerson', () => { + it('Sends the correct request', () => { stripe.account.createPerson('acct_123', { first_name: 'John', }); @@ -300,7 +300,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.createPerson( 'acct_123', { @@ -318,8 +318,8 @@ describe('Account Resource', function() { }); }); - describe('updatePerson', function() { - it('Sends the correct request', function() { + describe('updatePerson', () => { + it('Sends the correct request', () => { stripe.account.updatePerson('acct_123', 'person_123', { first_name: 'John', }); @@ -331,7 +331,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.updatePerson( 'acct_123', 'person_123', @@ -350,8 +350,8 @@ describe('Account Resource', function() { }); }); - describe('deletePerson', function() { - it('Sends the correct request', function() { + describe('deletePerson', () => { + it('Sends the correct request', () => { stripe.account.deletePerson('acct_123', 'person_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -361,7 +361,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.deletePerson('acct_123', 'person_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -373,8 +373,8 @@ describe('Account Resource', function() { }); }); - describe('listPersons', function() { - it('Sends the correct request', function() { + describe('listPersons', () => { + it('Sends the correct request', () => { stripe.account.listPersons('acct_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -384,7 +384,7 @@ describe('Account Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.account.listPersons('acct_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/AccountLinks.spec.js b/test/resources/AccountLinks.spec.js index 74dfe1caef..bd42414fcd 100644 --- a/test/resources/AccountLinks.spec.js +++ b/test/resources/AccountLinks.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('AccountLinks Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { +describe('AccountLinks Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { stripe.accountLinks.create({ account: 'acct_123', failure_url: 'https://stripe.com/failure', diff --git a/test/resources/ApplePayDomains.spec.js b/test/resources/ApplePayDomains.spec.js index 106e3fd9fd..38fd741849 100644 --- a/test/resources/ApplePayDomains.spec.js +++ b/test/resources/ApplePayDomains.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('ApplePayDomains Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('ApplePayDomains Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.applePayDomains.retrieve('apwc_retrieve'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('ApplePayDomains Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.applePayDomains.del('apwc_delete'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -28,8 +28,8 @@ describe('ApplePayDomains Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.applePayDomains.create({ domain_name: 'example.com', }); @@ -45,8 +45,8 @@ describe('ApplePayDomains Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.applePayDomains.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/ApplicationFeeRefunds.spec.js b/test/resources/ApplicationFeeRefunds.spec.js index 8f97d8db0e..75be78aa2e 100644 --- a/test/resources/ApplicationFeeRefunds.spec.js +++ b/test/resources/ApplicationFeeRefunds.spec.js @@ -1,61 +1,53 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var APPFEE_TEST_ID = 'appFeeIdTest999'; -var REFUND_TEST_ID = 'refundIdTest999'; +const APPFEE_TEST_ID = 'appFeeIdTest999'; +const REFUND_TEST_ID = 'refundIdTest999'; // Create new CustomerCard instance with pre-filled customerId: -var appFeeRefund = new resources.ApplicationFeeRefunds(stripe, { +const appFeeRefund = new resources.ApplicationFeeRefunds(stripe, { feeId: APPFEE_TEST_ID, }); // Use spy from existing resource: appFeeRefund._request = stripe.customers._request; -describe('ApplicationFeeRefund Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('ApplicationFeeRefund Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { appFeeRefund.retrieve(REFUND_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: - '/v1/application_fees/' + - APPFEE_TEST_ID + - '/refunds/' + - REFUND_TEST_ID, + url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, data: {}, headers: {}, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { appFeeRefund.update(REFUND_TEST_ID, { metadata: {key: 'value'}, }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: - '/v1/application_fees/' + - APPFEE_TEST_ID + - '/refunds/' + - REFUND_TEST_ID, + url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds/${REFUND_TEST_ID}`, data: {metadata: {key: 'value'}}, headers: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { appFeeRefund.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/application_fees/' + APPFEE_TEST_ID + '/refunds', + url: `/v1/application_fees/${APPFEE_TEST_ID}/refunds`, data: {}, headers: {}, }); diff --git a/test/resources/ApplicationFees.spec.js b/test/resources/ApplicationFees.spec.js index 34dbac595e..74487d76df 100644 --- a/test/resources/ApplicationFees.spec.js +++ b/test/resources/ApplicationFees.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('ApplicationFee Resource', function() { - describe('list', function() { - it('Sends the correct request', function() { +describe('ApplicationFee Resource', () => { + describe('list', () => { + it('Sends the correct request', () => { stripe.applicationFees.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('ApplicationFee Resource', function() { }); }); - describe('refund', function() { - it('Sends the correct request', function() { + describe('refund', () => { + it('Sends the correct request', () => { stripe.applicationFees.refund('applicationFeeIdExample3242', { amount: 23, }); @@ -30,8 +30,8 @@ describe('ApplicationFee Resource', function() { }); }); - describe('refunds', function() { - it('Sends the correct update request', function() { + describe('refunds', () => { + it('Sends the correct update request', () => { stripe.applicationFees.updateRefund( 'appFeeIdExample3242', 'refundIdExample2312', @@ -46,7 +46,7 @@ describe('ApplicationFee Resource', function() { }); }); - it('Sends the correct create request', function() { + it('Sends the correct create request', () => { stripe.applicationFees.createRefund('appFeeIdExample3242', {amount: 100}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -56,7 +56,7 @@ describe('ApplicationFee Resource', function() { }); }); - it('Sends the correct list request', function() { + it('Sends the correct list request', () => { stripe.applicationFees.listRefunds('appFeeIdExample3242'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -66,7 +66,7 @@ describe('ApplicationFee Resource', function() { }); }); - it('Sends the correct retrieve request', function() { + it('Sends the correct retrieve request', () => { stripe.applicationFees.retrieveRefund( 'appFeeIdExample3242', 'refundIdExample2312' diff --git a/test/resources/Balance.spec.js b/test/resources/Balance.spec.js index 4951f9e151..c1e8a3f686 100644 --- a/test/resources/Balance.spec.js +++ b/test/resources/Balance.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Balance Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Balance Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.balance.retrieve(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -15,7 +15,7 @@ describe('Balance Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.balance.retrieve('aGN0bIwXnHdw5645VABjPdSn8nWY7G11'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -27,8 +27,8 @@ describe('Balance Resource', function() { }); }); - describe('listTransactions', function() { - it('Sends the correct request', function() { + describe('listTransactions', () => { + it('Sends the correct request', () => { stripe.balance.listTransactions(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -38,7 +38,7 @@ describe('Balance Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.balance.listTransactions('aGN0bIwXnHdw5645VABjPdSn8nWY7G11'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -50,8 +50,8 @@ describe('Balance Resource', function() { }); }); - describe('retrieveTransaction', function() { - it('Sends the correct request', function() { + describe('retrieveTransaction', () => { + it('Sends the correct request', () => { stripe.balance.retrieveTransaction('transactionIdFoo'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -61,7 +61,7 @@ describe('Balance Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.balance.retrieveTransaction( 'transactionIdFoo', 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11' diff --git a/test/resources/BitcoinReceivers.spec.js b/test/resources/BitcoinReceivers.spec.js index ada4e055db..494840c17a 100644 --- a/test/resources/BitcoinReceivers.spec.js +++ b/test/resources/BitcoinReceivers.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('BitcoinReceivers Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('BitcoinReceivers Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.bitcoinReceivers.retrieve('receiverId1'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('BitcoinReceivers Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.bitcoinReceivers.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -28,8 +28,8 @@ describe('BitcoinReceivers Resource', function() { }); }); - describe('listTransactions', function() { - it('Sends the correct request', function() { + describe('listTransactions', () => { + it('Sends the correct request', () => { stripe.bitcoinReceivers.listTransactions('receiverId', { limit: 1, }); diff --git a/test/resources/ChargeRefunds.spec.js b/test/resources/ChargeRefunds.spec.js index 843930073f..4bba3c1cae 100644 --- a/test/resources/ChargeRefunds.spec.js +++ b/test/resources/ChargeRefunds.spec.js @@ -1,67 +1,67 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var CHARGE_TEST_ID = 'chargeIdTest999'; -var REFUND_TEST_ID = 'refundIdTest999'; +const CHARGE_TEST_ID = 'chargeIdTest999'; +const REFUND_TEST_ID = 'refundIdTest999'; // Create new CustomerCard instance with pre-filled customerId: -var chargeRefund = new resources.ChargeRefunds(stripe, { +const chargeRefund = new resources.ChargeRefunds(stripe, { chargeId: CHARGE_TEST_ID, }); // Use spy from existing resource: chargeRefund._request = stripe.customers._request; -describe('ChargeRefund Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('ChargeRefund Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { chargeRefund.retrieve(REFUND_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/charges/' + CHARGE_TEST_ID + '/refunds/' + REFUND_TEST_ID, + url: `/v1/charges/${CHARGE_TEST_ID}/refunds/${REFUND_TEST_ID}`, data: {}, headers: {}, }); }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { chargeRefund.create({ amount: 100, }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/charges/' + CHARGE_TEST_ID + '/refunds', + url: `/v1/charges/${CHARGE_TEST_ID}/refunds`, data: {amount: 100}, headers: {}, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { chargeRefund.update(REFUND_TEST_ID, { metadata: {key: 'value'}, }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/charges/' + CHARGE_TEST_ID + '/refunds/' + REFUND_TEST_ID, + url: `/v1/charges/${CHARGE_TEST_ID}/refunds/${REFUND_TEST_ID}`, data: {metadata: {key: 'value'}}, headers: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { chargeRefund.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/charges/' + CHARGE_TEST_ID + '/refunds', + url: `/v1/charges/${CHARGE_TEST_ID}/refunds`, data: {}, headers: {}, }); diff --git a/test/resources/Charges.spec.js b/test/resources/Charges.spec.js index dc68e835bf..f0c82a4362 100644 --- a/test/resources/Charges.spec.js +++ b/test/resources/Charges.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Charge Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Charge Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.charges.retrieve('chargeIdFoo123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Charge Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.charges.create({ amount: '1500', currency: 'usd', @@ -44,8 +44,8 @@ describe('Charge Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.charges.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -56,8 +56,8 @@ describe('Charge Resource', function() { }); }); - describe('capture', function() { - it('Sends the correct request', function() { + describe('capture', () => { + it('Sends the correct request', () => { stripe.charges.capture('chargeIdExample3242', {amount: 23}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -68,8 +68,8 @@ describe('Charge Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.charges.update('chargeIdExample3242', {description: 'foo321'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -80,8 +80,8 @@ describe('Charge Resource', function() { }); }); - describe('refund', function() { - it('Sends the correct request', function() { + describe('refund', () => { + it('Sends the correct request', () => { stripe.charges.refund('chargeIdExample3242', {amount: 23}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -91,7 +91,7 @@ describe('Charge Resource', function() { }); }); - it('Incorrect arguments result in an error', function() { + it('Incorrect arguments result in an error', () => { expect( stripe.charges.refund('chargeIdExample123', 39392) ).to.be.eventually.rejectedWith(/unknown arguments/i); @@ -106,8 +106,8 @@ describe('Charge Resource', function() { }); }); - describe('refunds', function() { - it('Sends the correct update request', function() { + describe('refunds', () => { + it('Sends the correct update request', () => { stripe.charges.updateRefund( 'chargeIdExample3242', 'refundIdExample2312', @@ -121,7 +121,7 @@ describe('Charge Resource', function() { }); }); - it('Sends the correct create request', function() { + it('Sends the correct create request', () => { stripe.charges.createRefund('chargeIdExample3242', {amount: 100}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -131,7 +131,7 @@ describe('Charge Resource', function() { }); }); - it('Sends the correct list request', function() { + it('Sends the correct list request', () => { stripe.charges.listRefunds('chargeIdExample3242'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -141,7 +141,7 @@ describe('Charge Resource', function() { }); }); - it('Sends the correct retrieve request', function() { + it('Sends the correct retrieve request', () => { stripe.charges.retrieveRefund( 'chargeIdExample3242', 'refundIdExample2312' @@ -155,8 +155,8 @@ describe('Charge Resource', function() { }); }); - describe('updateDispute', function() { - it('Sends the correct request', function() { + describe('updateDispute', () => { + it('Sends the correct request', () => { stripe.charges.updateDispute('chargeIdExample3242', {evidence: 'foo'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -167,8 +167,8 @@ describe('Charge Resource', function() { }); }); - describe('closeDispute', function() { - it('Sends the correct request', function() { + describe('closeDispute', () => { + it('Sends the correct request', () => { stripe.charges.closeDispute('chargeIdExample3242', {}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -179,8 +179,8 @@ describe('Charge Resource', function() { }); }); - describe('markAsFraudulent', function() { - it('Sends the correct request', function() { + describe('markAsFraudulent', () => { + it('Sends the correct request', () => { stripe.charges.markAsFraudulent('chargeIdExample3242'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -191,8 +191,8 @@ describe('Charge Resource', function() { }); }); - describe('markAsSafe', function() { - it('Sends the correct request', function() { + describe('markAsSafe', () => { + it('Sends the correct request', () => { stripe.charges.markAsSafe('chargeIdExample3242'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/Checkout/Sessions.spec.js b/test/resources/Checkout/Sessions.spec.js index 1b071806f0..2ab499b94f 100644 --- a/test/resources/Checkout/Sessions.spec.js +++ b/test/resources/Checkout/Sessions.spec.js @@ -1,14 +1,14 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Checkout', function() { - describe('Sessions Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { - var params = { +describe('Checkout', () => { + describe('Sessions Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { + const params = { cancel_url: 'https://stripe.com/cancel', client_reference_id: '1234', line_items: [ @@ -38,8 +38,8 @@ describe('Checkout', function() { }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.checkout.sessions.retrieve('cs_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/CountrySpecs.spec.js b/test/resources/CountrySpecs.spec.js index b896cdb91d..d5f6252aa4 100644 --- a/test/resources/CountrySpecs.spec.js +++ b/test/resources/CountrySpecs.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('CountrySpecs Resource', function() { - describe('list', function() { - it('Sends the correct request', function() { +describe('CountrySpecs Resource', () => { + describe('list', () => { + it('Sends the correct request', () => { stripe.countrySpecs.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,13 +16,13 @@ describe('CountrySpecs Resource', function() { }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { - var country = 'US'; + describe('retrieve', () => { + it('Sends the correct request', () => { + const country = 'US'; stripe.countrySpecs.retrieve(country); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/country_specs/' + country, + url: `/v1/country_specs/${country}`, data: {}, headers: {}, }); diff --git a/test/resources/Coupons.spec.js b/test/resources/Coupons.spec.js index 199845993e..f906a02d79 100644 --- a/test/resources/Coupons.spec.js +++ b/test/resources/Coupons.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Coupons Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Coupons Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.coupons.retrieve('couponId123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Coupons Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.coupons.del('couponId123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -28,8 +28,8 @@ describe('Coupons Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.coupons.update('couponId123', { metadata: {a: '1234'}, }); @@ -44,8 +44,8 @@ describe('Coupons Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.coupons.create({ percent_off: 25, duration: 'repeating', @@ -65,8 +65,8 @@ describe('Coupons Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.coupons.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/CreditNotes.spec.js b/test/resources/CreditNotes.spec.js index b0343e1eca..025e01a176 100644 --- a/test/resources/CreditNotes.spec.js +++ b/test/resources/CreditNotes.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('CreditNotes Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('CreditNotes Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.creditNotes.retrieve('cn_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,9 +16,9 @@ describe('CreditNotes Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { - var data = { + describe('create', () => { + it('Sends the correct request', () => { + const data = { amount: 100, invoice: 'in_123', reason: 'duplicate', @@ -28,13 +28,13 @@ describe('CreditNotes Resource', function() { method: 'POST', url: '/v1/credit_notes', headers: {}, - data: data, + data, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.creditNotes.list({count: 25}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -45,8 +45,8 @@ describe('CreditNotes Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.creditNotes.update('cn_123', {application_fee: 200}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -57,8 +57,8 @@ describe('CreditNotes Resource', function() { }); }); - describe('voidCreditNote', function() { - it('Sends the correct request', function() { + describe('voidCreditNote', () => { + it('Sends the correct request', () => { stripe.creditNotes.voidCreditNote('cn_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/CustomerCards.spec.js b/test/resources/CustomerCards.spec.js index 0354d9fb7e..4a9812f792 100644 --- a/test/resources/CustomerCards.spec.js +++ b/test/resources/CustomerCards.spec.js @@ -1,79 +1,79 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var CUSTOMER_TEST_ID = 'customerIdTest999'; +const CUSTOMER_TEST_ID = 'customerIdTest999'; // Create new CustomerCard instance with pre-filled customerId: -var customerCard = new resources.CustomerCards(stripe, { +const customerCard = new resources.CustomerCards(stripe, { customerId: CUSTOMER_TEST_ID, }); // Use spy from existing resource: customerCard._request = stripe.customers._request; -describe('CustomerCard Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('CustomerCard Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { customerCard.retrieve('cardIdFoo456'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/cards/cardIdFoo456', + url: `/v1/customers/${CUSTOMER_TEST_ID}/cards/cardIdFoo456`, headers: {}, data: {}, }); }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { customerCard.create({ number: '123456', exp_month: '12', }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/cards', + url: `/v1/customers/${CUSTOMER_TEST_ID}/cards`, headers: {}, data: {number: '123456', exp_month: '12'}, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { customerCard.update('cardIdFoo456', { name: 'Bob M. Baz', }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/cards/cardIdFoo456', + url: `/v1/customers/${CUSTOMER_TEST_ID}/cards/cardIdFoo456`, headers: {}, data: {name: 'Bob M. Baz'}, }); }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { customerCard.del('cardIdFoo456'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/cards/cardIdFoo456', + url: `/v1/customers/${CUSTOMER_TEST_ID}/cards/cardIdFoo456`, headers: {}, data: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { customerCard.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/cards', + url: `/v1/customers/${CUSTOMER_TEST_ID}/cards`, headers: {}, data: {}, }); diff --git a/test/resources/CustomerSubscriptions.spec.js b/test/resources/CustomerSubscriptions.spec.js index 6d9b71933e..842902464c 100644 --- a/test/resources/CustomerSubscriptions.spec.js +++ b/test/resources/CustomerSubscriptions.spec.js @@ -1,97 +1,88 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var CUSTOMER_TEST_ID = 'customerIdTest999'; +const CUSTOMER_TEST_ID = 'customerIdTest999'; // Create new CustomerSubscription instance with pre-filled customerId: -var customerSubscription = new resources.CustomerSubscriptions(stripe, { +const customerSubscription = new resources.CustomerSubscriptions(stripe, { customerId: CUSTOMER_TEST_ID, }); // Use spy from existing resource: customerSubscription._request = stripe.customers._request; -describe('CustomerSubscription Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('CustomerSubscription Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { customerSubscription.retrieve('subscriptionIdFoo456'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: - '/v1/customers/' + - CUSTOMER_TEST_ID + - '/subscriptions/subscriptionIdFoo456', + url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions/subscriptionIdFoo456`, headers: {}, data: {}, }); }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { customerSubscription.create({ plan: 'gold', quantity: '12', }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/subscriptions', + url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions`, headers: {}, data: {plan: 'gold', quantity: '12'}, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { customerSubscription.update('subscriptionIdFoo456', { name: 'Bob M. Baz', }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: - '/v1/customers/' + - CUSTOMER_TEST_ID + - '/subscriptions/subscriptionIdFoo456', + url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions/subscriptionIdFoo456`, headers: {}, data: {name: 'Bob M. Baz'}, }); }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { customerSubscription.del('subscriptionIdFoo456'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', - url: - '/v1/customers/' + - CUSTOMER_TEST_ID + - '/subscriptions/subscriptionIdFoo456', + url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions/subscriptionIdFoo456`, headers: {}, data: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { customerSubscription.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/subscriptions', + url: `/v1/customers/${CUSTOMER_TEST_ID}/subscriptions`, headers: {}, data: {}, }); }); }); - describe('Discount methods', function() { - describe('deleteDiscount', function() { - it('Sends the correct request', function() { + describe('Discount methods', () => { + describe('deleteDiscount', () => { + it('Sends the correct request', () => { customerSubscription.deleteDiscount( 'customerIdFoo321', 'subscriptionIdBar654' diff --git a/test/resources/Customers.spec.js b/test/resources/Customers.spec.js index 3193585e12..ee3d0adf3b 100644 --- a/test/resources/Customers.spec.js +++ b/test/resources/Customers.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; +const TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; -describe('Customers Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Customers Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.customers.retrieve('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -17,7 +17,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.retrieve('cus_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -29,8 +29,8 @@ describe('Customers Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.customers.create({description: 'Some customer'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -40,7 +40,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.create({description: 'Some customer'}, TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -51,7 +51,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth and no body]', function() { + it('Sends the correct request [with specified auth and no body]', () => { stripe.customers.create(TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -62,7 +62,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified idempotency_key in options]', function() { + it('Sends the correct request [with specified idempotency_key in options]', () => { stripe.customers.create( {description: 'Some customer'}, {idempotency_key: 'foo'} @@ -75,7 +75,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth in options]', function() { + it('Sends the correct request [with specified auth in options]', () => { stripe.customers.create( {description: 'Some customer'}, {api_key: TEST_AUTH_KEY} @@ -89,7 +89,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth and idempotent key in options]', function() { + it('Sends the correct request [with specified auth and idempotent key in options]', () => { stripe.customers.create( {description: 'Some customer'}, {api_key: TEST_AUTH_KEY, idempotency_key: 'foo'} @@ -103,7 +103,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth in options and no body]', function() { + it('Sends the correct request [with specified auth in options and no body]', () => { stripe.customers.create({api_key: TEST_AUTH_KEY}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -115,8 +115,8 @@ describe('Customers Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.customers.update('cus_123', { description: 'Foo "baz"', }); @@ -129,8 +129,8 @@ describe('Customers Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.customers.del('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -141,8 +141,8 @@ describe('Customers Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.customers.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -152,7 +152,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.list(TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -164,9 +164,9 @@ describe('Customers Resource', function() { }); }); - describe('Subscription methods', function() { - describe('updateSubscription', function() { - it('Sends the correct request', function() { + describe('Subscription methods', () => { + describe('updateSubscription', () => { + it('Sends the correct request', () => { stripe.customers.updateSubscription('cus_123', { plan: 'fooPlan', }); @@ -178,7 +178,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.updateSubscription( 'cus_123', { @@ -196,8 +196,8 @@ describe('Customers Resource', function() { }); }); - describe('cancelSubscription', function() { - it('Sends the correct request', function() { + describe('cancelSubscription', () => { + it('Sends the correct request', () => { stripe.customers.cancelSubscription('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -207,7 +207,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.cancelSubscription('cus_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -218,8 +218,8 @@ describe('Customers Resource', function() { }); }); - describe('With at_period_end defined', function() { - it('Sends the correct request', function() { + describe('With at_period_end defined', () => { + it('Sends the correct request', () => { stripe.customers.cancelSubscription('cus_123', {at_period_end: true}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -230,8 +230,8 @@ describe('Customers Resource', function() { }); }); - describe('With at_period_end defined [with specified auth]', function() { - it('Sends the correct request', function() { + describe('With at_period_end defined [with specified auth]', () => { + it('Sends the correct request', () => { stripe.customers.cancelSubscription( 'cus_123', {at_period_end: true}, @@ -249,9 +249,9 @@ describe('Customers Resource', function() { }); }); - describe('Discount methods', function() { - describe('deleteDiscount', function() { - it('Sends the correct request', function() { + describe('Discount methods', () => { + describe('deleteDiscount', () => { + it('Sends the correct request', () => { stripe.customers.deleteDiscount('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -262,8 +262,8 @@ describe('Customers Resource', function() { }); }); - describe('deleteSubscriptionDiscount', function() { - it('Sends the correct request', function() { + describe('deleteSubscriptionDiscount', () => { + it('Sends the correct request', () => { stripe.customers.deleteSubscriptionDiscount('cus_123', 'sub_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -275,10 +275,10 @@ describe('Customers Resource', function() { }); }); - describe('Metadata methods', function() { - describe('setMetadata', function() { - describe('When deleting metadata', function() { - it('Sends the correct request', function() { + describe('Metadata methods', () => { + describe('setMetadata', () => { + describe('When deleting metadata', () => { + it('Sends the correct request', () => { stripe.customers.setMetadata('cus_123', null); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -291,17 +291,17 @@ describe('Customers Resource', function() { }); }); - describe('When setting new metadata', function() { - it('Sends one request to get current, and another to set new data', function() { - return expect( - new Promise(function(resolve, reject) { + describe('When setting new metadata', () => { + it('Sends one request to get current, and another to set new data', () => + expect( + new Promise((resolve, reject) => { stripe.customers .setMetadata('cus_123', { foo: 123, baz: 456, }) - .then(function() { - var reqs = stripe.REQUESTS; + .then(() => { + const reqs = stripe.REQUESTS; resolve([ // Last two requests reqs[reqs.length - 2], @@ -326,12 +326,11 @@ describe('Customers Resource', function() { metadata: {foo: 123, baz: 456}, }, }, - ]); - }); + ])); }); - describe('When setting with an auth key', function() { - it('Sends the correct request, including the specified auth key', function() { + describe('When setting with an auth key', () => { + it('Sends the correct request, including the specified auth key', () => { stripe.customers.setMetadata('cus_123', null, TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -367,9 +366,9 @@ describe('Customers Resource', function() { }); }); - describe('Card methods', function() { - describe('retrieveCard', function() { - it('Sends the correct request', function() { + describe('Card methods', () => { + describe('retrieveCard', () => { + it('Sends the correct request', () => { stripe.customers.retrieveCard('cus_123', 'card_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -379,7 +378,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.retrieveCard('cus_123', 'card_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -391,8 +390,8 @@ describe('Customers Resource', function() { }); }); - describe('createCard', function() { - it('Sends the correct request', function() { + describe('createCard', () => { + it('Sends the correct request', () => { stripe.customers.createCard('cus_123', { number: '123456', exp_month: '12', @@ -405,7 +404,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.createCard( 'cus_123', { @@ -424,8 +423,8 @@ describe('Customers Resource', function() { }); }); - describe('updateCard', function() { - it('Sends the correct request', function() { + describe('updateCard', () => { + it('Sends the correct request', () => { stripe.customers.updateCard('cus_123', 'card_123', { name: 'Bob M. Baz', }); @@ -438,8 +437,8 @@ describe('Customers Resource', function() { }); }); - describe('deleteCard', function() { - it('Sends the correct request', function() { + describe('deleteCard', () => { + it('Sends the correct request', () => { stripe.customers.deleteCard('cus_123', 'card_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -449,7 +448,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.deleteCard('cus_123', 'card_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -461,8 +460,8 @@ describe('Customers Resource', function() { }); }); - describe('listCards', function() { - it('Sends the correct request', function() { + describe('listCards', () => { + it('Sends the correct request', () => { stripe.customers.listCards('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -472,7 +471,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.listCards('cus_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -485,9 +484,9 @@ describe('Customers Resource', function() { }); }); - describe('Source methods', function() { - describe('retrieveSource', function() { - it('Sends the correct request', function() { + describe('Source methods', () => { + describe('retrieveSource', () => { + it('Sends the correct request', () => { stripe.customers.retrieveSource('cus_123', 'card_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -497,7 +496,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.retrieveSource('cus_123', 'card_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -509,8 +508,8 @@ describe('Customers Resource', function() { }); }); - describe('createSource', function() { - it('Sends the correct request', function() { + describe('createSource', () => { + it('Sends the correct request', () => { stripe.customers.createSource('cus_123', { object: 'card', number: '123456', @@ -524,7 +523,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.createSource( 'cus_123', { @@ -544,8 +543,8 @@ describe('Customers Resource', function() { }); }); - describe('updateSource', function() { - it('Sends the correct request', function() { + describe('updateSource', () => { + it('Sends the correct request', () => { stripe.customers.updateSource('cus_123', 'card_123', { name: 'Bob M. Baz', }); @@ -558,8 +557,8 @@ describe('Customers Resource', function() { }); }); - describe('deleteSource', function() { - it('Sends the correct request', function() { + describe('deleteSource', () => { + it('Sends the correct request', () => { stripe.customers.deleteSource('cus_123', 'card_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -569,7 +568,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.deleteSource('cus_123', 'card_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -581,8 +580,8 @@ describe('Customers Resource', function() { }); }); - describe('listSources', function() { - it('Sends the correct request', function() { + describe('listSources', () => { + it('Sends the correct request', () => { stripe.customers.listSources('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -592,7 +591,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.listSources('cus_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -604,9 +603,9 @@ describe('Customers Resource', function() { }); }); - describe('verifySource', function() { - it('Sends the correct request', function() { - var data = {amounts: [32, 45]}; + describe('verifySource', () => { + it('Sends the correct request', () => { + const data = {amounts: [32, 45]}; stripe.customers.verifySource( 'cus_123', @@ -618,16 +617,16 @@ describe('Customers Resource', function() { method: 'POST', url: '/v1/customers/cus_123/sources/card_123/verify', headers: {}, - data: data, + data, auth: TEST_AUTH_KEY, }); }); }); }); - describe('Subscription methods', function() { - describe('retrieveSubscription', function() { - it('Sends the correct request', function() { + describe('Subscription methods', () => { + describe('retrieveSubscription', () => { + it('Sends the correct request', () => { stripe.customers.retrieveSubscription('cus_123', 'sub_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -637,7 +636,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.retrieveSubscription( 'cus_123', 'sub_123', @@ -653,8 +652,8 @@ describe('Customers Resource', function() { }); }); - describe('createSubscription', function() { - it('Sends the correct request', function() { + describe('createSubscription', () => { + it('Sends the correct request', () => { stripe.customers.createSubscription('cus_123', { plan: 'gold', quantity: '12', @@ -667,7 +666,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.createSubscription( 'cus_123', { @@ -686,8 +685,8 @@ describe('Customers Resource', function() { }); }); - describe('updateSubscription (new-style api)', function() { - it('Sends the correct request', function() { + describe('updateSubscription (new-style api)', () => { + it('Sends the correct request', () => { stripe.customers.updateSubscription('cus_123', 'sub_123', { quantity: '2', }); @@ -699,7 +698,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.updateSubscription( 'cus_123', 'sub_123', @@ -718,8 +717,8 @@ describe('Customers Resource', function() { }); }); - describe('cancelSubscription (new-style api)', function() { - it('Sends the correct request', function() { + describe('cancelSubscription (new-style api)', () => { + it('Sends the correct request', () => { stripe.customers.cancelSubscription('cus_123', 'sub_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -729,7 +728,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.cancelSubscription( 'cus_123', 'sub_123', @@ -744,8 +743,8 @@ describe('Customers Resource', function() { }); }); - describe('With at_period_end defined', function() { - it('Sends the correct request', function() { + describe('With at_period_end defined', () => { + it('Sends the correct request', () => { stripe.customers.cancelSubscription('cus_123', 'sub_123', { at_period_end: true, }); @@ -758,8 +757,8 @@ describe('Customers Resource', function() { }); }); - describe('With at_period_end defined [with specified auth]', function() { - it('Sends the correct request', function() { + describe('With at_period_end defined [with specified auth]', () => { + it('Sends the correct request', () => { stripe.customers.cancelSubscription( 'cus_123', 'sub_123', @@ -777,8 +776,8 @@ describe('Customers Resource', function() { }); }); - describe('listSubscriptions', function() { - it('Sends the correct request', function() { + describe('listSubscriptions', () => { + it('Sends the correct request', () => { stripe.customers.listSubscriptions('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -788,7 +787,7 @@ describe('Customers Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.customers.listSubscriptions('cus_123', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -801,9 +800,9 @@ describe('Customers Resource', function() { }); }); - describe('TaxId methods', function() { - describe('retrieveTaxId', function() { - it('Sends the correct request', function() { + describe('TaxId methods', () => { + describe('retrieveTaxId', () => { + it('Sends the correct request', () => { stripe.customers.retrieveTaxId('cus_123', 'txi_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -814,9 +813,9 @@ describe('Customers Resource', function() { }); }); - describe('createTaxId', function() { - it('Sends the correct request', function() { - var data = { + describe('createTaxId', () => { + it('Sends the correct request', () => { + const data = { type: 'eu_vat', value: '11111', }; @@ -825,13 +824,13 @@ describe('Customers Resource', function() { method: 'POST', url: '/v1/customers/cus_123/tax_ids', headers: {}, - data: data, + data, }); }); }); - describe('deleteTaxId', function() { - it('Sends the correct request', function() { + describe('deleteTaxId', () => { + it('Sends the correct request', () => { stripe.customers.deleteTaxId('cus_123', 'txi_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -842,8 +841,8 @@ describe('Customers Resource', function() { }); }); - describe('listTaxIds', function() { - it('Sends the correct request', function() { + describe('listTaxIds', () => { + it('Sends the correct request', () => { stripe.customers.listTaxIds('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Disputes.spec.js b/test/resources/Disputes.spec.js index d227adfe3d..6bee3ed7f8 100644 --- a/test/resources/Disputes.spec.js +++ b/test/resources/Disputes.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Dispute Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Dispute Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.disputes.retrieve('dp_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Dispute Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.disputes.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -28,8 +28,8 @@ describe('Dispute Resource', function() { }); }); - describe('close', function() { - it('Sends the correct request', function() { + describe('close', () => { + it('Sends the correct request', () => { stripe.disputes.close('dp_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -40,8 +40,8 @@ describe('Dispute Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.disputes.update('dp_123', {evidence: {customer_name: 'Bob'}}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/EphemeralKeys.spec.js b/test/resources/EphemeralKeys.spec.js index 565a066186..1a5a2ca171 100644 --- a/test/resources/EphemeralKeys.spec.js +++ b/test/resources/EphemeralKeys.spec.js @@ -1,7 +1,7 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; function errorsOnNoStripeVersion() { return expect( @@ -27,9 +27,9 @@ function sendsCorrectStripeVersion() { }); } -describe('EphemeralKey Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { +describe('EphemeralKey Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { stripe.ephemeralKeys.create( {customer: 'cus_123'}, {stripe_version: '2017-05-25'} @@ -46,7 +46,7 @@ describe('EphemeralKey Resource', function() { }); }); - describe('when an api version is set', function() { + describe('when an api version is set', () => { beforeEach(function() { this.oldVersion = stripe.getApiField('version'); stripe.setApiVersion('2017-05-25'); @@ -56,16 +56,15 @@ describe('EphemeralKey Resource', function() { stripe.setApiVersion(this.oldVersion); }); - it('Errors if no stripe-version is specified', function() { - return errorsOnNoStripeVersion(); - }); + it('Errors if no stripe-version is specified', () => + errorsOnNoStripeVersion()); - it('Sends the correct stripe-version', function() { + it('Sends the correct stripe-version', () => { sendsCorrectStripeVersion(); }); }); - describe('when no api version is set', function() { + describe('when no api version is set', () => { beforeEach(function() { this.oldVersion = stripe.getApiField('version'); stripe.setApiVersion(null); @@ -75,18 +74,17 @@ describe('EphemeralKey Resource', function() { stripe.setApiVersion(this.oldVersion); }); - it('Errors if no stripe-version is specified', function() { - return errorsOnNoStripeVersion(); - }); + it('Errors if no stripe-version is specified', () => + errorsOnNoStripeVersion()); - it('Sends the correct stripe-version', function() { + it('Sends the correct stripe-version', () => { sendsCorrectStripeVersion(); }); }); }); - describe('delete', function() { - it('Sends the correct request', function() { + describe('delete', () => { + it('Sends the correct request', () => { stripe.ephemeralKeys.del('ephkey_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', diff --git a/test/resources/Events.spec.js b/test/resources/Events.spec.js index c5e77fdfdb..28fbe98ed4 100644 --- a/test/resources/Events.spec.js +++ b/test/resources/Events.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Events Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Events Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.events.retrieve('eventIdBaz'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Events Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.events.list({count: 25}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/ExchangeRates.spec.js b/test/resources/ExchangeRates.spec.js index 9f7108b77f..233119cd57 100644 --- a/test/resources/ExchangeRates.spec.js +++ b/test/resources/ExchangeRates.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('ExchangeRates Resource', function() { - describe('list', function() { - it('Sends the correct request', function() { +describe('ExchangeRates Resource', () => { + describe('list', () => { + it('Sends the correct request', () => { stripe.exchangeRates.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,13 +16,13 @@ describe('ExchangeRates Resource', function() { }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { - var currency = 'USD'; + describe('retrieve', () => { + it('Sends the correct request', () => { + const currency = 'USD'; stripe.exchangeRates.retrieve(currency); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/exchange_rates/' + currency, + url: `/v1/exchange_rates/${currency}`, data: {}, headers: {}, }); diff --git a/test/resources/FileLinks.spec.js b/test/resources/FileLinks.spec.js index 8bf6677b21..1071d22ec0 100644 --- a/test/resources/FileLinks.spec.js +++ b/test/resources/FileLinks.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('FileLinks Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('FileLinks Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.fileLinks.retrieve('link_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('FileLinks Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.fileLinks.create({file: 'file_123'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -28,8 +28,8 @@ describe('FileLinks Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.fileLinks.update('link_123', {metadata: {key: 'value'}}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -40,8 +40,8 @@ describe('FileLinks Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.fileLinks.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/FileUploads.spec.js b/test/resources/FileUploads.spec.js index 1a846356be..06669b84ed 100644 --- a/test/resources/FileUploads.spec.js +++ b/test/resources/FileUploads.spec.js @@ -1,15 +1,15 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; -var fs = require('fs'); -var path = require('path'); +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; +const fs = require('fs'); +const path = require('path'); -var TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; +const TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; -describe('File Uploads Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('File Uploads Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.fileUploads.retrieve('fil_12345'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -19,7 +19,7 @@ describe('File Uploads Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.fileUploads.retrieve('fil_12345', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -31,8 +31,8 @@ describe('File Uploads Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.fileUploads.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -43,10 +43,10 @@ describe('File Uploads Resource', function() { }); }); - describe('create', function() { - it('Sends the correct file upload request', function() { - var testFilename = path.join(__dirname, 'data/minimal.pdf'); - var f = fs.readFileSync(testFilename); + describe('create', () => { + it('Sends the correct file upload request', () => { + const testFilename = path.join(__dirname, 'data/minimal.pdf'); + const f = fs.readFileSync(testFilename); stripe.fileUploads.create({ purpose: 'dispute_evidence', @@ -63,9 +63,9 @@ describe('File Uploads Resource', function() { expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); }); - it('Sends the correct file upload request [with specified auth]', function() { - var testFilename = path.join(__dirname, 'data/minimal.pdf'); - var f = fs.readFileSync(testFilename); + it('Sends the correct file upload request [with specified auth]', () => { + const testFilename = path.join(__dirname, 'data/minimal.pdf'); + const f = fs.readFileSync(testFilename); stripe.fileUploads.create( { @@ -86,9 +86,9 @@ describe('File Uploads Resource', function() { expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); }); - it('Streams a file and sends the correct file upload request', function() { - var testFilename = path.join(__dirname, 'data/minimal.pdf'); - var f = fs.createReadStream(testFilename); + it('Streams a file and sends the correct file upload request', () => { + const testFilename = path.join(__dirname, 'data/minimal.pdf'); + const f = fs.createReadStream(testFilename); return stripe.fileUploads .create({ @@ -100,7 +100,7 @@ describe('File Uploads Resource', function() { }, file_link_data: {create: true}, }) - .then(function() { + .then(() => { expect(stripe.LAST_REQUEST).to.deep.property( 'host', 'files.stripe.com' @@ -110,9 +110,9 @@ describe('File Uploads Resource', function() { }); }); - it('Streams a file and sends the correct file upload request [with specified auth]', function() { - var testFilename = path.join(__dirname, 'data/minimal.pdf'); - var f = fs.createReadStream(testFilename); + it('Streams a file and sends the correct file upload request [with specified auth]', () => { + const testFilename = path.join(__dirname, 'data/minimal.pdf'); + const f = fs.createReadStream(testFilename); return stripe.fileUploads .create( @@ -127,7 +127,7 @@ describe('File Uploads Resource', function() { }, TEST_AUTH_KEY ) - .then(function() { + .then(() => { expect(stripe.LAST_REQUEST).to.deep.property( 'host', 'files.stripe.com' diff --git a/test/resources/Files.spec.js b/test/resources/Files.spec.js index 280eec92c1..52487ffe07 100644 --- a/test/resources/Files.spec.js +++ b/test/resources/Files.spec.js @@ -1,15 +1,15 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; -var fs = require('fs'); -var path = require('path'); +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; +const fs = require('fs'); +const path = require('path'); -var TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; +const TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; -describe('Files Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Files Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.files.retrieve('fil_12345'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -19,7 +19,7 @@ describe('Files Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.files.retrieve('fil_12345', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -31,8 +31,8 @@ describe('Files Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.files.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -43,10 +43,10 @@ describe('Files Resource', function() { }); }); - describe('create', function() { - it('Sends the correct file upload request', function() { - var testFilename = path.join(__dirname, 'data/minimal.pdf'); - var f = fs.readFileSync(testFilename); + describe('create', () => { + it('Sends the correct file upload request', () => { + const testFilename = path.join(__dirname, 'data/minimal.pdf'); + const f = fs.readFileSync(testFilename); stripe.files.create({ purpose: 'dispute_evidence', @@ -63,9 +63,9 @@ describe('Files Resource', function() { expect(stripe.LAST_REQUEST).to.deep.property('url', '/v1/files'); }); - it('Sends the correct file upload request [with specified auth]', function() { - var testFilename = path.join(__dirname, 'data/minimal.pdf'); - var f = fs.readFileSync(testFilename); + it('Sends the correct file upload request [with specified auth]', () => { + const testFilename = path.join(__dirname, 'data/minimal.pdf'); + const f = fs.readFileSync(testFilename); stripe.files.create( { @@ -86,9 +86,9 @@ describe('Files Resource', function() { expect(stripe.LAST_REQUEST).to.deep.property('auth', TEST_AUTH_KEY); }); - it('Streams a file and sends the correct file upload request', function() { - var testFilename = path.join(__dirname, 'data/minimal.pdf'); - var f = fs.createReadStream(testFilename); + it('Streams a file and sends the correct file upload request', () => { + const testFilename = path.join(__dirname, 'data/minimal.pdf'); + const f = fs.createReadStream(testFilename); return stripe.files .create({ @@ -100,7 +100,7 @@ describe('Files Resource', function() { }, file_link_data: {create: true}, }) - .then(function() { + .then(() => { expect(stripe.LAST_REQUEST).to.deep.property( 'host', 'files.stripe.com' @@ -110,9 +110,9 @@ describe('Files Resource', function() { }); }); - it('Streams a file and sends the correct file upload request [with specified auth]', function() { - var testFilename = path.join(__dirname, 'data/minimal.pdf'); - var f = fs.createReadStream(testFilename); + it('Streams a file and sends the correct file upload request [with specified auth]', () => { + const testFilename = path.join(__dirname, 'data/minimal.pdf'); + const f = fs.createReadStream(testFilename); return stripe.files .create( @@ -127,7 +127,7 @@ describe('Files Resource', function() { }, TEST_AUTH_KEY ) - .then(function() { + .then(() => { expect(stripe.LAST_REQUEST).to.deep.property( 'host', 'files.stripe.com' diff --git a/test/resources/InvoiceItems.spec.js b/test/resources/InvoiceItems.spec.js index 6a6352968a..61de4fd338 100644 --- a/test/resources/InvoiceItems.spec.js +++ b/test/resources/InvoiceItems.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('InvoiceItems Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('InvoiceItems Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.invoiceItems.retrieve('invoiceItemIdTesting123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('InvoiceItems Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.invoiceItems.create({ customer: 'cust_id_888', }); @@ -30,8 +30,8 @@ describe('InvoiceItems Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.invoiceItems.update('invoiceItemId1', { amount: 1900, }); @@ -44,8 +44,8 @@ describe('InvoiceItems Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.invoiceItems.del('invoiceItemId2'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -56,8 +56,8 @@ describe('InvoiceItems Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.invoiceItems.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Invoices.spec.js b/test/resources/Invoices.spec.js index cfd8657b2d..b6598d8c38 100644 --- a/test/resources/Invoices.spec.js +++ b/test/resources/Invoices.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Invoices Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Invoices Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.invoices.retrieve('in_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Invoices Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.invoices.create({application_fee: 111}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -28,8 +28,8 @@ describe('Invoices Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.invoices.list({count: 25}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -40,8 +40,8 @@ describe('Invoices Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.invoices.update('in_123', {application_fee: 200}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -52,8 +52,8 @@ describe('Invoices Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.invoices.del('in_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -64,8 +64,8 @@ describe('Invoices Resource', function() { }); }); - describe('retrieveLines', function() { - it('Sends the correct request', function() { + describe('retrieveLines', () => { + it('Sends the correct request', () => { stripe.invoices.retrieveLines('in_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -76,9 +76,9 @@ describe('Invoices Resource', function() { }); }); - describe('retrieveUpcoming', function() { - describe('With just a customer ID', function() { - it('Sends the correct request', function() { + describe('retrieveUpcoming', () => { + describe('With just a customer ID', () => { + it('Sends the correct request', () => { stripe.invoices.retrieveUpcoming('cus_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -89,8 +89,8 @@ describe('Invoices Resource', function() { }); }); - describe('With a subscription ID in addition to a customer ID', function() { - it('Sends the correct request', function() { + describe('With a subscription ID in addition to a customer ID', () => { + it('Sends the correct request', () => { stripe.invoices.retrieveUpcoming('cus_123', 'sub_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -101,8 +101,8 @@ describe('Invoices Resource', function() { }); }); - describe('With an options object that includes `subscription_items`', function() { - it('Sends the correct request', function() { + describe('With an options object that includes `subscription_items`', () => { + it('Sends the correct request', () => { stripe.invoices.retrieveUpcoming('cus_123', { subscription_items: [{plan: 'potato'}, {plan: 'rutabaga'}], }); @@ -118,8 +118,8 @@ describe('Invoices Resource', function() { }); }); - describe('Without a customer id but options', function() { - it('Sends the correct request', function() { + describe('Without a customer id but options', () => { + it('Sends the correct request', () => { stripe.invoices.retrieveUpcoming({ customer: 'cus_abc', subscription_items: [{plan: 'potato'}, {plan: 'rutabaga'}], @@ -136,8 +136,8 @@ describe('Invoices Resource', function() { }); }); - describe('With an options object that includes `subscription_items` in addition to a subscription ID', function() { - it('Sends the correct request', function() { + describe('With an options object that includes `subscription_items` in addition to a subscription ID', () => { + it('Sends the correct request', () => { stripe.invoices.retrieveUpcoming('cus_123', 'sub_123', { subscription_items: [ {plan: 'potato'}, @@ -163,8 +163,8 @@ describe('Invoices Resource', function() { }); }); - describe('With a options object in addition to a customer ID', function() { - it('Sends the correct request', function() { + describe('With a options object in addition to a customer ID', () => { + it('Sends the correct request', () => { stripe.invoices.retrieveUpcoming('cus_123', {plan: 'planId123'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -176,8 +176,8 @@ describe('Invoices Resource', function() { }); }); - describe('finalizeInvoice', function() { - it('Sends the correct request', function() { + describe('finalizeInvoice', () => { + it('Sends the correct request', () => { stripe.invoices.finalizeInvoice('in_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -188,8 +188,8 @@ describe('Invoices Resource', function() { }); }); - describe('mark uncollectible', function() { - it('Sends the correct request', function() { + describe('mark uncollectible', () => { + it('Sends the correct request', () => { stripe.invoices.markUncollectible('in_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -200,8 +200,8 @@ describe('Invoices Resource', function() { }); }); - describe('pay', function() { - it('Sends the correct request', function() { + describe('pay', () => { + it('Sends the correct request', () => { stripe.invoices.pay('in_123', { source: 'tok_FooBar', }); @@ -214,8 +214,8 @@ describe('Invoices Resource', function() { }); }); - describe('sendInvoice', function() { - it('Sends the correct request', function() { + describe('sendInvoice', () => { + it('Sends the correct request', () => { stripe.invoices.sendInvoice('in_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -226,8 +226,8 @@ describe('Invoices Resource', function() { }); }); - describe('voidInvoice', function() { - it('Sends the correct request', function() { + describe('voidInvoice', () => { + it('Sends the correct request', () => { stripe.invoices.voidInvoice('in_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/IssuerFraudRecords.spec.js b/test/resources/IssuerFraudRecords.spec.js index 46842348c7..6a4bd87265 100644 --- a/test/resources/IssuerFraudRecords.spec.js +++ b/test/resources/IssuerFraudRecords.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('IssuerFraudRecord Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('IssuerFraudRecord Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.issuerFraudRecords.retrieve('issfr_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('IssuerFraudRecord Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.issuerFraudRecords.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Issuing/Authorization.spec.js b/test/resources/Issuing/Authorization.spec.js index bb3e3d5d01..e58774d59f 100644 --- a/test/resources/Issuing/Authorization.spec.js +++ b/test/resources/Issuing/Authorization.spec.js @@ -1,12 +1,12 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Issuing', function() { - describe('Authorization Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Issuing', () => { + describe('Authorization Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.issuing.authorizations.retrieve('iauth_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -17,8 +17,8 @@ describe('Issuing', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.issuing.authorizations.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -29,8 +29,8 @@ describe('Issuing', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.issuing.authorizations.update('iauth_123', { metadata: { thing1: true, @@ -51,8 +51,8 @@ describe('Issuing', function() { }); }); - describe('approve', function() { - it('Sends the correct request', function() { + describe('approve', () => { + it('Sends the correct request', () => { stripe.issuing.authorizations.approve('iauth_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -63,8 +63,8 @@ describe('Issuing', function() { }); }); - describe('decline', function() { - it('Sends the correct request', function() { + describe('decline', () => { + it('Sends the correct request', () => { stripe.issuing.authorizations.decline('iauth_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/Issuing/Cardholders.spec.js b/test/resources/Issuing/Cardholders.spec.js index 646e735c40..16bf3b531b 100644 --- a/test/resources/Issuing/Cardholders.spec.js +++ b/test/resources/Issuing/Cardholders.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Issuing', function() { - describe('Cardholders Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Issuing', () => { + describe('Cardholders Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.issuing.cardholders.retrieve('ich_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Issuing', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.issuing.cardholders.create({ billing: {}, name: 'Tim Testperson', @@ -39,8 +39,8 @@ describe('Issuing', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.issuing.cardholders.update('ich_123', { metadata: { thing1: true, @@ -61,8 +61,8 @@ describe('Issuing', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.issuing.cardholders.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Issuing/Cards.spec.js b/test/resources/Issuing/Cards.spec.js index 90e8111ff3..551667064b 100644 --- a/test/resources/Issuing/Cards.spec.js +++ b/test/resources/Issuing/Cards.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Issuing', function() { - describe('Cards Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Issuing', () => { + describe('Cards Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.issuing.cards.retrieve('ic_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Issuing', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.issuing.cards.create({ currency: 'usd', type: 'physical', @@ -37,8 +37,8 @@ describe('Issuing', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.issuing.cards.update('ic_123', { metadata: { thing1: true, @@ -59,8 +59,8 @@ describe('Issuing', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.issuing.cards.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -72,9 +72,9 @@ describe('Issuing', function() { }); }); - describe('Virtual Cards Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('Virtual Cards Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.issuing.cards.retrieveDetails('ic_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ diff --git a/test/resources/Issuing/Disputes.spec.js b/test/resources/Issuing/Disputes.spec.js index 2af1f0cd43..4ae2d3ac5a 100644 --- a/test/resources/Issuing/Disputes.spec.js +++ b/test/resources/Issuing/Disputes.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Issuing', function() { - describe('Disputes Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Issuing', () => { + describe('Disputes Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.issuing.disputes.retrieve('idp_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Issuing', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.issuing.disputes.create({ transaction: 'ipi_123', }); @@ -35,8 +35,8 @@ describe('Issuing', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.issuing.disputes.update('idp_123', { metadata: { thing1: true, @@ -57,8 +57,8 @@ describe('Issuing', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.issuing.disputes.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Issuing/Transactions.spec.js b/test/resources/Issuing/Transactions.spec.js index 89e6ffac5f..2fa9854d56 100644 --- a/test/resources/Issuing/Transactions.spec.js +++ b/test/resources/Issuing/Transactions.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Issuing', function() { - describe('Transactions Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Issuing', () => { + describe('Transactions Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.issuing.transactions.retrieve('ipi_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Issuing', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.issuing.transactions.update('ipi_123', { metadata: { thing1: true, @@ -41,8 +41,8 @@ describe('Issuing', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.issuing.transactions.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/LoginLinks.spec.js b/test/resources/LoginLinks.spec.js index f46361259a..f8c6c36183 100644 --- a/test/resources/LoginLinks.spec.js +++ b/test/resources/LoginLinks.spec.js @@ -1,24 +1,24 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var ACCOUNT_ID = 'acct_EXPRESS'; +const ACCOUNT_ID = 'acct_EXPRESS'; // Create new LoginLink instance with pre-filled accountId: -var loginLink = new resources.LoginLinks(stripe, {accountId: ACCOUNT_ID}); +const loginLink = new resources.LoginLinks(stripe, {accountId: ACCOUNT_ID}); // Use spy from existing resource: loginLink._request = stripe.customers._request; -describe('LoginLink Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { +describe('LoginLink Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { loginLink.create(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/accounts/' + ACCOUNT_ID + '/login_links', + url: `/v1/accounts/${ACCOUNT_ID}/login_links`, headers: {}, data: {}, }); diff --git a/test/resources/OAuth.spec.js b/test/resources/OAuth.spec.js index 7db3345309..c04af14f3c 100644 --- a/test/resources/OAuth.spec.js +++ b/test/resources/OAuth.spec.js @@ -1,38 +1,38 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); +const stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; -var URL = require('url'); -var qs = require('qs'); +const expect = require('chai').expect; +const URL = require('url'); +const qs = require('qs'); -describe('OAuth', function() { - describe('authorize', function() { - describe('when a default client_id is set', function() { - beforeEach(function() { +describe('OAuth', () => { + describe('authorize', () => { + describe('when a default client_id is set', () => { + beforeEach(() => { stripe.setClientId('default_client_id'); }); - it('Uses the correct host', function() { - var url = stripe.oauth.authorizeUrl(); + it('Uses the correct host', () => { + const url = stripe.oauth.authorizeUrl(); - var host = URL.parse(url).hostname; + const host = URL.parse(url).hostname; expect(host).to.equal('connect.stripe.com'); }); - it('Uses the correct path', function() { - var url = stripe.oauth.authorizeUrl({state: 'some_state'}); + it('Uses the correct path', () => { + const url = stripe.oauth.authorizeUrl({state: 'some_state'}); - var pathname = URL.parse(url).pathname; + const pathname = URL.parse(url).pathname; expect(pathname).to.equal('/oauth/authorize'); }); - it('Uses the correct query', function() { - var url = stripe.oauth.authorizeUrl({state: 'some_state'}); + it('Uses the correct query', () => { + const url = stripe.oauth.authorizeUrl({state: 'some_state'}); - var query = qs.parse(URL.parse(url).query); + const query = qs.parse(URL.parse(url).query); expect(query.client_id).to.equal('default_client_id'); expect(query.response_type).to.equal('code'); @@ -40,19 +40,19 @@ describe('OAuth', function() { expect(query.state).to.equal('some_state'); }); - it('Uses a provided client_id instead of the default', function() { - var url = stripe.oauth.authorizeUrl({client_id: '123abc'}); + it('Uses a provided client_id instead of the default', () => { + const url = stripe.oauth.authorizeUrl({client_id: '123abc'}); - var query = qs.parse(URL.parse(url).query); + const query = qs.parse(URL.parse(url).query); expect(query.client_id).to.equal('123abc'); }); - describe('for Express account', function() { - it('Uses the correct path', function() { - var url = stripe.oauth.authorizeUrl({}, {express: true}); + describe('for Express account', () => { + it('Uses the correct path', () => { + const url = stripe.oauth.authorizeUrl({}, {express: true}); - var pathname = URL.parse(url).pathname; + const pathname = URL.parse(url).pathname; expect(pathname).to.equal('/express/oauth/authorize'); }); @@ -60,8 +60,8 @@ describe('OAuth', function() { }); }); - describe('token', function() { - it('Sends the correct request', function() { + describe('token', () => { + it('Sends the correct request', () => { stripe.oauth.token({ code: '123abc', grant_type: 'authorization_code', @@ -80,12 +80,12 @@ describe('OAuth', function() { }); }); - describe('deauthorize', function() { - beforeEach(function() { + describe('deauthorize', () => { + beforeEach(() => { stripe.setClientId('default_client_id'); }); - it('Sends the correct request without explicit client_id', function() { + it('Sends the correct request without explicit client_id', () => { stripe.oauth.deauthorize({ stripe_user_id: 'some_user_id', }); @@ -102,7 +102,7 @@ describe('OAuth', function() { }); }); - it('Sends the correct request with explicit client_id', function() { + it('Sends the correct request with explicit client_id', () => { stripe.oauth.deauthorize({ stripe_user_id: 'some_user_id', client_id: '123abc', diff --git a/test/resources/OrderReturns.spec.js b/test/resources/OrderReturns.spec.js index 2dff709fe9..f39052edb2 100644 --- a/test/resources/OrderReturns.spec.js +++ b/test/resources/OrderReturns.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('OrderReturn Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('OrderReturn Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.orderReturns.retrieve('orderReturnIdFoo123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('OrderReturn Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.orderReturns.list({ limit: 3, }); @@ -31,7 +31,7 @@ describe('OrderReturn Resource', function() { }); }); - it('Supports filtering by order', function() { + it('Supports filtering by order', () => { stripe.orderReturns.list({ order: 'orderIdFoo123', }); diff --git a/test/resources/Orders.spec.js b/test/resources/Orders.spec.js index d0d05de51c..c367271577 100644 --- a/test/resources/Orders.spec.js +++ b/test/resources/Orders.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Order Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Order Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.orders.retrieve('orderIdFoo123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Order Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.orders.create({ currency: 'usd', items: [ @@ -58,8 +58,8 @@ describe('Order Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.orders.list({ limit: 3, }); @@ -73,7 +73,7 @@ describe('Order Resource', function() { }); }); - it('Supports filtering by status', function() { + it('Supports filtering by status', () => { stripe.orders.list({ status: 'active', }); @@ -88,8 +88,8 @@ describe('Order Resource', function() { }); }); - describe('pay', function() { - it('Sends the correct request', function() { + describe('pay', () => { + it('Sends the correct request', () => { stripe.orders.pay('orderIdFoo3242', { source: 'tok_FooBar', }); @@ -102,8 +102,8 @@ describe('Order Resource', function() { }); }); - describe('returnOrder', function() { - it('Sends the correct request', function() { + describe('returnOrder', () => { + it('Sends the correct request', () => { stripe.orders.returnOrder('orderIdFoo3242', { items: [{parent: 'sku_123'}], }); @@ -116,8 +116,8 @@ describe('Order Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.orders.update('orderIdFoo3242', {status: 'fulfilled'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/PaymentIntents.spec.js b/test/resources/PaymentIntents.spec.js index 81f8f2c639..757b900ff5 100644 --- a/test/resources/PaymentIntents.spec.js +++ b/test/resources/PaymentIntents.spec.js @@ -1,14 +1,14 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var PAYMENT_INTENT_TEST_ID = 'pi_123'; +const PAYMENT_INTENT_TEST_ID = 'pi_123'; -describe('Payment Intents Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { - var params = { +describe('Payment Intents Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { + const params = { amount: 200, currency: 'usd', payment_method_types: ['card'], @@ -23,8 +23,8 @@ describe('Payment Intents Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.paymentIntents.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -35,62 +35,62 @@ describe('Payment Intents Resource', function() { }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.paymentIntents.retrieve(PAYMENT_INTENT_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID, + url: `/v1/payment_intents/${PAYMENT_INTENT_TEST_ID}`, headers: {}, data: {}, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.paymentIntents.update(PAYMENT_INTENT_TEST_ID, { metadata: {key: 'value'}, }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID, + url: `/v1/payment_intents/${PAYMENT_INTENT_TEST_ID}`, headers: {}, data: {metadata: {key: 'value'}}, }); }); }); - describe('cancel', function() { - it('Sends the correct request', function() { + describe('cancel', () => { + it('Sends the correct request', () => { stripe.paymentIntents.cancel(PAYMENT_INTENT_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID + '/cancel', + url: `/v1/payment_intents/${PAYMENT_INTENT_TEST_ID}/cancel`, headers: {}, data: {}, }); }); }); - describe('capture', function() { - it('Sends the correct request', function() { + describe('capture', () => { + it('Sends the correct request', () => { stripe.paymentIntents.capture(PAYMENT_INTENT_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID + '/capture', + url: `/v1/payment_intents/${PAYMENT_INTENT_TEST_ID}/capture`, headers: {}, data: {}, }); }); }); - describe('confirm', function() { - it('Sends the correct request', function() { + describe('confirm', () => { + it('Sends the correct request', () => { stripe.paymentIntents.confirm(PAYMENT_INTENT_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/payment_intents/' + PAYMENT_INTENT_TEST_ID + '/confirm', + url: `/v1/payment_intents/${PAYMENT_INTENT_TEST_ID}/confirm`, headers: {}, data: {}, }); diff --git a/test/resources/PaymentMethods.spec.js b/test/resources/PaymentMethods.spec.js index bc395521db..0860c1cb45 100644 --- a/test/resources/PaymentMethods.spec.js +++ b/test/resources/PaymentMethods.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('PaymentMethods Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('PaymentMethods Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.paymentMethods.retrieve('pm_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,9 +16,9 @@ describe('PaymentMethods Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { - var data = { + describe('create', () => { + it('Sends the correct request', () => { + const data = { type: 'card', }; stripe.paymentMethods.create(data); @@ -26,14 +26,14 @@ describe('PaymentMethods Resource', function() { method: 'POST', url: '/v1/payment_methods', headers: {}, - data: data, + data, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { - var data = { + describe('list', () => { + it('Sends the correct request', () => { + const data = { customer: 'cus_123', type: 'card', }; @@ -42,14 +42,14 @@ describe('PaymentMethods Resource', function() { method: 'GET', url: '/v1/payment_methods', headers: {}, - data: data, + data, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { - var data = { + describe('update', () => { + it('Sends the correct request', () => { + const data = { metadata: {key: 'value'}, }; stripe.paymentMethods.update('pm_123', data); @@ -57,13 +57,13 @@ describe('PaymentMethods Resource', function() { method: 'POST', url: '/v1/payment_methods/pm_123', headers: {}, - data: data, + data, }); }); }); - describe('attach', function() { - it('Sends the correct request', function() { + describe('attach', () => { + it('Sends the correct request', () => { stripe.paymentMethods.attach('pm_123', {customer: 'cus_123'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -74,8 +74,8 @@ describe('PaymentMethods Resource', function() { }); }); - describe('detach', function() { - it('Sends the correct request', function() { + describe('detach', () => { + it('Sends the correct request', () => { stripe.paymentMethods.detach('pm_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/Payouts.spec.js b/test/resources/Payouts.spec.js index 8b19252a64..1f1678acae 100644 --- a/test/resources/Payouts.spec.js +++ b/test/resources/Payouts.spec.js @@ -1,25 +1,25 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var PAYOUT_TEST_ID = 'po_testid1'; +const PAYOUT_TEST_ID = 'po_testid1'; -describe('Payouts Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Payouts Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.payouts.retrieve(PAYOUT_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/payouts/' + PAYOUT_TEST_ID, + url: `/v1/payouts/${PAYOUT_TEST_ID}`, headers: {}, data: {}, }); }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.payouts.create({ amount: 200, currency: 'usd', @@ -33,34 +33,34 @@ describe('Payouts Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.payouts.update(PAYOUT_TEST_ID, { metadata: {key: 'value'}, }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/payouts/' + PAYOUT_TEST_ID, + url: `/v1/payouts/${PAYOUT_TEST_ID}`, headers: {}, data: {metadata: {key: 'value'}}, }); }); }); - describe('cancel', function() { - it('Sends the correct request', function() { + describe('cancel', () => { + it('Sends the correct request', () => { stripe.payouts.cancel(PAYOUT_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/payouts/' + PAYOUT_TEST_ID + '/cancel', + url: `/v1/payouts/${PAYOUT_TEST_ID}/cancel`, headers: {}, data: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.payouts.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -71,12 +71,12 @@ describe('Payouts Resource', function() { }); }); - describe('listTransactions', function() { - it('Sends the correct request', function() { + describe('listTransactions', () => { + it('Sends the correct request', () => { stripe.payouts.listTransactions(PAYOUT_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/payouts/' + PAYOUT_TEST_ID + '/transactions', + url: `/v1/payouts/${PAYOUT_TEST_ID}/transactions`, headers: {}, data: {}, }); diff --git a/test/resources/Persons.spec.js b/test/resources/Persons.spec.js index 8d7112dbce..0b199f6715 100644 --- a/test/resources/Persons.spec.js +++ b/test/resources/Persons.spec.js @@ -1,77 +1,77 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var ACCOUNT_TEST_ID = 'acct_123'; -var PERSON_TEST_ID = 'person_123'; +const ACCOUNT_TEST_ID = 'acct_123'; +const PERSON_TEST_ID = 'person_123'; // Create new Person instance with pre-filled accountId: -var person = new resources.Persons(stripe, {accountId: ACCOUNT_TEST_ID}); +const person = new resources.Persons(stripe, {accountId: ACCOUNT_TEST_ID}); // Use spy from existing resource: person._request = stripe.customers._request; -describe('Person Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { +describe('Person Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { person.create({ first_name: 'John', }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/persons', + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, data: {first_name: 'John'}, headers: {}, }); }); }); - describe('delete', function() { - it('Sends the correct request', function() { + describe('delete', () => { + it('Sends the correct request', () => { person.del(PERSON_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', - url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/persons/' + PERSON_TEST_ID, + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, data: {}, headers: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { person.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/persons', + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons`, data: {}, headers: {}, }); }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('retrieve', () => { + it('Sends the correct request', () => { person.retrieve(PERSON_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/persons/' + PERSON_TEST_ID, + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, data: {}, headers: {}, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { person.update(PERSON_TEST_ID, { first_name: 'John', }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/accounts/' + ACCOUNT_TEST_ID + '/persons/' + PERSON_TEST_ID, + url: `/v1/accounts/${ACCOUNT_TEST_ID}/persons/${PERSON_TEST_ID}`, data: {first_name: 'John'}, headers: {}, }); diff --git a/test/resources/Plans.spec.js b/test/resources/Plans.spec.js index 6468c95f46..85f9226fdc 100644 --- a/test/resources/Plans.spec.js +++ b/test/resources/Plans.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Plans Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Plans Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.plans.retrieve('planId1'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Plans Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.plans.create({ amount: 200, currency: 'usd', @@ -30,7 +30,7 @@ describe('Plans Resource', function() { }); }); - it('Sends the correct request for metered', function() { + it('Sends the correct request for metered', () => { stripe.plans.create({ amount: 200, currency: 'usd', @@ -44,7 +44,7 @@ describe('Plans Resource', function() { }); }); - it('Sends the correct request for tiered plans', function() { + it('Sends the correct request for tiered plans', () => { stripe.plans.create({ currency: 'usd', billing_scheme: 'tiered', @@ -64,7 +64,7 @@ describe('Plans Resource', function() { }); }); - it('Sends the correct request for transform usage plans', function() { + it('Sends the correct request for transform usage plans', () => { stripe.plans.create({ amount: 200, currency: 'usd', @@ -83,8 +83,8 @@ describe('Plans Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.plans.update('planId3', { amount: 1900, currency: 'usd', @@ -98,8 +98,8 @@ describe('Plans Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.plans.del('planId4'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -110,8 +110,8 @@ describe('Plans Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.plans.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Products.spec.js b/test/resources/Products.spec.js index 9efb4ec49e..21c6193521 100644 --- a/test/resources/Products.spec.js +++ b/test/resources/Products.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Product Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Product Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.products.retrieve('productIdFoo123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Product Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.products.create({ name: 'Llamas', active: true, @@ -36,8 +36,8 @@ describe('Product Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.products.list({ limit: 3, }); @@ -51,7 +51,7 @@ describe('Product Resource', function() { }); }); - it('Supports filtering by shippable', function() { + it('Supports filtering by shippable', () => { stripe.products.list({ shippable: true, }); @@ -66,8 +66,8 @@ describe('Product Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.products.update('productIdFoo3242', {caption: 'test'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -78,8 +78,8 @@ describe('Product Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.products.del('productIdFoo3242'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', diff --git a/test/resources/Radar/ValueListItems.spec.js b/test/resources/Radar/ValueListItems.spec.js index ee414a1e77..286ef956ba 100644 --- a/test/resources/Radar/ValueListItems.spec.js +++ b/test/resources/Radar/ValueListItems.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Radar', function() { - describe('ValueLists Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Radar', () => { + describe('ValueLists Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.radar.valueListItems.retrieve('rsli_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Radar', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.radar.valueListItems.create({ value_list: 'rsl_123', value: 'value', @@ -37,8 +37,8 @@ describe('Radar', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.radar.valueListItems.list({ value_list: 'rsl_123', }); @@ -53,8 +53,8 @@ describe('Radar', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.radar.valueListItems.del('rsli_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', diff --git a/test/resources/Radar/ValueLists.spec.js b/test/resources/Radar/ValueLists.spec.js index 1acaf6dc53..57c778257e 100644 --- a/test/resources/Radar/ValueLists.spec.js +++ b/test/resources/Radar/ValueLists.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Radar', function() { - describe('ValueLists Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Radar', () => { + describe('ValueLists Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.radar.valueLists.retrieve('rsl_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Radar', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.radar.valueLists.create({ alias: 'alias', name: 'name', @@ -37,8 +37,8 @@ describe('Radar', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.radar.valueLists.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -49,8 +49,8 @@ describe('Radar', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.radar.valueLists.del('rsl_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -61,8 +61,8 @@ describe('Radar', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.radar.valueLists.update('rsl_123', { metadata: {a: '1234'}, }); diff --git a/test/resources/RecipientCards.spec.js b/test/resources/RecipientCards.spec.js index abd4007442..885b974912 100644 --- a/test/resources/RecipientCards.spec.js +++ b/test/resources/RecipientCards.spec.js @@ -1,79 +1,79 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var RECIPIENT_TEST_ID = 'recipientIdTest999'; +const RECIPIENT_TEST_ID = 'recipientIdTest999'; // Create new recipientCard instance with pre-filled recipientId: -var recipientCard = new resources.RecipientCards(stripe, { +const recipientCard = new resources.RecipientCards(stripe, { recipientId: RECIPIENT_TEST_ID, }); // Use spy from existing resource: recipientCard._request = stripe.recipients._request; -describe('RecipientCard Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('RecipientCard Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { recipientCard.retrieve('cardIdFoo456'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/recipients/' + RECIPIENT_TEST_ID + '/cards/cardIdFoo456', + url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards/cardIdFoo456`, headers: {}, data: {}, }); }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { recipientCard.create({ number: '123456', exp_month: '12', }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/recipients/' + RECIPIENT_TEST_ID + '/cards', + url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards`, headers: {}, data: {number: '123456', exp_month: '12'}, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { recipientCard.update('cardIdFoo456', { name: 'Bob M. Baz', }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/recipients/' + RECIPIENT_TEST_ID + '/cards/cardIdFoo456', + url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards/cardIdFoo456`, headers: {}, data: {name: 'Bob M. Baz'}, }); }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { recipientCard.del('cardIdFoo456'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', - url: '/v1/recipients/' + RECIPIENT_TEST_ID + '/cards/cardIdFoo456', + url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards/cardIdFoo456`, headers: {}, data: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { recipientCard.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/recipients/' + RECIPIENT_TEST_ID + '/cards', + url: `/v1/recipients/${RECIPIENT_TEST_ID}/cards`, headers: {}, data: {}, }); diff --git a/test/resources/Recipients.spec.js b/test/resources/Recipients.spec.js index 3c428b1ff5..8ee3f33fe1 100644 --- a/test/resources/Recipients.spec.js +++ b/test/resources/Recipients.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; +const TEST_AUTH_KEY = 'aGN0bIwXnHdw5645VABjPdSn8nWY7G11'; -describe('Recipients Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Recipients Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.recipients.retrieve('recipientId1'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -18,8 +18,8 @@ describe('Recipients Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.recipients.create({ name: 'Bob', type: 'individual', @@ -33,8 +33,8 @@ describe('Recipients Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.recipients.update('recipientId3', { name: 'Bob Smith', }); @@ -47,8 +47,8 @@ describe('Recipients Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.recipients.del('recipientId4'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -59,8 +59,8 @@ describe('Recipients Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.recipients.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -71,9 +71,9 @@ describe('Recipients Resource', function() { }); }); - describe('Card methods', function() { - describe('retrieveCard', function() { - it('Sends the correct request', function() { + describe('Card methods', () => { + describe('retrieveCard', () => { + it('Sends the correct request', () => { stripe.recipients.retrieveCard('recipientIdFoo321', 'cardIdFoo456'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -83,7 +83,7 @@ describe('Recipients Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.recipients.retrieveCard( 'recipientIdFoo321', 'cardIdFoo456', @@ -99,8 +99,8 @@ describe('Recipients Resource', function() { }); }); - describe('createCard', function() { - it('Sends the correct request', function() { + describe('createCard', () => { + it('Sends the correct request', () => { stripe.recipients.createCard('recipientIdFoo321', { number: '123456', exp_month: '12', @@ -113,7 +113,7 @@ describe('Recipients Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.recipients.createCard( 'recipientIdFoo321', { @@ -132,8 +132,8 @@ describe('Recipients Resource', function() { }); }); - describe('updateCard', function() { - it('Sends the correct request', function() { + describe('updateCard', () => { + it('Sends the correct request', () => { stripe.recipients.updateCard('recipientIdFoo321', 'cardIdFoo456', { name: 'Bob M. Baz', }); @@ -146,8 +146,8 @@ describe('Recipients Resource', function() { }); }); - describe('deleteCard', function() { - it('Sends the correct request', function() { + describe('deleteCard', () => { + it('Sends the correct request', () => { stripe.recipients.deleteCard('recipientIdFoo321', 'cardIdFoo456'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -157,7 +157,7 @@ describe('Recipients Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.recipients.deleteCard( 'recipientIdFoo321', 'cardIdFoo456', @@ -173,8 +173,8 @@ describe('Recipients Resource', function() { }); }); - describe('listCards', function() { - it('Sends the correct request', function() { + describe('listCards', () => { + it('Sends the correct request', () => { stripe.recipients.listCards('recipientIdFoo321'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -184,7 +184,7 @@ describe('Recipients Resource', function() { }); }); - it('Sends the correct request [with specified auth]', function() { + it('Sends the correct request [with specified auth]', () => { stripe.recipients.listCards('recipientIdFoo321', TEST_AUTH_KEY); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Refunds.spec.js b/test/resources/Refunds.spec.js index fd8a32b104..843477d149 100644 --- a/test/resources/Refunds.spec.js +++ b/test/resources/Refunds.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Refund Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { +describe('Refund Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { stripe.refunds.create({ amount: '300', charge: 'ch_123', @@ -23,8 +23,8 @@ describe('Refund Resource', function() { }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.refunds.retrieve('re_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -35,8 +35,8 @@ describe('Refund Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.refunds.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -47,8 +47,8 @@ describe('Refund Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.refunds.update('re_123', {metadata: {key: 'abcd'}}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/Reporting/ReportRuns.spec.js b/test/resources/Reporting/ReportRuns.spec.js index a9f04c6692..dd83a00854 100644 --- a/test/resources/Reporting/ReportRuns.spec.js +++ b/test/resources/Reporting/ReportRuns.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Reporting', function() { - describe('ReportRuns Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Reporting', () => { + describe('ReportRuns Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.reporting.reportRuns.retrieve('frr_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Reporting', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.reporting.reportRuns.create({ parameters: { connected_account: 'acct_123', @@ -41,8 +41,8 @@ describe('Reporting', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.reporting.reportRuns.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Reporting/ReportTypes.spec.js b/test/resources/Reporting/ReportTypes.spec.js index a13c2db4b3..37e7bd3134 100644 --- a/test/resources/Reporting/ReportTypes.spec.js +++ b/test/resources/Reporting/ReportTypes.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Reporting', function() { - describe('ReportTypes Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Reporting', () => { + describe('ReportTypes Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.reporting.reportTypes.retrieve('activity.summary.1'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Reporting', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.reporting.reportTypes.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Reviews.spec.js b/test/resources/Reviews.spec.js index 850473afec..03296088aa 100644 --- a/test/resources/Reviews.spec.js +++ b/test/resources/Reviews.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Review Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Review Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.reviews.retrieve('prv_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Review Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.reviews.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -28,8 +28,8 @@ describe('Review Resource', function() { }); }); - describe('approve', function() { - it('Sends the correct request', function() { + describe('approve', () => { + it('Sends the correct request', () => { stripe.reviews.approve('prv_123', {amount: 23}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/SKUs.spec.js b/test/resources/SKUs.spec.js index fc9d1f27e7..5155d8fec8 100644 --- a/test/resources/SKUs.spec.js +++ b/test/resources/SKUs.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('SKU Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('SKU Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.skus.retrieve('skuIdFoo123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('SKU Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.skus.create({ currency: 'usd', inventory: {type: 'finite', quantity: 500}, @@ -40,8 +40,8 @@ describe('SKU Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.skus.list({ limit: 3, }); @@ -55,7 +55,7 @@ describe('SKU Resource', function() { }); }); - it('Supports filtering by product', function() { + it('Supports filtering by product', () => { stripe.skus.list({ product: 'prodId123', }); @@ -70,8 +70,8 @@ describe('SKU Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.skus.update('skuIdFoo3242', {caption: 'test'}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -82,8 +82,8 @@ describe('SKU Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.skus.del('skuIdFoo3242'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', diff --git a/test/resources/Sigma/ScheduledQueryRuns.spec.js b/test/resources/Sigma/ScheduledQueryRuns.spec.js index 857fee694e..710762d8e0 100644 --- a/test/resources/Sigma/ScheduledQueryRuns.spec.js +++ b/test/resources/Sigma/ScheduledQueryRuns.spec.js @@ -1,12 +1,12 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Sigma', function() { - describe('ScheduledQueryRun Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Sigma', () => { + describe('ScheduledQueryRun Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.sigma.scheduledQueryRuns.retrieve('sqr_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -17,8 +17,8 @@ describe('Sigma', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.sigma.scheduledQueryRuns.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Sources.spec.js b/test/resources/Sources.spec.js index 51d7111539..89da485560 100644 --- a/test/resources/Sources.spec.js +++ b/test/resources/Sources.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Sources Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Sources Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.sources.retrieve('sourceId1'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Sources Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.sources.create({ amount: 200, currency: 'usd', @@ -46,8 +46,8 @@ describe('Sources Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.sources.update('src_foo', { metadata: {foo: 'bar'}, }); @@ -60,8 +60,8 @@ describe('Sources Resource', function() { }); }); - describe('listSourceTransactions', function() { - it('Sends the correct request', function() { + describe('listSourceTransactions', () => { + it('Sends the correct request', () => { stripe.sources.listSourceTransactions('src_foo'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -72,8 +72,8 @@ describe('Sources Resource', function() { }); }); - describe('verify', function() { - it('Sends the correct request', function() { + describe('verify', () => { + it('Sends the correct request', () => { stripe.sources.verify('src_foo', {values: [32, 45]}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/SubscriptionItems.spec.js b/test/resources/SubscriptionItems.spec.js index 76b1c598b3..73e59d58c2 100644 --- a/test/resources/SubscriptionItems.spec.js +++ b/test/resources/SubscriptionItems.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('SubscriptionItems Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('SubscriptionItems Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.subscriptionItems.retrieve('test_sub_item'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('SubscriptionItems Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.subscriptionItems.del('test_sub_item'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -28,8 +28,8 @@ describe('SubscriptionItems Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.subscriptionItems.update('test_sub_item', { plan: 'gold', }); @@ -44,8 +44,8 @@ describe('SubscriptionItems Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.subscriptionItems.create({ subscription: 'test_sub', plan: 'gold', @@ -63,8 +63,8 @@ describe('SubscriptionItems Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.subscriptionItems.list({ limit: 3, subscription: 'test_sub', diff --git a/test/resources/SubscriptionSchedule.spec.js b/test/resources/SubscriptionSchedule.spec.js index 9e07b182a2..68107b3382 100644 --- a/test/resources/SubscriptionSchedule.spec.js +++ b/test/resources/SubscriptionSchedule.spec.js @@ -1,44 +1,44 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var SCHEDULE_TEST_ID = 'sub_sched_123'; -var REVISION_TEST_ID = 'sub_sched_rev_123'; +const SCHEDULE_TEST_ID = 'sub_sched_123'; +const REVISION_TEST_ID = 'sub_sched_rev_123'; -describe('Subscription Schedule Resource', function() { - describe('cancel', function() { - it('Sends the correct request', function() { - var data = { +describe('Subscription Schedule Resource', () => { + describe('cancel', () => { + it('Sends the correct request', () => { + const data = { invoice_now: true, }; stripe.subscriptionSchedules.cancel(SCHEDULE_TEST_ID, data); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/cancel', - data: data, + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/cancel`, + data, headers: {}, }); }); }); - describe('create', function() { - it('Sends the correct request', function() { - var data = { + describe('create', () => { + it('Sends the correct request', () => { + const data = { customer: 'cus_123', }; stripe.subscriptionSchedules.create(data); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', url: '/v1/subscription_schedules', - data: data, + data, headers: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.subscriptionSchedules.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -49,23 +49,23 @@ describe('Subscription Schedule Resource', function() { }); }); - describe('release', function() { - it('Sends the correct request', function() { - var data = { + describe('release', () => { + it('Sends the correct request', () => { + const data = { preserve_cancel_date: true, }; stripe.subscriptionSchedules.release(SCHEDULE_TEST_ID, data); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/release', - data: data, + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/release`, + data, headers: {}, }); }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.subscriptionSchedules.retrieve(SCHEDULE_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -76,45 +76,41 @@ describe('Subscription Schedule Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { - var data = {metadata: {key: 'value'}}; + describe('update', () => { + it('Sends the correct request', () => { + const data = {metadata: {key: 'value'}}; stripe.subscriptionSchedules.update(SCHEDULE_TEST_ID, data); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID, - data: data, + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}`, + data, headers: {}, }); }); }); - describe('Revision methods', function() { - describe('retrieveRevision', function() { - it('Sends the correct request', function() { + describe('Revision methods', () => { + describe('retrieveRevision', () => { + it('Sends the correct request', () => { stripe.subscriptionSchedules.retrieveRevision( SCHEDULE_TEST_ID, REVISION_TEST_ID ); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: - '/v1/subscription_schedules/' + - SCHEDULE_TEST_ID + - '/revisions/' + - REVISION_TEST_ID, + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions/${REVISION_TEST_ID}`, headers: {}, data: {}, }); }); }); - describe('listRevisions', function() { - it('Sends the correct request', function() { + describe('listRevisions', () => { + it('Sends the correct request', () => { stripe.subscriptionSchedules.listRevisions(SCHEDULE_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/revisions', + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions`, headers: {}, data: {}, }); diff --git a/test/resources/SubscriptionScheduleRevision.spec.js b/test/resources/SubscriptionScheduleRevision.spec.js index 58adf867cf..4c15320d7a 100644 --- a/test/resources/SubscriptionScheduleRevision.spec.js +++ b/test/resources/SubscriptionScheduleRevision.spec.js @@ -1,43 +1,39 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var SCHEDULE_TEST_ID = 'sub_sched_123'; -var REVISION_TEST_ID = 'sub_sched_rev_123'; +const SCHEDULE_TEST_ID = 'sub_sched_123'; +const REVISION_TEST_ID = 'sub_sched_rev_123'; // Create new SubscriptionScheduleRevision instance with pre-filled scheduleId: -var revision = new resources.SubscriptionScheduleRevisions(stripe, { +const revision = new resources.SubscriptionScheduleRevisions(stripe, { scheduleId: SCHEDULE_TEST_ID, }); // Use spy from existing resource: revision._request = stripe.customers._request; -describe('SubscriptionScheduleRevision Resource', function() { - describe('list', function() { - it('Sends the correct request', function() { +describe('SubscriptionScheduleRevision Resource', () => { + describe('list', () => { + it('Sends the correct request', () => { revision.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/subscription_schedules/' + SCHEDULE_TEST_ID + '/revisions', + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions`, data: {}, headers: {}, }); }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('retrieve', () => { + it('Sends the correct request', () => { revision.retrieve(REVISION_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: - '/v1/subscription_schedules/' + - SCHEDULE_TEST_ID + - '/revisions/' + - REVISION_TEST_ID, + url: `/v1/subscription_schedules/${SCHEDULE_TEST_ID}/revisions/${REVISION_TEST_ID}`, data: {}, headers: {}, }); diff --git a/test/resources/Subscriptions.spec.js b/test/resources/Subscriptions.spec.js index 31b1e876f5..d1f7631295 100644 --- a/test/resources/Subscriptions.spec.js +++ b/test/resources/Subscriptions.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('subscriptions Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('subscriptions Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.subscriptions.retrieve('test_sub'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('subscriptions Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.subscriptions.del('test_sub'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -28,8 +28,8 @@ describe('subscriptions Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.subscriptions.update('test_sub', { metadata: {a: '1234'}, }); @@ -44,8 +44,8 @@ describe('subscriptions Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.subscriptions.create({ customer: 'test_cus', plan: 'gold', @@ -63,8 +63,8 @@ describe('subscriptions Resource', function() { }); }); - describe('update with items array', function() { - it('Sends the correct request', function() { + describe('update with items array', () => { + it('Sends the correct request', () => { stripe.subscriptions.update('test_sub', { items: [ { @@ -89,8 +89,8 @@ describe('subscriptions Resource', function() { }); }); - describe('create with items array', function() { - it('Sends the correct request', function() { + describe('create with items array', () => { + it('Sends the correct request', () => { stripe.subscriptions.create({ items: [ { @@ -116,8 +116,8 @@ describe('subscriptions Resource', function() { }); }); - describe('update with items object', function() { - it('Sends the correct request', function() { + describe('update with items object', () => { + it('Sends the correct request', () => { stripe.subscriptions.update('test_sub', { items: { '0': { @@ -142,8 +142,8 @@ describe('subscriptions Resource', function() { }); }); - describe('create with items object', function() { - it('Sends the correct request', function() { + describe('create with items object', () => { + it('Sends the correct request', () => { stripe.subscriptions.create({ items: { '0': { @@ -169,8 +169,8 @@ describe('subscriptions Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.subscriptions.list({ limit: 3, customer: 'test_cus', @@ -189,9 +189,9 @@ describe('subscriptions Resource', function() { }); }); - describe('Discount methods', function() { - describe('deleteDiscount', function() { - it('Sends the correct request', function() { + describe('Discount methods', () => { + describe('deleteDiscount', () => { + it('Sends the correct request', () => { stripe.subscriptions.deleteDiscount('test_sub'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', diff --git a/test/resources/TaxIds.spec.js b/test/resources/TaxIds.spec.js index 773400e030..fda30f9faa 100644 --- a/test/resources/TaxIds.spec.js +++ b/test/resources/TaxIds.spec.js @@ -1,64 +1,64 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var CUSTOMER_TEST_ID = 'cus_123'; -var TAX_ID_TEST_ID = 'txi_123'; +const CUSTOMER_TEST_ID = 'cus_123'; +const TAX_ID_TEST_ID = 'txi_123'; -var taxId = new resources.TaxIds(stripe, {customerId: CUSTOMER_TEST_ID}); +const taxId = new resources.TaxIds(stripe, {customerId: CUSTOMER_TEST_ID}); // Use spy from existing resource: taxId._request = stripe.customers._request; -describe('TaxId Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { - var data = { +describe('TaxId Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { + const data = { type: 'eu_vat', value: '11111', }; taxId.create(data); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/tax_ids', - data: data, + url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, + data, headers: {}, }); }); }); - describe('delete', function() { - it('Sends the correct request', function() { + describe('delete', () => { + it('Sends the correct request', () => { taxId.del(TAX_ID_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/tax_ids/' + TAX_ID_TEST_ID, + url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, data: {}, headers: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { taxId.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/tax_ids', + url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids`, data: {}, headers: {}, }); }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('retrieve', () => { + it('Sends the correct request', () => { taxId.retrieve(TAX_ID_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/customers/' + CUSTOMER_TEST_ID + '/tax_ids/' + TAX_ID_TEST_ID, + url: `/v1/customers/${CUSTOMER_TEST_ID}/tax_ids/${TAX_ID_TEST_ID}`, data: {}, headers: {}, }); diff --git a/test/resources/TaxRates.spec.js b/test/resources/TaxRates.spec.js index 74e931b29b..65afc211b3 100644 --- a/test/resources/TaxRates.spec.js +++ b/test/resources/TaxRates.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('TaxRates Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('TaxRates Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.taxRates.retrieve('txr_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,9 +16,9 @@ describe('TaxRates Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { - var data = { + describe('update', () => { + it('Sends the correct request', () => { + const data = { metadata: {a: '1234'}, }; stripe.taxRates.update('txr_123', data); @@ -26,14 +26,14 @@ describe('TaxRates Resource', function() { method: 'POST', url: '/v1/tax_rates/txr_123', headers: {}, - data: data, + data, }); }); }); - describe('create', function() { - it('Sends the correct request', function() { - var data = { + describe('create', () => { + it('Sends the correct request', () => { + const data = { display_name: 'name', inclusive: false, percentage: 10.15, @@ -44,13 +44,13 @@ describe('TaxRates Resource', function() { method: 'POST', url: '/v1/tax_rates', headers: {}, - data: data, + data, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.taxRates.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Terminal/ConnectionTokens.spec.js b/test/resources/Terminal/ConnectionTokens.spec.js index 75dd800361..2fa3a23845 100644 --- a/test/resources/Terminal/ConnectionTokens.spec.js +++ b/test/resources/Terminal/ConnectionTokens.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Terminal', function() { - describe('ConnectionToken Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { +describe('Terminal', () => { + describe('ConnectionToken Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { stripe.terminal.connectionTokens.create({}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/Terminal/Locations.spec.js b/test/resources/Terminal/Locations.spec.js index 335beb55b9..9ed65d5f8b 100644 --- a/test/resources/Terminal/Locations.spec.js +++ b/test/resources/Terminal/Locations.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Terminal', function() { - describe('Locations Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Terminal', () => { + describe('Locations Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.terminal.locations.retrieve('loc_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Terminal', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.terminal.locations.create({ display_name: 'name', address: { @@ -49,8 +49,8 @@ describe('Terminal', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.terminal.locations.del('loc_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -61,8 +61,8 @@ describe('Terminal', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.terminal.locations.update('loc_123', { display_name: 'name', }); @@ -77,8 +77,8 @@ describe('Terminal', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.terminal.locations.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Terminal/Readers.spec.js b/test/resources/Terminal/Readers.spec.js index ab6f60451f..f4bd88fb90 100644 --- a/test/resources/Terminal/Readers.spec.js +++ b/test/resources/Terminal/Readers.spec.js @@ -1,13 +1,13 @@ 'use strict'; -var stripe = require('../../../testUtils').getSpyableStripe(); +const stripe = require('../../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const expect = require('chai').expect; -describe('Terminal', function() { - describe('Readers Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Terminal', () => { + describe('Readers Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.terminal.readers.retrieve('rdr_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -19,8 +19,8 @@ describe('Terminal', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.terminal.readers.create({ registration_code: 'a-b-c', label: 'name', @@ -37,8 +37,8 @@ describe('Terminal', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.terminal.readers.del('rdr_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -49,8 +49,8 @@ describe('Terminal', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.terminal.readers.update('rdr_123', { label: 'name', }); @@ -65,8 +65,8 @@ describe('Terminal', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.terminal.readers.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/ThreeDSecure.spec.js b/test/resources/ThreeDSecure.spec.js index 9efc67b1e6..7ff3aad648 100644 --- a/test/resources/ThreeDSecure.spec.js +++ b/test/resources/ThreeDSecure.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('ThreeDSecure Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('ThreeDSecure Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.threeDSecure.retrieve('tdsrc_id'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('ThreeDSecure Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.threeDSecure.create({ card: 'tok_test', amount: 1500, diff --git a/test/resources/Tokens.spec.js b/test/resources/Tokens.spec.js index 397168f002..a5dd59708a 100644 --- a/test/resources/Tokens.spec.js +++ b/test/resources/Tokens.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Tokens Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { +describe('Tokens Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { stripe.tokens.create({ card: {number: 123}, }); @@ -18,8 +18,8 @@ describe('Tokens Resource', function() { }); }); - describe('retrieve', function() { - it('Sends the correct request', function() { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.tokens.retrieve('tokenId1'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/Topups.spec.js b/test/resources/Topups.spec.js index 7c1d1c2b94..dc77c0d2d0 100644 --- a/test/resources/Topups.spec.js +++ b/test/resources/Topups.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Topup Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Topup Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.topups.retrieve('tu_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Topup Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.topups.create({ source: 'src_123', amount: '1500', @@ -40,8 +40,8 @@ describe('Topup Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.topups.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -52,8 +52,8 @@ describe('Topup Resource', function() { }); }); - describe('cancel', function() { - it('Sends the correct request', function() { + describe('cancel', () => { + it('Sends the correct request', () => { stripe.topups.cancel('tu_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -64,8 +64,8 @@ describe('Topup Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.topups.update('tu_123', {metadata: {key: 'value'}}); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', diff --git a/test/resources/TransferReversals.spec.js b/test/resources/TransferReversals.spec.js index 5f06d8c0e9..3b0c9e67fb 100644 --- a/test/resources/TransferReversals.spec.js +++ b/test/resources/TransferReversals.spec.js @@ -1,75 +1,67 @@ 'use strict'; -var resources = require('../../lib/stripe').resources; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const resources = require('../../lib/stripe').resources; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -var TRANSFER_TEST_ID = 'transferIdTest999'; -var REVERSAL_TEST_ID = 'reversalIdTest999'; +const TRANSFER_TEST_ID = 'transferIdTest999'; +const REVERSAL_TEST_ID = 'reversalIdTest999'; // Create new CustomerCard instance with pre-filled customerId: -var transferReversal = new resources.TransferReversals(stripe, { +const transferReversal = new resources.TransferReversals(stripe, { transferId: TRANSFER_TEST_ID, }); // Use spy from existing resource: transferReversal._request = stripe.customers._request; -describe('TransferReversal Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('TransferReversal Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { transferReversal.retrieve(REVERSAL_TEST_ID); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: - '/v1/transfers/' + - TRANSFER_TEST_ID + - '/reversals/' + - REVERSAL_TEST_ID, + url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, data: {}, headers: {}, }); }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { transferReversal.create({ amount: 100, }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: '/v1/transfers/' + TRANSFER_TEST_ID + '/reversals', + url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, data: {amount: 100}, headers: {}, }); }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { transferReversal.update(REVERSAL_TEST_ID, { metadata: {key: 'value'}, }); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', - url: - '/v1/transfers/' + - TRANSFER_TEST_ID + - '/reversals/' + - REVERSAL_TEST_ID, + url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals/${REVERSAL_TEST_ID}`, data: {metadata: {key: 'value'}}, headers: {}, }); }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { transferReversal.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', - url: '/v1/transfers/' + TRANSFER_TEST_ID + '/reversals', + url: `/v1/transfers/${TRANSFER_TEST_ID}/reversals`, data: {}, headers: {}, }); diff --git a/test/resources/Transfers.spec.js b/test/resources/Transfers.spec.js index f00ba9defb..bc369d8b4d 100644 --- a/test/resources/Transfers.spec.js +++ b/test/resources/Transfers.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('Transfers Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('Transfers Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.transfers.retrieve('transferId1'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('Transfers Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.transfers.create({ amount: 200, currency: 'usd', @@ -32,8 +32,8 @@ describe('Transfers Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.transfers.update('transferId6654', { amount: 300, }); @@ -46,8 +46,8 @@ describe('Transfers Resource', function() { }); }); - describe('cancel', function() { - it('Sends the correct request', function() { + describe('cancel', () => { + it('Sends the correct request', () => { stripe.transfers.cancel('transferId4'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -58,8 +58,8 @@ describe('Transfers Resource', function() { }); }); - describe('reverse', function() { - it('Sends the correct request', function() { + describe('reverse', () => { + it('Sends the correct request', () => { stripe.transfers.reverse('transferId4'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', @@ -70,8 +70,8 @@ describe('Transfers Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.transfers.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -82,8 +82,8 @@ describe('Transfers Resource', function() { }); }); - describe('listTransactions', function() { - it('Sends the correct request', function() { + describe('listTransactions', () => { + it('Sends the correct request', () => { stripe.transfers.listTransactions('tr_14222'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/resources/UsageRecordSummaries.spec.js b/test/resources/UsageRecordSummaries.spec.js index 436dd580d7..0661ca727d 100644 --- a/test/resources/UsageRecordSummaries.spec.js +++ b/test/resources/UsageRecordSummaries.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('UsageRecordSummaries Resource', function() { - describe('list', function() { - it('Sends the correct request', function() { +describe('UsageRecordSummaries Resource', () => { + describe('list', () => { + it('Sends the correct request', () => { stripe.usageRecordSummaries.list('si_123', {}); expect(stripe.LAST_REQUEST).to.deep.equal({ @@ -16,7 +16,7 @@ describe('UsageRecordSummaries Resource', function() { }); }); - it('Includes any options that were provided', function(done) { + it('Includes any options that were provided', (done) => { stripe.usageRecordSummaries .list( 'si_123', @@ -25,7 +25,7 @@ describe('UsageRecordSummaries Resource', function() { stripe_account: 'acct_456', } ) - .then(function(record) { + .then((record) => { expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', url: '/v1/subscription_items/si_123/usage_record_summaries', @@ -39,8 +39,8 @@ describe('UsageRecordSummaries Resource', function() { }); }); - it('Calls a given callback', function(done) { - stripe.usageRecordSummaries.list('si_123', {}, function(error, record) { + it('Calls a given callback', (done) => { + stripe.usageRecordSummaries.list('si_123', {}, (error, record) => { done(error); }); }); diff --git a/test/resources/UsageRecords.spec.js b/test/resources/UsageRecords.spec.js index 0bd5f0b04f..fd9e3c7afc 100644 --- a/test/resources/UsageRecords.spec.js +++ b/test/resources/UsageRecords.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('UsageRecords Resource', function() { - describe('create', function() { - it('Sends the correct request', function() { +describe('UsageRecords Resource', () => { + describe('create', () => { + it('Sends the correct request', () => { stripe.usageRecords.create('si_123', { quantity: 123, timestamp: 123321, @@ -24,7 +24,7 @@ describe('UsageRecords Resource', function() { }); }); - it('Includes any options that were provided', function(done) { + it('Includes any options that were provided', (done) => { stripe.usageRecords .create( 'si_123', @@ -37,7 +37,7 @@ describe('UsageRecords Resource', function() { stripe_account: 'acct_456', } ) - .then(function(record) { + .then((record) => { expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'POST', url: '/v1/subscription_items/si_123/usage_records', @@ -55,7 +55,7 @@ describe('UsageRecords Resource', function() { }); }); - it('Calls a given callback', function(done) { + it('Calls a given callback', (done) => { stripe.usageRecords.create( 'si_123', { @@ -63,7 +63,7 @@ describe('UsageRecords Resource', function() { timestamp: 123321, action: 'increment', }, - function(error, record) { + (error, record) => { done(error); } ); diff --git a/test/resources/WebhookEndpoints.spec.js b/test/resources/WebhookEndpoints.spec.js index a2ac60b390..4c76854402 100644 --- a/test/resources/WebhookEndpoints.spec.js +++ b/test/resources/WebhookEndpoints.spec.js @@ -1,11 +1,11 @@ 'use strict'; -var stripe = require('../../testUtils').getSpyableStripe(); -var expect = require('chai').expect; +const stripe = require('../../testUtils').getSpyableStripe(); +const expect = require('chai').expect; -describe('WebhookEndpoints Resource', function() { - describe('retrieve', function() { - it('Sends the correct request', function() { +describe('WebhookEndpoints Resource', () => { + describe('retrieve', () => { + it('Sends the correct request', () => { stripe.webhookEndpoints.retrieve('we_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', @@ -16,8 +16,8 @@ describe('WebhookEndpoints Resource', function() { }); }); - describe('del', function() { - it('Sends the correct request', function() { + describe('del', () => { + it('Sends the correct request', () => { stripe.webhookEndpoints.del('we_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'DELETE', @@ -28,8 +28,8 @@ describe('WebhookEndpoints Resource', function() { }); }); - describe('update', function() { - it('Sends the correct request', function() { + describe('update', () => { + it('Sends the correct request', () => { stripe.webhookEndpoints.update('we_123', { enabled_events: ['charge.succeeded'], }); @@ -44,8 +44,8 @@ describe('WebhookEndpoints Resource', function() { }); }); - describe('create', function() { - it('Sends the correct request', function() { + describe('create', () => { + it('Sends the correct request', () => { stripe.webhookEndpoints.create({ enabled_events: ['charge.succeeded'], url: 'https://stripe.com', @@ -63,8 +63,8 @@ describe('WebhookEndpoints Resource', function() { }); }); - describe('list', function() { - it('Sends the correct request', function() { + describe('list', () => { + it('Sends the correct request', () => { stripe.webhookEndpoints.list(); expect(stripe.LAST_REQUEST).to.deep.equal({ method: 'GET', diff --git a/test/stripe.spec.js b/test/stripe.spec.js index a3901a3f56..7304a9d3e5 100644 --- a/test/stripe.spec.js +++ b/test/stripe.spec.js @@ -1,94 +1,93 @@ 'use strict'; -var testUtils = require('../testUtils'); -var utils = require('../lib/utils'); -var stripe = require('../lib/stripe')(testUtils.getUserStripeKey(), 'latest'); +const testUtils = require('../testUtils'); +const utils = require('../lib/utils'); +const stripe = require('../lib/stripe')(testUtils.getUserStripeKey(), 'latest'); -var http = require('http'); +const http = require('http'); -var expect = require('chai').expect; +const expect = require('chai').expect; -var CUSTOMER_DETAILS = { +const CUSTOMER_DETAILS = { description: 'Some customer', card: 'tok_visa', }; describe('Stripe Module', function() { - var cleanup = new testUtils.CleanupUtility(); + const cleanup = new testUtils.CleanupUtility(); this.timeout(20000); - describe('setApiKey', function() { - it('uses Bearer auth', function() { + describe('setApiKey', () => { + it('uses Bearer auth', () => { expect(stripe.getApiField('auth')).to.equal( - 'Bearer ' + testUtils.getUserStripeKey() + `Bearer ${testUtils.getUserStripeKey()}` ); }); }); - describe('GetClientUserAgent', function() { - it('Should return a user-agent serialized JSON object', function() { - return expect( - new Promise(function(resolve, reject) { - stripe.getClientUserAgent(function(c) { + describe('GetClientUserAgent', () => { + it('Should return a user-agent serialized JSON object', () => + expect( + new Promise((resolve, reject) => { + stripe.getClientUserAgent((c) => { resolve(JSON.parse(c)); }); }) - ).to.eventually.have.property('lang', 'node'); - }); + ).to.eventually.have.property('lang', 'node')); }); - describe('GetClientUserAgentSeeded', function() { - it('Should return a user-agent serialized JSON object', function() { - var userAgent = {lang: 'node'}; + describe('GetClientUserAgentSeeded', () => { + it('Should return a user-agent serialized JSON object', () => { + const userAgent = {lang: 'node'}; return expect( - new Promise(function(resolve, reject) { - stripe.getClientUserAgentSeeded(userAgent, function(c) { + new Promise((resolve, reject) => { + stripe.getClientUserAgentSeeded(userAgent, (c) => { resolve(JSON.parse(c)); }); }) ).to.eventually.have.property('lang', 'node'); }); - it('Should URI-encode user-agent fields', function() { - var userAgent = {lang: 'ï'}; + it('Should URI-encode user-agent fields', () => { + const userAgent = {lang: 'ï'}; return expect( - new Promise(function(resolve, reject) { - stripe.getClientUserAgentSeeded(userAgent, function(c) { + new Promise((resolve, reject) => { + stripe.getClientUserAgentSeeded(userAgent, (c) => { resolve(JSON.parse(c)); }); }) ).to.eventually.have.property('lang', '%C3%AF'); }); - describe('uname', function() { - var origExec; - beforeEach(function() { + describe('uname', () => { + let origExec; + beforeEach(() => { origExec = utils.safeExec; }); - afterEach(function() { + afterEach(() => { utils.safeExec = origExec; }); - it('gets added to the user-agent', function() { - utils.safeExec = function(cmd, cb) { + it('gets added to the user-agent', () => { + utils.safeExec = (cmd, cb) => { cb(null, 'foøname'); }; return expect( - new Promise(function(resolve, reject) { - stripe.getClientUserAgentSeeded({lang: 'node'}, function(c) { + new Promise((resolve, reject) => { + stripe.getClientUserAgentSeeded({lang: 'node'}, (c) => { resolve(JSON.parse(c)); }); }) ).to.eventually.have.property('uname', 'fo%C3%B8name'); }); - it('sets uname to UNKOWN in case of an error', function() { - utils.safeExec = function(cmd, cb) { + it('sets uname to UNKOWN in case of an error', () => { + utils.safeExec = (cmd, cb) => { cb(new Error('security'), null); }; return expect( - new Promise(function(resolve, reject) { - stripe.getClientUserAgentSeeded({lang: 'node'}, function(c) { + new Promise((resolve, reject) => { + stripe.getClientUserAgentSeeded({lang: 'node'}, (c) => { resolve(JSON.parse(c)); }); }) @@ -97,17 +96,17 @@ describe('Stripe Module', function() { }); }); - describe('setTimeout', function() { - it('Should define a default equal to the node default', function() { + describe('setTimeout', () => { + it('Should define a default equal to the node default', () => { expect(stripe.getApiField('timeout')).to.equal( http.createServer().timeout ); }); - it('Should allow me to set a custom timeout', function() { + it('Should allow me to set a custom timeout', () => { stripe.setTimeout(900); expect(stripe.getApiField('timeout')).to.equal(900); }); - it('Should allow me to set null, to reset to the default', function() { + it('Should allow me to set null, to reset to the default', () => { stripe.setTimeout(null); expect(stripe.getApiField('timeout')).to.equal( http.createServer().timeout @@ -115,27 +114,27 @@ describe('Stripe Module', function() { }); }); - describe('setAppInfo', function() { - describe('when given nothing or an empty object', function() { - it('should unset stripe._appInfo', function() { + describe('setAppInfo', () => { + describe('when given nothing or an empty object', () => { + it('should unset stripe._appInfo', () => { stripe.setAppInfo(); expect(stripe._appInfo).to.be.undefined; }); }); - describe('when given an object with no `name`', function() { - it('should throw an error', function() { - expect(function() { + describe('when given an object with no `name`', () => { + it('should throw an error', () => { + expect(() => { stripe.setAppInfo({}); }).to.throw(/AppInfo.name is required/); - expect(function() { + expect(() => { stripe.setAppInfo({ version: '1.2.3', }); }).to.throw(/AppInfo.name is required/); - expect(function() { + expect(() => { stripe.setAppInfo({ cats: '42', }); @@ -143,8 +142,8 @@ describe('Stripe Module', function() { }); }); - describe('when given at least a `name`', function() { - it('should set name, partner ID, url, and version of stripe._appInfo', function() { + describe('when given at least a `name`', () => { + it('should set name, partner ID, url, and version of stripe._appInfo', () => { stripe.setAppInfo({ name: 'MyAwesomeApp', }); @@ -180,7 +179,7 @@ describe('Stripe Module', function() { }); }); - it('should ignore any invalid properties', function() { + it('should ignore any invalid properties', () => { stripe.setAppInfo({ name: 'MyAwesomeApp', partner_id: 'partner_1234', @@ -197,8 +196,8 @@ describe('Stripe Module', function() { }); }); - it('should be included in the ClientUserAgent and be added to the UserAgent String', function(done) { - var appInfo = { + it('should be included in the ClientUserAgent and be added to the UserAgent String', (done) => { + const appInfo = { name: testUtils.getRandomString(), version: '1.2.345', url: 'https://myawesomeapp.info', @@ -206,11 +205,11 @@ describe('Stripe Module', function() { stripe.setAppInfo(appInfo); - stripe.getClientUserAgent(function(uaString) { + stripe.getClientUserAgent((uaString) => { expect(JSON.parse(uaString).application).to.eql(appInfo); expect(stripe.getAppInfoAsString()).to.eql( - appInfo.name + '/' + appInfo.version + ' (' + appInfo.url + ')' + `${appInfo.name}/${appInfo.version} (${appInfo.url})` ); done(); @@ -218,26 +217,25 @@ describe('Stripe Module', function() { }); }); - describe('Callback support', function() { - describe('Any given endpoint', function() { - it('Will call a callback if successful', function() { - return expect( - new Promise(function(resolve, reject) { - stripe.customers.create(CUSTOMER_DETAILS, function(err, customer) { + describe('Callback support', () => { + describe('Any given endpoint', () => { + it('Will call a callback if successful', () => + expect( + new Promise((resolve, reject) => { + stripe.customers.create(CUSTOMER_DETAILS, (err, customer) => { cleanup.deleteCustomer(customer.id); resolve('Called!'); }); }) - ).to.eventually.equal('Called!'); - }); + ).to.eventually.equal('Called!')); - it('Will expose HTTP response object', function() { - return expect( - new Promise(function(resolve, reject) { - stripe.customers.create(CUSTOMER_DETAILS, function(err, customer) { + it('Will expose HTTP response object', () => + expect( + new Promise((resolve, reject) => { + stripe.customers.create(CUSTOMER_DETAILS, (err, customer) => { cleanup.deleteCustomer(customer.id); - var headers = customer.lastResponse.headers; + const headers = customer.lastResponse.headers; expect(headers).to.contain.keys('request-id'); expect(customer.lastResponse.requestId).to.match(/^req_/); @@ -246,13 +244,15 @@ describe('Stripe Module', function() { resolve('Called!'); }); }) - ).to.eventually.equal('Called!'); - return expect( - new Promise(function(resolve, reject) { + ).to.eventually.equal('Called!')); + + it('Given an error the callback will receive it', () => + expect( + new Promise((resolve, reject) => { stripe.customers.createCard( 'nonExistentCustId', {card: {}}, - function(err, customer) { + (err, customer) => { if (err) { resolve('ErrorWasPassed'); } else { @@ -261,14 +261,13 @@ describe('Stripe Module', function() { } ); }) - ).to.eventually.become('ErrorWasPassed'); - }); + ).to.eventually.become('ErrorWasPassed')); }); }); - describe('errors', function() { - it('Exports errors as types', function() { - var Stripe = require('../lib/stripe'); + describe('errors', () => { + it('Exports errors as types', () => { + const Stripe = require('../lib/stripe'); expect( new Stripe.errors.StripeInvalidRequestError({ message: 'error', @@ -277,14 +276,14 @@ describe('Stripe Module', function() { }); }); - describe('setMaxNetworkRetries', function() { - describe('when given an empty or non-number variable', function() { - it('should error', function() { - expect(function() { + describe('setMaxNetworkRetries', () => { + describe('when given an empty or non-number variable', () => { + it('should error', () => { + expect(() => { stripe.setMaxNetworkRetries('foo'); }).to.throw(/maxNetworkRetries must be a number/); - expect(function() { + expect(() => { stripe.setMaxNetworkRetries(); }).to.throw(/maxNetworkRetries must be a number/); }); diff --git a/test/telemetry.spec.js b/test/telemetry.spec.js index cc62a61a86..355ec61de5 100644 --- a/test/telemetry.spec.js +++ b/test/telemetry.spec.js @@ -1,14 +1,14 @@ 'use strict'; require('../testUtils'); -var http = require('http'); +const http = require('http'); -var expect = require('chai').expect; -var testServer = null; +const expect = require('chai').expect; +let testServer = null; function createTestServer(handlerFunc, cb) { - var host = '127.0.0.1'; - testServer = http.createServer(function(req, res) { + const host = '127.0.0.1'; + testServer = http.createServer((req, res) => { try { handlerFunc(req, res); } catch (e) { @@ -20,28 +20,28 @@ function createTestServer(handlerFunc, cb) { ); } }); - testServer.listen(0, host, function() { - var port = testServer.address().port; + testServer.listen(0, host, () => { + const port = testServer.address().port; cb(host, port); }); } -describe('Client Telemetry', function() { - afterEach(function() { +describe('Client Telemetry', () => { + afterEach(() => { if (testServer) { testServer.close(); testServer = null; } }); - it('Does not send telemetry when disabled', function(done) { - var numRequests = 0; + it('Does not send telemetry when disabled', (done) => { + let numRequests = 0; createTestServer( - function(req, res) { + (req, res) => { numRequests += 1; - var telemetry = req.headers['x-stripe-client-telemetry']; + const telemetry = req.headers['x-stripe-client-telemetry']; switch (numRequests) { case 1: @@ -56,7 +56,7 @@ describe('Client Telemetry', function() { res.writeHead(200, {'Content-Type': 'application/json'}); res.end('{}'); }, - function(host, port) { + (host, port) => { const stripe = require('../lib/stripe')( 'sk_test_FEiILxKZwnmmocJDUjUNO6pa' ); @@ -64,10 +64,8 @@ describe('Client Telemetry', function() { stripe.balance .retrieve() - .then(function(res) { - return stripe.balance.retrieve(); - }) - .then(function(res) { + .then((res) => stripe.balance.retrieve()) + .then((res) => { expect(numRequests).to.equal(2); done(); }) @@ -76,14 +74,14 @@ describe('Client Telemetry', function() { ); }); - it('Sends client telemetry on the second request when enabled', function(done) { - var numRequests = 0; + it('Sends client telemetry on the second request when enabled', (done) => { + let numRequests = 0; createTestServer( - function(req, res) { + (req, res) => { numRequests += 1; - var telemetry = req.headers['x-stripe-client-telemetry']; + const telemetry = req.headers['x-stripe-client-telemetry']; switch (numRequests) { case 1: @@ -103,7 +101,7 @@ describe('Client Telemetry', function() { res.writeHead(200, {'Content-Type': 'application/json'}); res.end('{}'); }, - function(host, port) { + (host, port) => { const stripe = require('../lib/stripe')( 'sk_test_FEiILxKZwnmmocJDUjUNO6pa' ); @@ -112,10 +110,8 @@ describe('Client Telemetry', function() { stripe.balance .retrieve() - .then(function(res) { - return stripe.balance.retrieve(); - }) - .then(function(res) { + .then((res) => stripe.balance.retrieve()) + .then((res) => { expect(numRequests).to.equal(2); done(); }) @@ -124,14 +120,14 @@ describe('Client Telemetry', function() { ); }); - it('Buffers metrics on concurrent requests', function(done) { - var numRequests = 0; + it('Buffers metrics on concurrent requests', (done) => { + let numRequests = 0; createTestServer( - function(req, res) { + (req, res) => { numRequests += 1; - var telemetry = req.headers['x-stripe-client-telemetry']; + const telemetry = req.headers['x-stripe-client-telemetry']; switch (numRequests) { case 1: @@ -153,7 +149,7 @@ describe('Client Telemetry', function() { res.writeHead(200, {'Content-Type': 'application/json'}); res.end('{}'); }, - function(host, port) { + (host, port) => { const stripe = require('../lib/stripe')( 'sk_test_FEiILxKZwnmmocJDUjUNO6pa' ); @@ -161,13 +157,10 @@ describe('Client Telemetry', function() { stripe.setHost(host, port, 'http'); Promise.all([stripe.balance.retrieve(), stripe.balance.retrieve()]) - .then(function() { - return Promise.all([ - stripe.balance.retrieve(), - stripe.balance.retrieve(), - ]); - }) - .then(function() { + .then(() => + Promise.all([stripe.balance.retrieve(), stripe.balance.retrieve()]) + ) + .then(() => { expect(numRequests).to.equal(4); done(); }) diff --git a/test/utils.spec.js b/test/utils.spec.js index d9ae8a6d54..202da2f67c 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -2,14 +2,14 @@ require('../testUtils'); -var utils = require('../lib/utils'); -var expect = require('chai').expect; -var Buffer = require('safe-buffer').Buffer; +const utils = require('../lib/utils'); +const expect = require('chai').expect; +const Buffer = require('safe-buffer').Buffer; -describe('utils', function() { - describe('makeURLInterpolator', function() { - it('Interpolates values into a prepared template', function() { - var template = utils.makeURLInterpolator('/some/url/{foo}/{baz}?ok=1'); +describe('utils', () => { + describe('makeURLInterpolator', () => { + it('Interpolates values into a prepared template', () => { + const template = utils.makeURLInterpolator('/some/url/{foo}/{baz}?ok=1'); expect(template({foo: 1, baz: 2})).to.equal('/some/url/1/2?ok=1'); @@ -22,8 +22,8 @@ describe('utils', function() { }); }); - describe('stringifyRequestData', function() { - it('Handles basic types', function() { + describe('stringifyRequestData', () => { + it('Handles basic types', () => { expect( utils.stringifyRequestData({ a: 1, @@ -32,7 +32,7 @@ describe('utils', function() { ).to.equal('a=1&b=foo'); }); - it('Handles Dates', function() { + it('Handles Dates', () => { expect( utils.stringifyRequestData({ date: new Date('2009-02-13T23:31:30Z'), @@ -50,7 +50,7 @@ describe('utils', function() { ); }); - it('Handles deeply nested object', function() { + it('Handles deeply nested object', () => { expect( utils.stringifyRequestData({ a: { @@ -64,7 +64,7 @@ describe('utils', function() { ).to.equal('a[b][c][d]=2'); }); - it('Handles arrays of objects', function() { + it('Handles arrays of objects', () => { expect( utils.stringifyRequestData({ a: [{b: 'c'}, {b: 'd'}], @@ -72,7 +72,7 @@ describe('utils', function() { ).to.equal('a[0][b]=c&a[1][b]=d'); }); - it('Handles indexed arrays', function() { + it('Handles indexed arrays', () => { expect( utils.stringifyRequestData({ a: { @@ -83,7 +83,7 @@ describe('utils', function() { ).to.equal('a[0][b]=c&a[1][b]=d'); }); - it('Creates a string from an object, handling shallow nested objects', function() { + it('Creates a string from an object, handling shallow nested objects', () => { expect( utils.stringifyRequestData({ test: 1, @@ -106,11 +106,11 @@ describe('utils', function() { }); }); - describe('protoExtend', function() { - it('Provides an extension mechanism', function() { + describe('protoExtend', () => { + it('Provides an extension mechanism', () => { function A() {} A.extend = utils.protoExtend; - var B = A.extend({ + const B = A.extend({ constructor: function() { this.called = true; }, @@ -122,38 +122,38 @@ describe('utils', function() { }); }); - describe('getDataFromArgs', function() { - it('handles an empty list', function() { + describe('getDataFromArgs', () => { + it('handles an empty list', () => { expect(utils.getDataFromArgs([])).to.deep.equal({}); }); - it('handles a list with no object', function() { - var args = [1, 3]; + it('handles a list with no object', () => { + const args = [1, 3]; expect(utils.getDataFromArgs(args)).to.deep.equal({}); expect(args.length).to.equal(2); }); - it('ignores a hash with only options', function(done) { - var args = [{api_key: 'foo'}]; + it('ignores a hash with only options', (done) => { + const args = [{api_key: 'foo'}]; handleWarnings( - function() { + () => { expect(utils.getDataFromArgs(args)).to.deep.equal({}); expect(args.length).to.equal(1); done(); }, - function(message) { - throw new Error('Should not have warned, but did: ' + message); + (message) => { + throw new Error(`Should not have warned, but did: ${message}`); } ); }); - it('warns if the hash contains both data and options', function(done) { - var args = [{foo: 'bar', api_key: 'foo', idempotency_key: 'baz'}]; + it('warns if the hash contains both data and options', (done) => { + const args = [{foo: 'bar', api_key: 'foo', idempotency_key: 'baz'}]; handleWarnings( - function() { + () => { utils.getDataFromArgs(args); }, - function(message) { + (message) => { expect(message).to.equal( 'Stripe: Options found in arguments (api_key, idempotency_key).' + ' Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' @@ -163,62 +163,62 @@ describe('utils', function() { } ); }); - it('finds the data', function() { - var args = [{foo: 'bar'}, {api_key: 'foo'}]; + it('finds the data', () => { + const args = [{foo: 'bar'}, {api_key: 'foo'}]; expect(utils.getDataFromArgs(args)).to.deep.equal({foo: 'bar'}); expect(args.length).to.equal(1); }); }); - describe('getOptsFromArgs', function() { - it('handles an empty list', function() { + describe('getOptsFromArgs', () => { + it('handles an empty list', () => { expect(utils.getOptionsFromArgs([])).to.deep.equal({ auth: null, headers: {}, }); }); - it('handles an list with no object', function() { - var args = [1, 3]; + it('handles an list with no object', () => { + const args = [1, 3]; expect(utils.getOptionsFromArgs(args)).to.deep.equal({ auth: null, headers: {}, }); expect(args.length).to.equal(2); }); - it('ignores a non-options object', function() { - var args = [{foo: 'bar'}]; + it('ignores a non-options object', () => { + const args = [{foo: 'bar'}]; expect(utils.getOptionsFromArgs(args)).to.deep.equal({ auth: null, headers: {}, }); expect(args.length).to.equal(1); }); - it('parses an api key', function() { - var args = ['sk_test_iiiiiiiiiiiiiiiiiiiiiiii']; + it('parses an api key', () => { + const args = ['sk_test_iiiiiiiiiiiiiiiiiiiiiiii']; expect(utils.getOptionsFromArgs(args)).to.deep.equal({ auth: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii', headers: {}, }); expect(args.length).to.equal(0); }); - it('parses an idempotency key', function() { - var args = [{foo: 'bar'}, {idempotency_key: 'foo'}]; + it('parses an idempotency key', () => { + const args = [{foo: 'bar'}, {idempotency_key: 'foo'}]; expect(utils.getOptionsFromArgs(args)).to.deep.equal({ auth: null, headers: {'Idempotency-Key': 'foo'}, }); expect(args.length).to.equal(1); }); - it('parses an api version', function() { - var args = [{foo: 'bar'}, {stripe_version: '2003-03-30'}]; + it('parses an api version', () => { + const args = [{foo: 'bar'}, {stripe_version: '2003-03-30'}]; expect(utils.getOptionsFromArgs(args)).to.deep.equal({ auth: null, headers: {'Stripe-Version': '2003-03-30'}, }); expect(args.length).to.equal(1); }); - it('parses an idempotency key and api key and api version (with data)', function() { - var args = [ + it('parses an idempotency key and api key and api version (with data)', () => { + const args = [ {foo: 'bar'}, { api_key: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii', @@ -235,8 +235,8 @@ describe('utils', function() { }); expect(args.length).to.equal(1); }); - it('parses an idempotency key and api key and api version', function() { - var args = [ + it('parses an idempotency key and api key and api version', () => { + const args = [ { api_key: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii', idempotency_key: 'foo', @@ -252,8 +252,8 @@ describe('utils', function() { }); expect(args.length).to.equal(0); }); - it('warns if the hash contains something that does not belong', function(done) { - var args = [ + it('warns if the hash contains something that does not belong', (done) => { + const args = [ {foo: 'bar'}, { api_key: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii', @@ -265,10 +265,10 @@ describe('utils', function() { ]; handleWarnings( - function() { + () => { utils.getOptionsFromArgs(args); }, - function(message) { + (message) => { expect(message).to.equal( 'Stripe: Invalid options found (fishsticks, custard); ignoring.' ); @@ -279,24 +279,24 @@ describe('utils', function() { }); }); - describe('secureCompare', function() { - it('returns true given two equal things', function() { + describe('secureCompare', () => { + it('returns true given two equal things', () => { expect(utils.secureCompare('potato', 'potato')).to.equal(true); }); - it('returns false given two unequal things', function() { + it('returns false given two unequal things', () => { expect(utils.secureCompare('potato', 'tomato')).to.equal(false); }); - it('throws an error if not given two things to compare', function() { - expect(function() { + it('throws an error if not given two things to compare', () => { + expect(() => { utils.secureCompare('potato'); }).to.throw(); }); }); - describe('removeEmpty', function() { - it('removes empty properties and leaves non-empty ones', function() { + describe('removeEmpty', () => { + it('removes empty properties and leaves non-empty ones', () => { expect( utils.removeEmpty({ cat: 3, @@ -310,25 +310,25 @@ describe('utils', function() { }); }); - it('throws an error if not given two things to compare', function() { - expect(function() { + it('throws an error if not given two things to compare', () => { + expect(() => { utils.removeEmpty('potato'); }).to.throw(); }); }); - describe('safeExec', function() { - var origExec; - beforeEach(function() { + describe('safeExec', () => { + let origExec; + beforeEach(() => { origExec = utils._exec; }); - afterEach(function() { + afterEach(() => { utils._exec = origExec; }); - it('runs exec', function() { - var calls = []; - utils._exec = function(cmd, cb) { + it('runs exec', () => { + const calls = []; + utils._exec = (cmd, cb) => { calls.push([cmd, cb]); }; @@ -337,13 +337,13 @@ describe('utils', function() { expect(calls).to.deep.equal([['hello', myCb]]); }); - it('passes along normal errors', function() { - var myErr = Error('hi'); - utils._exec = function(cmd, cb) { + it('passes along normal errors', () => { + const myErr = Error('hi'); + utils._exec = (cmd, cb) => { cb(myErr, null); }; - var calls = []; + const calls = []; function myCb(err, x) { calls.push([err, x]); } @@ -351,13 +351,13 @@ describe('utils', function() { expect(calls).to.deep.equal([[myErr, null]]); }); - it('passes along thrown errors as normal callback errors', function() { - var myErr = Error('hi'); - utils._exec = function(cmd, cb) { + it('passes along thrown errors as normal callback errors', () => { + const myErr = Error('hi'); + utils._exec = (cmd, cb) => { throw myErr; }; - var calls = []; + const calls = []; function myCb(err, x) { calls.push([err, x]); } @@ -366,8 +366,8 @@ describe('utils', function() { }); }); - describe('flattenAndStringify', function() { - it('Stringifies primitive types', function() { + describe('flattenAndStringify', () => { + it('Stringifies primitive types', () => { expect( utils.flattenAndStringify({ a: 1, @@ -378,7 +378,7 @@ describe('utils', function() { ).to.eql({a: '1', b: 'foo', c: 'true', d: 'null'}); }); - it('Flattens nested values', function() { + it('Flattens nested values', () => { expect( utils.flattenAndStringify({ x: { @@ -389,7 +389,7 @@ describe('utils', function() { ).to.eql({'x[a]': '1', 'x[b]': 'foo'}); }); - it('Does not flatten File objects', function() { + it('Does not flatten File objects', () => { expect( utils.flattenAndStringify({ file: { @@ -402,10 +402,10 @@ describe('utils', function() { ).to.eql({file: {data: 'foo'}, 'x[a]': '1'}); }); - it('Does not flatten Buffer objects', function() { - var buf = Buffer.from('Hi!'); - var flattened = utils.flattenAndStringify({ - buf: buf, + it('Does not flatten Buffer objects', () => { + const buf = Buffer.from('Hi!'); + const flattened = utils.flattenAndStringify({ + buf, x: { a: 1, }, @@ -423,7 +423,7 @@ function handleWarnings(doWithShimmedConsoleWarn, onWarn) { /* eslint-disable no-console */ // Shim `console.warn` - var _warn = console.warn; + const _warn = console.warn; console.warn = onWarn; doWithShimmedConsoleWarn(); @@ -435,14 +435,14 @@ function handleWarnings(doWithShimmedConsoleWarn, onWarn) { } else { /* eslint-disable-next-line no-inner-declarations */ function onProcessWarn(warning) { - onWarn(warning.name + ': ' + warning.message); + onWarn(`${warning.name}: ${warning.message}`); } process.on('warning', onProcessWarn); doWithShimmedConsoleWarn(); - process.nextTick(function() { + process.nextTick(() => { process.removeListener('warning', onProcessWarn); }); } diff --git a/testUtils/index.js b/testUtils/index.js index 443b2c4655..8215645e53 100644 --- a/testUtils/index.js +++ b/testUtils/index.js @@ -6,26 +6,26 @@ require('mocha'); // Ensure we are using the 'as promised' libs before any tests are run: require('chai').use(require('chai-as-promised')); -var ResourceNamespace = require('../lib/ResourceNamespace').ResourceNamespace; +const ResourceNamespace = require('../lib/ResourceNamespace').ResourceNamespace; -var utils = (module.exports = { - getUserStripeKey: function() { - var key = +const utils = (module.exports = { + getUserStripeKey: () => { + const key = process.env.STRIPE_TEST_API_KEY || 'tGN0bIwXnHdwOa85VABjPdSn8nWY7G7I'; return key; }, - getSpyableStripe: function() { + getSpyableStripe: () => { // Provide a testable stripe instance // That is, with mock-requests built in and hookable - var stripe = require('../lib/stripe'); - var stripeInstance = stripe('fakeAuthToken'); + const stripe = require('../lib/stripe'); + const stripeInstance = stripe('fakeAuthToken'); stripeInstance.REQUESTS = []; - for (var i in stripeInstance) { + for (const i in stripeInstance) { makeInstanceSpyable(stripeInstance, stripeInstance[i]); } @@ -33,9 +33,9 @@ var utils = (module.exports = { if (thisInstance instanceof stripe.StripeResource) { patchRequest(stripeInstance, thisInstance); } else if (thisInstance instanceof ResourceNamespace) { - var namespace = thisInstance; + const namespace = thisInstance; - for (var j in namespace) { + for (const j in namespace) { makeInstanceSpyable(stripeInstance, namespace[j]); } } @@ -43,10 +43,10 @@ var utils = (module.exports = { function patchRequest(stripeInstance, instance) { instance._request = function(method, host, url, data, auth, options, cb) { - var req = (stripeInstance.LAST_REQUEST = { - method: method, - url: url, - data: data, + const req = (stripeInstance.LAST_REQUEST = { + method, + url, + data, headers: options.headers || {}, }); if (auth) { @@ -68,11 +68,11 @@ var utils = (module.exports = { * CleanupUtility will automatically register on the mocha afterEach hook, * ensuring its called after each descendent-describe block. */ - CleanupUtility: (function() { + CleanupUtility: (() => { CleanupUtility.DEFAULT_TIMEOUT = 20000; function CleanupUtility(timeout) { - var self = this; + const self = this; this._cleanupFns = []; this._stripe = require('../lib/stripe')( utils.getUserStripeKey(), @@ -85,27 +85,27 @@ var utils = (module.exports = { } CleanupUtility.prototype = { - doCleanup: function(done) { - var cleanups = this._cleanupFns; - var total = cleanups.length; - var completed = 0; - var fn; + doCleanup(done) { + const cleanups = this._cleanupFns; + const total = cleanups.length; + let completed = 0; + let fn; while ((fn = cleanups.shift())) { - var promise = fn.call(this); + const promise = fn.call(this); if (!promise || !promise.then) { throw new Error( 'CleanupUtility expects cleanup functions to return promises!' ); } promise.then( - function() { + () => { // cleanup successful completed += 1; if (completed === total) { done(); } }, - function(err) { + (err) => { // not successful throw err; } @@ -115,25 +115,25 @@ var utils = (module.exports = { done(); } }, - add: function(fn) { + add(fn) { this._cleanupFns.push(fn); }, - deleteCustomer: function(custId) { + deleteCustomer(custId) { this.add(function() { return this._stripe.customers.del(custId); }); }, - deletePlan: function(pId) { + deletePlan(pId) { this.add(function() { return this._stripe.plans.del(pId); }); }, - deleteCoupon: function(cId) { + deleteCoupon(cId) { this.add(function() { return this._stripe.coupons.del(cId); }); }, - deleteInvoiceItem: function(iiId) { + deleteInvoiceItem(iiId) { this.add(function() { return this._stripe.invoiceItems.del(iiId); }); @@ -146,17 +146,17 @@ var utils = (module.exports = { /** * Get a random string for test Object creation */ - getRandomString: function() { + getRandomString: () => { return Math.random() .toString(36) .slice(2); }, - envSupportsForAwait: function() { + envSupportsForAwait: () => { return typeof Symbol !== 'undefined' && Symbol.asyncIterator; }, - envSupportsAwait: function() { + envSupportsAwait: () => { try { eval('(async function() {})'); // eslint-disable-line no-eval return true;