From adcbb17ebc9b447f5cec887cd23a9e1d07baddb7 Mon Sep 17 00:00:00 2001 From: Bruno Vieira Date: Thu, 18 Jan 2024 13:53:56 +0000 Subject: [PATCH] replace request library for superagent Signed-off-by: Bruno Vieira --- CHANGELOG.md | 3 + lib/chartmogul/util/retry.js | 14 +- package-lock.json | 328 ++++++++++++++++++++++--- package.json | 3 +- test/chartmogul/contact.js | 7 +- test/chartmogul/customer.js | 13 +- test/chartmogul/enrichment/customer.js | 7 +- test/chartmogul/invoice.js | 11 +- test/chartmogul/metrics/activity.js | 7 +- test/chartmogul/metrics/index.js | 57 +++-- test/chartmogul/resource.js | 30 ++- 11 files changed, 394 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0cb749..2b4093d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning]. [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html +## [3.2.2] - 2023-01-28 +- Remove the `requests` library and use `superagent` instead + ## [3.2.1] - 2023-12-20 - Fix missing `customer_uuid` when creating a note or retrieving all notes from a customer diff --git a/lib/chartmogul/util/retry.js b/lib/chartmogul/util/retry.js index 60ee5ab..60e0490 100644 --- a/lib/chartmogul/util/retry.js +++ b/lib/chartmogul/util/retry.js @@ -1,7 +1,8 @@ 'use strict'; -const request = require('request'); +const superagent = require('superagent'); const retry = require('retry'); +const { URL } = require('url'); function retryOnStatus (res) { if ( @@ -42,12 +43,19 @@ module.exports = function retryRequest (retries, options, cb) { minTimeout: 500, maxTimeout: 60 * 1000 }); + operation.attempt(function (currentAttempt) { - request(options, (err, res, body) => { + const requestUrl = new URL(options.uri, options.baseUrl).toString(); + const request = superagent(options.method || 'get', requestUrl) + .auth(options.auth.user, options.auth.pass) + .set(options.headers) + .send(options.body); + + request.end((err, res) => { if (operation.retry(retryOnStatus(res) || retryOnNetworkError(err))) { return; } - cb(err, res, body); + cb(err, res, res && res.body); }); }); }; diff --git a/package-lock.json b/package-lock.json index ddd9f24..98cabba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "chartmogul-node", - "version": "3.1.0", + "version": "3.2.1", "lockfileVersion": 2, "requires": true, "packages": { @@ -12,6 +12,7 @@ "nyc": "^15.1.0", "request": "^2.88.2", "retry": "^0.13.1", + "superagent": "^8.1.2", "uri-templates": "^0.2.0" }, "devDependencies": { @@ -964,6 +965,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==" + }, "node_modules/asn1": { "version": "0.2.6", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", @@ -1183,7 +1189,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", - "dev": true, "dependencies": { "function-bind": "^1.1.1", "get-intrinsic": "^1.0.2" @@ -1385,6 +1390,14 @@ "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==" }, + "node_modules/component-emitter": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", + "integrity": "sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1410,6 +1423,11 @@ "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==" }, + "node_modules/cookiejar": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", + "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==" + }, "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -1583,6 +1601,15 @@ "node": ">=6.0" } }, + "node_modules/dezalgo": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", + "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", + "dependencies": { + "asap": "^2.0.0", + "wrappy": "1" + } + }, "node_modules/diff": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", @@ -2201,6 +2228,11 @@ "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==" + }, "node_modules/fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -2336,6 +2368,34 @@ "node": ">= 0.12" } }, + "node_modules/formidable": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz", + "integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==", + "dependencies": { + "dezalgo": "^1.0.4", + "hexoid": "^1.0.0", + "once": "^1.4.0", + "qs": "^6.11.0" + }, + "funding": { + "url": "https://ko-fi.com/tunnckoCore/commissions" + } + }, + "node_modules/formidable/node_modules/qs": { + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/fromentries": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz", @@ -2391,8 +2451,7 @@ "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "node_modules/function.prototype.name": { "version": "1.1.5", @@ -2450,7 +2509,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", - "dev": true, "dependencies": { "function-bind": "^1.1.1", "has": "^1.0.3", @@ -2602,7 +2660,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, "dependencies": { "function-bind": "^1.1.1" }, @@ -2643,7 +2700,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -2655,7 +2711,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -2710,6 +2765,14 @@ "he": "bin/he" } }, + "node_modules/hexoid": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", + "integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==", + "engines": { + "node": ">=8" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -3384,6 +3447,25 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -3808,7 +3890,6 @@ "version": "1.12.3", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -4551,7 +4632,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", - "dev": true, "dependencies": { "call-bind": "^1.0.0", "get-intrinsic": "^1.0.2", @@ -4613,9 +4693,9 @@ "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==" }, "node_modules/sshpk": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.17.0.tgz", - "integrity": "sha512-/9HIEs1ZXGhSPE8X6Ccm7Nam1z8KcoCqPdI7ecm1N33EzAetWahvQWVqLZtaZQ+IDKX4IyA2o0gBzqIMkAagHQ==", + "version": "1.18.0", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.18.0.tgz", + "integrity": "sha512-2p2KJZTSqQ/I3+HX42EpYOa2l3f8Erv8MWKsy2I9uf4wA7yFIkXRffYdsx86y6z4vHtV8u7g+pPlr8/4ouAxsQ==", "dependencies": { "asn1": "~0.2.3", "assert-plus": "^1.0.0", @@ -4740,6 +4820,83 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/superagent": { + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz", + "integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==", + "dependencies": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.4", + "debug": "^4.3.4", + "fast-safe-stringify": "^2.1.1", + "form-data": "^4.0.0", + "formidable": "^2.1.2", + "methods": "^1.1.2", + "mime": "2.6.0", + "qs": "^6.11.0", + "semver": "^7.3.8" + }, + "engines": { + "node": ">=6.4.0 <13 || >=14" + } + }, + "node_modules/superagent/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/superagent/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/superagent/node_modules/qs": { + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/superagent/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/superagent/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -5968,6 +6125,11 @@ "is-shared-array-buffer": "^1.0.2" } }, + "asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==" + }, "asn1": { "version": "0.2.6", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", @@ -6130,7 +6292,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", - "dev": true, "requires": { "function-bind": "^1.1.1", "get-intrinsic": "^1.0.2" @@ -6273,6 +6434,11 @@ "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==" }, + "component-emitter": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", + "integrity": "sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -6295,6 +6461,11 @@ "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==" }, + "cookiejar": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", + "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==" + }, "core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -6418,6 +6589,15 @@ "node-source-walk": "^4.0.0" } }, + "dezalgo": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", + "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", + "requires": { + "asap": "^2.0.0", + "wrappy": "1" + } + }, "diff": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", @@ -6869,6 +7049,11 @@ "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, + "fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==" + }, "fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -6971,6 +7156,27 @@ "mime-types": "^2.1.12" } }, + "formidable": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz", + "integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==", + "requires": { + "dezalgo": "^1.0.4", + "hexoid": "^1.0.0", + "once": "^1.4.0", + "qs": "^6.11.0" + }, + "dependencies": { + "qs": { + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "requires": { + "side-channel": "^1.0.4" + } + } + } + }, "fromentries": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz", @@ -7002,8 +7208,7 @@ "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "function.prototype.name": { "version": "1.1.5", @@ -7043,7 +7248,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", - "dev": true, "requires": { "function-bind": "^1.1.1", "has": "^1.0.3", @@ -7152,7 +7356,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, "requires": { "function-bind": "^1.1.1" } @@ -7180,14 +7383,12 @@ "has-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", - "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", - "dev": true + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==" }, "has-symbols": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" }, "has-tostringtag": { "version": "1.0.0", @@ -7220,6 +7421,11 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, + "hexoid": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", + "integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==" + }, "html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -7707,6 +7913,16 @@ "semver": "^6.0.0" } }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==" + }, + "mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==" + }, "mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -8040,8 +8256,7 @@ "object-inspect": { "version": "1.12.3", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", - "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", - "dev": true + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==" }, "object-keys": { "version": "1.1.1", @@ -8578,7 +8793,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", - "dev": true, "requires": { "call-bind": "^1.0.0", "get-intrinsic": "^1.0.2", @@ -8630,9 +8844,9 @@ "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==" }, "sshpk": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.17.0.tgz", - "integrity": "sha512-/9HIEs1ZXGhSPE8X6Ccm7Nam1z8KcoCqPdI7ecm1N33EzAetWahvQWVqLZtaZQ+IDKX4IyA2o0gBzqIMkAagHQ==", + "version": "1.18.0", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.18.0.tgz", + "integrity": "sha512-2p2KJZTSqQ/I3+HX42EpYOa2l3f8Erv8MWKsy2I9uf4wA7yFIkXRffYdsx86y6z4vHtV8u7g+pPlr8/4ouAxsQ==", "requires": { "asn1": "~0.2.3", "assert-plus": "^1.0.0", @@ -8724,6 +8938,64 @@ "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, + "superagent": { + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz", + "integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==", + "requires": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.4", + "debug": "^4.3.4", + "fast-safe-stringify": "^2.1.1", + "form-data": "^4.0.0", + "formidable": "^2.1.2", + "methods": "^1.1.2", + "mime": "2.6.0", + "qs": "^6.11.0", + "semver": "^7.3.8" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "qs": { + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "requires": { + "side-channel": "^1.0.4" + } + }, + "semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } + }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", diff --git a/package.json b/package.json index 854156f..373b3c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chartmogul-node", - "version": "3.2.1", + "version": "3.2.2", "description": "Official Chartmogul API Node.js Client", "main": "lib/chartmogul.js", "scripts": { @@ -33,6 +33,7 @@ "nyc": "^15.1.0", "request": "^2.88.2", "retry": "^0.13.1", + "superagent": "^8.1.2", "uri-templates": "^0.2.0" }, "devDependencies": { diff --git a/test/chartmogul/contact.js b/test/chartmogul/contact.js index 18a418d..071ebf4 100644 --- a/test/chartmogul/contact.js +++ b/test/chartmogul/contact.js @@ -59,7 +59,7 @@ describe('Contact', () => { }); }); - it('should list all contacts with pagination', () => { + it('should list all contacts with pagination', done => { const query = { per_page: 1, cursor: 'cursor==' @@ -82,13 +82,14 @@ describe('Contact', () => { /* eslint-enable camelcase */ }); - return Contact.all(config, query) + Contact.all(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res.cursor).to.eql('MjAyMy0wMy0xM1QxMjowMTozMi44MD=='); expect(res.has_more).to.eql(false); }); + done(); }); it('throws DeprecatedParamError if using old pagination parameter', done => { @@ -106,8 +107,8 @@ describe('Contact', () => { expect(e).to.be.instanceOf(ChartMogul.DeprecatedParamError); expect(e.httpStatus).to.equal(422); expect(e.message).to.equal('"page" param is deprecated {}'); - done(); }); + done(); }); it('retrieves a contact', () => { diff --git a/test/chartmogul/customer.js b/test/chartmogul/customer.js index 534e5ed..ba948c8 100644 --- a/test/chartmogul/customer.js +++ b/test/chartmogul/customer.js @@ -57,11 +57,11 @@ describe('Customer', () => { expect(e).to.be.instanceOf(ChartMogul.DeprecatedParamError); expect(e.httpStatus).to.equal(422); expect(e.message).to.equal('"page" param is deprecated {}'); - done(); }); + done(); }); - it('should list all customers with pagination', () => { + it('should list all customers with pagination', done => { const query = { per_page: 1, cursor: 'cursor==' @@ -89,13 +89,14 @@ describe('Customer', () => { /* eslint-enable camelcase */ }); - return Customer.all(config, query) + Customer.all(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res.cursor).to.eql('MjAyMy0wMy0xM1QxMjowMTozMi44MD=='); expect(res.has_more).to.eql(false); }); + done(); }); it('should delete a customer', () => { @@ -304,7 +305,7 @@ describe('Enrichment#Customer', () => { }); }); - it('should search for a customer with pagination', () => { + it('should search for a customer with pagination', done => { const query = { email: 'adam@smith.com', per_page: 1 @@ -321,13 +322,14 @@ describe('Enrichment#Customer', () => { /* eslint-enable camelcase */ }); - return Customer.search(config, query) + Customer.search(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res.cursor).to.eql('JjI3MjI4NTM=='); expect(res.has_more).to.eql(false); }); + done(); }); it('should retrieve customer attributes', () => { @@ -391,6 +393,7 @@ describe('Enrichment#Customer', () => { expect(res).to.be.instanceof(Object); }); }); + it('should connect subscriptions', () => { const customerUuid = 'cus_7e4e5c3d-832c-4fa4-bf77-6fdc8c6e14bc'; /* eslint-disable camelcase */ diff --git a/test/chartmogul/enrichment/customer.js b/test/chartmogul/enrichment/customer.js index aae16a2..5c13dcf 100644 --- a/test/chartmogul/enrichment/customer.js +++ b/test/chartmogul/enrichment/customer.js @@ -63,8 +63,8 @@ describe('DeprecatedEnrichment#Customer', () => { expect(e).to.be.instanceOf(ChartMogul.DeprecatedParamError); expect(e.httpStatus).to.equal(422); expect(e.message).to.equal('"page" param is deprecated {}'); - done(); }); + done(); }); it('should get all customers with pagination', () => { @@ -87,7 +87,7 @@ describe('DeprecatedEnrichment#Customer', () => { }); }); - it('should search for a customer with pagination', () => { + it('should search for a customer with pagination', done => { const email = 'adam@smith.com'; const query = { email, @@ -105,13 +105,14 @@ describe('DeprecatedEnrichment#Customer', () => { /* eslint-enable camelcase */ }); - return Customer.search(config, query) + Customer.search(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res.cursor).to.eql('cursor=='); expect(res.has_more).to.eql(false); }); + done(); }); it('should retrieve customer attributes', () => { diff --git a/test/chartmogul/invoice.js b/test/chartmogul/invoice.js index c18f751..22fe4b5 100644 --- a/test/chartmogul/invoice.js +++ b/test/chartmogul/invoice.js @@ -149,8 +149,8 @@ describe('Customer Invoice', () => { return done(err); } expect(res).to.have.property('invoices'); - done(); }); + done(); }); it('throws DeprecatedParamError if using old pagination parameter', done => { @@ -170,8 +170,8 @@ describe('Customer Invoice', () => { expect(e).to.be.instanceOf(ChartMogul.DeprecatedParamError); expect(e.httpStatus).to.equal(422); expect(e.message).to.equal('"page" param is deprecated {}'); - done(); }); + done(); }); it('should list all customer invoices with pagination', () => { @@ -219,8 +219,8 @@ describe('Customer Invoice', () => { expect(res.invoices).to.be.instanceof(Array); expect(res.cursor).to.eql('cursor=='); expect(res.has_more).to.eql(false); - done(); }); + done(); }); }); @@ -240,13 +240,13 @@ describe('Invoices', () => { }); }); - it('should get invoices by external id', () => { + it('should get invoices by external id', done => { nock(config.API_BASE) .get('/v1/invoices') .query({ external_id: 'INV0001' }) .reply(200, invoiceListResult); - return Invoice.all(config, { external_id: 'INV0001' }) + Invoice.all(config, { external_id: 'INV0001' }) .then(res => { expect(res).to.have.property('invoices'); expect(res.invoices).to.be.instanceof(Array); @@ -254,6 +254,7 @@ describe('Invoices', () => { expect(res.cursor).to.eql('cursor=='); expect(res.has_more).to.eql(false); }); + done(); }); it('should delete an invoice', () => { diff --git a/test/chartmogul/metrics/activity.js b/test/chartmogul/metrics/activity.js index b4eb9d1..a17f143 100644 --- a/test/chartmogul/metrics/activity.js +++ b/test/chartmogul/metrics/activity.js @@ -23,11 +23,11 @@ describe('Activity', () => { expect(e).to.be.instanceOf(ChartMogul.DeprecatedParamError); expect(e.httpStatus).to.equal(422); expect(e.message).to.equal('"page" param is deprecated {}'); - done(); }); + done(); }); - it('should retrieve all activities with pagination', () => { + it('should retrieve all activities with pagination', done => { const query = { 'start-date': '2020-01-01', per_page: 1, @@ -59,12 +59,13 @@ describe('Activity', () => { has_more: false, cursor: 'cursor==' }); - return Activity.all(config, query) + Activity.all(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res.has_more).to.eql(false); expect(res.cursor).to.eql('cursor=='); }); + done(); }); }); diff --git a/test/chartmogul/metrics/index.js b/test/chartmogul/metrics/index.js index c687aed..67cfc77 100644 --- a/test/chartmogul/metrics/index.js +++ b/test/chartmogul/metrics/index.js @@ -7,7 +7,7 @@ const nock = require('nock'); const Metrics = ChartMogul.Metrics; describe('Metrics', () => { - it('should retrieve all key metrics', () => { + it('should retrieve all key metrics', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24', @@ -146,14 +146,15 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.all(config, query) + Metrics.all(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); }); + done(); }); - it('should retrieve MRR', () => { + it('should retrieve MRR', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24', @@ -178,15 +179,16 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.mrr(config, query) + Metrics.mrr(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res).to.have.property('summary'); }); + done(); }); - it('should retrieve ARR', () => { + it('should retrieve ARR', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24', @@ -204,15 +206,16 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.arr(config, query) + Metrics.arr(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res).to.have.property('summary'); }); + done(); }); - it('should retrieve ARPA', () => { + it('should retrieve ARPA', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24', @@ -229,15 +232,16 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.arpa(config, query) + Metrics.arpa(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res).to.have.property('summary'); }); + done(); }); - it('should retrieve ASP', () => { + it('should retrieve ASP', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24', @@ -254,15 +258,16 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.asp(config, query) + Metrics.asp(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res).to.have.property('summary'); }); + done(); }); - it('should retrieve Customer Count', () => { + it('should retrieve Customer Count', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24', @@ -279,15 +284,16 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.customerCount(config, query) + Metrics.customerCount(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res).to.have.property('summary'); }); + done(); }); - it('should retrieve Customer Churn Rate', () => { + it('should retrieve Customer Churn Rate', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24' @@ -303,15 +309,16 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.customerChurnRate(config, query) + Metrics.customerChurnRate(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res).to.have.property('summary'); }); + done(); }); - it('should retrieve MRR Churn Rate', () => { + it('should retrieve MRR Churn Rate', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24' @@ -327,15 +334,16 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.mrrChurnRate(config, query) + Metrics.mrrChurnRate(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res).to.have.property('summary'); }); + done(); }); - it('should retrieve LTV', () => { + it('should retrieve LTV', done => { const query = { 'start-date': '2015-01-01', 'end-date': '2015-11-24' @@ -351,12 +359,13 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.ltv(config, query) + Metrics.ltv(config, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res).to.have.property('summary'); }); + done(); }); it('throws DeprecatedParamError if using old pagination parameter', done => { @@ -376,11 +385,11 @@ describe('Metrics', () => { expect(e).to.be.instanceOf(ChartMogul.DeprecatedParamError); expect(e.httpStatus).to.equal(422); expect(e.message).to.equal('"page" param is deprecated {}'); - done(); }); + done(); }); - it('should list customer activites with pagination', () => { + it('should list customer activites with pagination', done => { const customerUuid = 'cus_9bf6482d-01e5-4944-957d-5bc730d2cda3'; const query = { cursor: 'cursor==' }; @@ -405,16 +414,17 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.Customer.activities(config, customerUuid, query) + Metrics.Customer.activities(config, customerUuid, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res.has_more).to.eql(false); expect(res.cursor).to.eql('cursor=='); }); + done(); }); - it('should list customer subscriptions with pagination', () => { + it('should list customer subscriptions with pagination', done => { const customerUuid = 'cus_9bf6482d-01e5-4944-957d-5bc730d2cda3'; const query = { cursor: 'cursor==', per_page: 200 }; @@ -443,12 +453,13 @@ describe('Metrics', () => { /* eslint-enable camelcase */ }); - return Metrics.Customer.subscriptions(config, customerUuid, query) + Metrics.Customer.subscriptions(config, customerUuid, query) .then(res => { expect(res).to.have.property('entries'); expect(res.entries).to.be.instanceof(Array); expect(res.cursor).to.eql('cursor=='); expect(res.per_page).to.eql(200); }); + done(); }); }); diff --git a/test/chartmogul/resource.js b/test/chartmogul/resource.js index 62b9d8e..e266931 100644 --- a/test/chartmogul/resource.js +++ b/test/chartmogul/resource.js @@ -30,9 +30,9 @@ describe('Resource', () => { 401: 'ForbiddenError', 403: 'ForbiddenError', 404: 'NotFoundError', - 422: 'ResourceInvalidError', 500: 'ChartMogulError' }; + Object.keys(errorCodes).forEach(function (code) { it(`should throw ${errorCodes[code]}`, done => { nock(config.API_BASE) @@ -45,8 +45,8 @@ describe('Resource', () => { expect(e).to.be.instanceOf(ChartMogul[errorCodes[code]]); expect(e.httpStatus).to.equal(Number(code)); expect(e.response).to.equal('error message'); - done(); }); + done(); }); }); @@ -61,11 +61,11 @@ describe('Resource', () => { expect(err).to.be.instanceOf(ChartMogul[errorCodes[code]]); expect(err.httpStatus).to.equal(Number(code)); expect(err.response).to.equal('error message'); - done(); } else { done(new Error('Should throw error')); } }); + done(); }); }); @@ -78,8 +78,8 @@ describe('Resource', () => { .then(res => done(new Error('Should throw error'))) .catch(e => { expect(e).to.be.instanceOf(Error); - done(); }); + done(); }); it('should throw ResourceInvalidError', done => { @@ -96,8 +96,8 @@ describe('Resource', () => { expect(e.message).to.equal( 'The Customer could not be created or updated. {"error":"message"}' ); - done(); }); + done(); }); it('should throw ConfigurationError', done => { @@ -105,8 +105,8 @@ describe('Resource', () => { .then(res => done(new Error('Should throw error'))) .catch(e => { expect(e).to.be.instanceOf(ChartMogul.ConfigurationError); - done(); }); + done(); }); }); @@ -118,35 +118,41 @@ describe('Resource Retry', () => { ); let server, status, retry; + config.retries = 1; + before(done => { server = startMockServer(done); }); after(done => server.close(done)); - it('should retry if status 429 is received', () => { + it('should retry if status 429 is received', done => { retry = 1; status = 429; - return Customer.all(config).then(res => { + Customer.all(config).then(res => { expect(res).to.be.eql('ok'); expect(retry).to.be.eql(0); }); + done(); }); - it('should retry if status 500 is received', () => { + + it('should retry if status 500 is received', done => { retry = 1; status = 500; - return Customer.all(config).then(res => { + Customer.all(config).then(res => { expect(res).to.be.eql('ok'); expect(retry).to.be.eql(0); }); + done(); }); - it('should retry on ECONNRESET', () => { + it('should retry on ECONNRESET', done => { retry = 1; status = 0; - return Customer.all(config).then(res => { + Customer.all(config).then(res => { expect(res).to.be.eql('ok'); expect(retry).to.be.eql(0); }); + done(); }); // mock server used to send server errors to let the client retry