omnipartners
Version:
Node.js wrapper for Omniparners API.
120 lines (119 loc) • 4.41 kB
JavaScript
;
/* eslint-env mocha */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const test_utils_1 = require("./test.utils");
const Api_1 = __importDefault(require("../lib/Api"));
const baseConfig = {
host: "http://httpbin.org",
key: "aaa",
secret: "bbb",
};
class TestApi extends Api_1.default {
constructor() {
super(...arguments);
this.defaultTimeout = 10;
}
basicGet(data) {
return this.get("/get", data);
}
}
class BaseIdentityTest {
constructor() {
this.Api = TestApi;
this.apiConfig = baseConfig;
}
}
class BasicGet extends BaseIdentityTest {
constructor() {
super(...arguments);
this.name = "basicGet";
this.httpPath = "/get";
this.httpMethod = "get";
this.httpDefaultData = {
hash: test_utils_1.REGEX_HASH,
key: baseConfig.key,
};
}
"handle invalid json"({ err }) {
expect(err).toMatchObject({
code: "OP/InvalidJSONReponseError",
data: {
text: "{ invalid json! }",
},
isOmnipartnersError: true,
message: "OP/Invalid JSON Reponse Error",
statusCode: 502,
statusText: "Bad Gateway",
});
}
"handle invalid opStatus"({ err }) {
expect(err).toMatchObject({
code: "OP/OPStatusError/2",
data: {
message: "Invalid request in which required header or parameters are either missing or invalid.",
statusCode: 2,
},
isOmnipartnersError: true,
message: "OP/Invalid request in which required header or parameters are either missing or invalid.",
statusCode: 502,
statusText: "Bad Gateway",
});
}
"handle unkown opStatus"({ err }) {
expect(err).toMatchObject({
code: "OP/UnknownOPStatusError/99",
data: {
statusCode: 99,
},
isOmnipartnersError: true,
message: "OP/Invalid Response Error - Unkown OP Status/99",
statusCode: 502,
statusText: "Bad Gateway",
});
}
"handle socket timeout"({ err }) {
expect(err).toMatchObject({
code: "OP/RequestTimeoutError",
data: {},
isOmnipartnersError: true,
message: "OP/Request Timeout Error",
statusCode: 503,
statusText: "Gateway Time-out",
});
}
"handle valid opStatus"({ err }) {
expect(err).toEqual(null);
}
}
__decorate([
(0, test_utils_1.withMock)({ reply: `{ invalid json! }` }),
(0, test_utils_1.withArguments)({}, { shouldThrow: true })
], BasicGet.prototype, "handle invalid json", null);
__decorate([
(0, test_utils_1.withMock)({ reply: { statusCode: 2 } }),
(0, test_utils_1.withArguments)({}, { shouldThrow: true })
], BasicGet.prototype, "handle invalid opStatus", null);
__decorate([
(0, test_utils_1.withMock)({ reply: { statusCode: 99 } }),
(0, test_utils_1.withArguments)({}, { shouldThrow: true })
], BasicGet.prototype, "handle unkown opStatus", null);
__decorate([
(0, test_utils_1.withMock)({ reply: {}, delay: { head: 99999 } }),
(0, test_utils_1.withArguments)({}, { shouldThrow: true })
], BasicGet.prototype, "handle socket timeout", null);
__decorate([
(0, test_utils_1.withMock)({ reply: { statusCode: 0, data: { foo: "bar" } } }),
(0, test_utils_1.withArguments)({})
], BasicGet.prototype, "handle valid opStatus", null);
(0, test_utils_1.describeApi)("Api", () => {
(0, test_utils_1.describeMethod)(BasicGet);
});