Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #16 from OpenFn/better-test
Browse files Browse the repository at this point in the history
Better test
Closes #13
stuartc authored Jan 19, 2021
2 parents 880a608 + 094bcc2 commit 6392340
Showing 10 changed files with 1,404 additions and 1,974 deletions.
12 changes: 10 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"plugins": ["@babel/plugin-proposal-function-bind"],
"presets": ["@babel/preset-env"]
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10"
}
}
]
]
}
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
language: node_js
node_js:
- node # Current stable, i.e. 13 in October, 2019
- lts/* # Most recent LTS version, i.e. 12 in October, 2019
- 10 # Explicitly include an active LTS version
- 8 # Explicitly include the maintenance LTS version
- 14
- 12
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -4,4 +4,4 @@ LIB = $(SRC:src/%.js=lib/%.js)
lib: $(LIB)
lib/%.js: src/%.js
mkdir -p $(@D)
babel $< -o $@
./node_modules/.bin/babel $< -o $@
296 changes: 143 additions & 153 deletions lib/Adaptor.js

Large diffs are not rendered by default.

69 changes: 31 additions & 38 deletions lib/Client.js
Original file line number Diff line number Diff line change
@@ -10,67 +10,60 @@ var _request = _interopRequireDefault(require("request"));

var _Utils = require("./Utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function rawRequest(params) {
return new Promise(function (resolve, reject) {
(0, _request["default"])(params, function (error, response, body) {
return new Promise((resolve, reject) => {
(0, _request.default)(params, (error, response, body) => {
error = (0, _Utils.assembleError)({
error: error,
response: response,
params: params
error,
response,
params
});
error && reject(error);
console.log("\u2713 Request succeeded. (The response body will be available in state.)");
var resp = (0, _Utils.tryJson)(body);
console.log(`✓ Request succeeded. (The response body will be available in state.)`);
const resp = (0, _Utils.tryJson)(body);
resolve(resp);
});
});
}

function req(method, params) {
var body = params.body,
query = params.query,
rest = _objectWithoutProperties(params, ["body", "query"]);

return new Promise(function (resolve, reject) {
var j = _request["default"].jar();

(0, _request["default"])(_objectSpread({
const {
body,
query,
...rest
} = params;
return new Promise((resolve, reject) => {
const j = _request.default.jar();

(0, _request.default)({
jar: j,
json: body,
method: method,
qs: query
}, rest), function (error, response, body) {
qs: query,
...rest
}, function (error, response, body) {
error = (0, _Utils.assembleError)({
error: error,
response: response,
params: params
error,
response,
params
});

if (error) {
reject(error);
} else {
console.log("\u2713 ".concat(method, " succeeded. (The response body will be available in state.)"));
var resp = (0, _Utils.tryJson)(body);
console.log(`✓ ${method} succeeded. (The response body will be available in state.)`);
const resp = (0, _Utils.tryJson)(body);

if (rest.keepCookie) {
var __cookie = j.getCookieString(params.url);
const __cookie = j.getCookieString(params.url);

resolve(_objectSpread({
__cookie: __cookie,
__headers: response.headers
}, resp));
resolve({
__cookie,
__headers: response.headers,
...resp
});
} else {
resolve(resp);
}
14 changes: 7 additions & 7 deletions lib/Utils.js
Original file line number Diff line number Diff line change
@@ -20,18 +20,18 @@ function setAuth(configuration, manualAuth) {
};else return null;
}

function assembleError(_ref) {
var response = _ref.response,
error = _ref.error,
params = _ref.params;

function assembleError({
response,
error,
params
}) {
if (response) {
var customCodes = params.options && params.options.successCodes;
const customCodes = params.options && params.options.successCodes;
if ((customCodes || [200, 201, 202]).indexOf(response.statusCode) > -1) return false;
}

if (error) return error;
return new Error("Server responded with: \n".concat(JSON.stringify(response, null, 2)));
return new Error(`Server responded with: \n${JSON.stringify(response, null, 2)}`);
}

function tryJson(data) {
10 changes: 4 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Adaptor = exports["default"] = void 0;
exports.Adaptor = exports.default = void 0;

var Adaptor = _interopRequireWildcard(require("./Adaptor"));

exports.Adaptor = Adaptor;

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var _default = Adaptor;
exports["default"] = _default;
exports.default = _default;
2,514 changes: 806 additions & 1,708 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -22,17 +22,14 @@
"request": "^2.72.0"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/cli": "^7.12.10",
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-function-bind": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@babel/preset-stage-0": "^7.8.3",
"@babel/register": "^7.9.0",
"assertion-error": "^1.0.1",
"chai": "^3.4.0",
"deep-eql": "^0.1.3",
"mocha": "^7.1.1",
"nock": "^12.0.3",
"sinon": "^1.17.2"
"chai": "^4.2.0",
"deep-eql": "^4.0.0",
"mocha": "^7.1.0",
"nock": "^13.0.5",
"sinon": "^9.2.3"
}
}
440 changes: 394 additions & 46 deletions test/index.js

Large diffs are not rendered by default.

0 comments on commit 6392340

Please sign in to comment.