Skip to content

Commit 8c0b5e4

Browse files
Kyle KeatingLMS007
authored andcommitted
Fix error when returning non JSON strings
- longsummary must be a json string in all cases - In the generic error cases, we don’t need to pass the error object to the user as we already pass the message in the shortSummary. - Remove erroneous only from FakerGenerate.spec (TODO: need to update lint to catch these)
1 parent 5941bd9 commit 8c0b5e4

File tree

8 files changed

+30
-9
lines changed

8 files changed

+30
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rapidapi/testing-worker",
3-
"version": "0.0.26",
3+
"version": "0.0.27",
44
"description": "A RapidAPI Testing worker CLI",
55
"private": false,
66
"license": "MIT",

src/models/TestExecutable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class TestExecutable {
9292
action: action.action,
9393
success: false,
9494
shortSummary: e.message,
95-
longSummary: e,
95+
longSummary: null,
9696
time: 0,
9797
},
9898
];

src/models/actions/FakerGenerate.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe("FakerGenerate", () => {
113113
expect($result.actionReports[0].shortSummary).not.toContain("Invalid");
114114
});
115115

116-
it.only("should pass undefined for missing params", async () => {
116+
it("should pass undefined for missing params", async () => {
117117
let $action = new FakerGenerate({
118118
variable: "b",
119119
category: "date",

src/models/actions/LogicIf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class LogicIf extends BaseAction {
6969
action: "Logic.if",
7070
success: false,
7171
shortSummary: e.message,
72-
longSummary: e,
72+
longSummary: null,
7373
time: performance.now() - t0,
7474
},
7575
],

src/models/actions/LogicIf.spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,31 @@ describe("LogicIf", () => {
5757
};
5858
let $context = new Context({ varName: 815 });
5959
await $action.eval($context);
60-
6160
expect($action.children.eval.called).toBeFalsy();
6261
});
6362
});
6463

64+
it("should return an error if operator is invalid", async () => {
65+
let $action = new LogicIf({
66+
key: "a",
67+
operator: "not_valid",
68+
value: "a",
69+
});
70+
$action.children = {
71+
eval: sinon.fake.returns({ apiCalls: [], actionReports: [] }),
72+
};
73+
let $context = new Context({ varName: 815 });
74+
let $result = await $action.eval($context);
75+
76+
expect($result.actionReports.length).toBe(1);
77+
expect($result.actionReports[0].action).toBe("Logic.if");
78+
expect($result.actionReports[0].success).toBe(false);
79+
// eslint-disable-next-line no-useless-escape
80+
expect($result.actionReports[0].shortSummary).toBe('Testing for undefined operator "not_valid"');
81+
expect(typeof $result.actionReports[0].time).toBe("number");
82+
expect($result.actionReports[0].longSummary).toBe(null);
83+
});
84+
6585
describe("compare()", () => {
6686
describe("==", () => {
6787
it("should be true if values are equal", () => {

src/models/actions/LoopFor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class LoopForEach extends BaseAction {
2929
action: "Loop.forEach",
3030
success: false,
3131
shortSummary: `Object at ${this.parameters.expression} is not an array`,
32-
longSummary: `Expected an array, instead got ${typeof arr} with value: ${arr}`,
32+
longSummary: JSON.stringify({ summary: `Expected an array, instead got ${typeof arr} with value: ${arr}` }),
33+
//longSummary: null,
3334
time: performance.now() - t0,
3435
},
3536
],
@@ -55,7 +56,7 @@ class LoopForEach extends BaseAction {
5556
result.actionReports.unshift({
5657
action: "Loop.forEach",
5758
success: failedCount == 0,
58-
shortSummary: `Itterated over ${arr.length} elements in array ${this.parameters.expression}. ${
59+
shortSummary: `Iterated over ${arr.length} elements in array ${this.parameters.expression}. ${
5960
result.actionReports.length - failedCount
6061
}/${result.actionReports.length} steps passed.`,
6162
longSummary: null,

src/models/actions/LoopFor.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("LoopForEach", () => {
8080
expect($result.actionReports.length).toBe(1);
8181
expect($result.actionReports[0].action).toBe("Loop.forEach");
8282
expect($result.actionReports[0].success).toBe(false);
83-
83+
expect(typeof $result.actionReports[0].longSummary).toBe("string");
8484
expect($action.children.eval.callCount).toBe(0);
8585
});
8686
});

src/models/actions/MiscGroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MiscGroup extends BaseAction {
1818
action: "Misc.group",
1919
success: false,
2020
shortSummary: e.message,
21-
longSummary: e,
21+
longSummary: null,
2222
time: performance.now() - t0,
2323
},
2424
],

0 commit comments

Comments
 (0)