1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import chai = require("chai");
|
7 | import "mocha";
|
8 | import { ResponseTemplate } from "../src/responsetemplate";
|
9 |
|
10 | const expect = chai.expect;
|
11 |
|
12 | describe("ResponseTemplate class", function () {
|
13 | this.slow(1000);
|
14 |
|
15 | describe("#.constructor", () => {
|
16 | it("check instance [raw empty string]", () => {
|
17 | const tpl = new ResponseTemplate("");
|
18 | expect(tpl.getCode()).to.equal(423);
|
19 | expect(tpl.getDescription()).to.equal("Empty API response. Probably unreachable API end point {CONNECTION_URL}");
|
20 | });
|
21 |
|
22 | it("check template `invalid` being returned", () => {
|
23 | const tpl = new ResponseTemplate("[RESPONSE]\r\ncode=200\r\nqueuetime=0\r\nEOF\r\n");
|
24 | expect(tpl.getCode()).to.equal(423);
|
25 | expect(tpl.getDescription()).to.equal("Invalid API response. Contact Support");
|
26 | });
|
27 | });
|
28 |
|
29 | describe("#.getHash", () => {
|
30 | it("check return value", () => {
|
31 | const h = new ResponseTemplate("").getHash();
|
32 | expect(h.CODE).to.equal("423");
|
33 | expect(h.DESCRIPTION).to.equal("Empty API response. Probably unreachable API end point {CONNECTION_URL}");
|
34 | });
|
35 | });
|
36 |
|
37 | describe("#.getQueuetime", () => {
|
38 | it("check return value [n/a in API response]", () => {
|
39 | const tpl = new ResponseTemplate("");
|
40 | expect(tpl.getQueuetime()).to.equal(0);
|
41 | });
|
42 |
|
43 | it("check return value [in API response]", () => {
|
44 | const tpl = new ResponseTemplate("[RESPONSE]\r\ncode=423\r\ndescription=Empty API response. Probably unreachable API end point\r\nqueuetime=0\r\nEOF\r\n");
|
45 | expect(tpl.getQueuetime()).to.equal(0);
|
46 | });
|
47 | });
|
48 |
|
49 | describe("#.getRuntime", () => {
|
50 | it("check return value [n/a in API response]", () => {
|
51 | const tpl = new ResponseTemplate("");
|
52 | expect(tpl.getRuntime()).to.equal(0);
|
53 | });
|
54 |
|
55 | it("check return value [in API response]", () => {
|
56 | const tpl = new ResponseTemplate("[RESPONSE]\r\ncode=423\r\ndescription=Empty API response. Probably unreachable API end point\r\nruntime=0.12\r\nEOF\r\n");
|
57 | expect(tpl.getRuntime()).to.equal(0.12);
|
58 | });
|
59 | });
|
60 |
|
61 | describe("#.isPending", () => {
|
62 | it("check return value [n/a in API response]", () => {
|
63 | const tpl = new ResponseTemplate("");
|
64 | expect(tpl.isPending()).to.be.false;
|
65 | });
|
66 |
|
67 | it("check return value [in API response]", () => {
|
68 | const tpl = new ResponseTemplate("[RESPONSE]\r\ncode=200\r\ndescription=Command completed successfully\r\npending=1\r\nEOF\r\n");
|
69 | expect(tpl.isPending()).to.be.true;
|
70 | });
|
71 | });
|
72 | });
|