chore: tests for hoppscotch-cli (#2300)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { HoppCLIError } from "../../../types/errors";
|
||||
import { checkFilePath } from "../../../utils/checks";
|
||||
|
||||
describe("checkFilePath", () => {
|
||||
test("File doesn't exists.", () => {
|
||||
return expect(
|
||||
checkFilePath("./src/samples/this-file-not-exists.json")()
|
||||
).resolves.toSubsetEqualLeft(<HoppCLIError>{
|
||||
code: "FILE_NOT_FOUND",
|
||||
});
|
||||
});
|
||||
|
||||
test("File not of JSON type.", () => {
|
||||
return expect(
|
||||
checkFilePath("./src/__tests__/samples/notjson.txt")()
|
||||
).resolves.toSubsetEqualLeft(<HoppCLIError>{
|
||||
code: "FILE_NOT_JSON",
|
||||
});
|
||||
});
|
||||
|
||||
test("Existing JSON file.", () => {
|
||||
return expect(
|
||||
checkFilePath("./src/__tests__/samples/passes.json")()
|
||||
).resolves.toBeRight();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { isHoppCLIError } from "../../../utils/checks";
|
||||
|
||||
describe("isHoppCLIError", () => {
|
||||
test("NULL error value.", () => {
|
||||
expect(isHoppCLIError(null)).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Non-existing code property.", () => {
|
||||
expect(isHoppCLIError({ name: "name" })).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Invalid code value.", () => {
|
||||
expect(isHoppCLIError({ code: 2 })).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Valid code value.", () => {
|
||||
expect(isHoppCLIError({ code: "TEST_SCRIPT_ERROR" })).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { isHoppErrnoException } from "../../../utils/checks";
|
||||
|
||||
describe("isHoppErrnoException", () => {
|
||||
test("NULL exception value.", () => {
|
||||
expect(isHoppErrnoException(null)).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Non-existing name property.", () => {
|
||||
expect(isHoppErrnoException({ what: "what" })).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Invalid name value.", () => {
|
||||
expect(isHoppErrnoException({ name: 3 })).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Valid name value.", () => {
|
||||
expect(isHoppErrnoException({ name: "name" })).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,84 @@
|
||||
import { isRESTCollection } from "../../../utils/checks";
|
||||
|
||||
describe("isRESTCollection", () => {
|
||||
test("Undefined collection value.", () => {
|
||||
expect(isRESTCollection(undefined)).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Invalid id value.", () => {
|
||||
expect(
|
||||
isRESTCollection({
|
||||
v: 1,
|
||||
name: "test",
|
||||
id: 1,
|
||||
})
|
||||
).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Invalid requests value.", () => {
|
||||
expect(
|
||||
isRESTCollection({
|
||||
v: 1,
|
||||
name: "test",
|
||||
id: "1",
|
||||
requests: null,
|
||||
})
|
||||
).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Invalid folders value.", () => {
|
||||
expect(
|
||||
isRESTCollection({
|
||||
v: 1,
|
||||
name: "test",
|
||||
id: "1",
|
||||
requests: [],
|
||||
folders: undefined,
|
||||
})
|
||||
).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Invalid RESTCollection(s) in folders.", () => {
|
||||
expect(
|
||||
isRESTCollection({
|
||||
v: 1,
|
||||
name: "test",
|
||||
id: "1",
|
||||
requests: [],
|
||||
folders: [
|
||||
{
|
||||
v: 1,
|
||||
name: "test1",
|
||||
id: "2",
|
||||
requests: undefined,
|
||||
folders: [],
|
||||
},
|
||||
],
|
||||
})
|
||||
).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Invalid HoppRESTRequest(s) in requests.", () => {
|
||||
expect(
|
||||
isRESTCollection({
|
||||
v: 1,
|
||||
name: "test",
|
||||
id: "1",
|
||||
requests: [{}],
|
||||
folders: [],
|
||||
})
|
||||
).toBeFalsy();
|
||||
});
|
||||
|
||||
test("Valid RESTCollection.", () => {
|
||||
expect(
|
||||
isRESTCollection({
|
||||
v: 1,
|
||||
name: "test",
|
||||
id: "1",
|
||||
requests: [],
|
||||
folders: [],
|
||||
})
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user