chore: tests for hoppscotch-cli (#2300)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Deepanshu Dhruw
2022-05-11 15:44:19 +05:30
committed by GitHub
parent d04520698d
commit 432337b801
30 changed files with 1919 additions and 155 deletions

View File

@@ -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();
});
});

View File

@@ -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();
});
});

View File

@@ -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();
});
});

View File

@@ -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();
});
});