feat: added support for passing env.json file to test cmd (#2373)

This commit is contained in:
Deepanshu Dhruw
2022-06-15 23:53:24 +05:30
committed by GitHub
parent 2d0bd48e00
commit 0244b941b3
20 changed files with 309 additions and 96 deletions

View File

@@ -1,10 +1,12 @@
import { HoppCLIError } from "../../../types/errors";
import { checkFilePath } from "../../../utils/checks";
import { checkFile } from "../../../utils/checks";
describe("checkFilePath", () => {
import "@relmify/jest-fp-ts";
describe("checkFile", () => {
test("File doesn't exists.", () => {
return expect(
checkFilePath("./src/samples/this-file-not-exists.json")()
checkFile("./src/samples/this-file-not-exists.json")()
).resolves.toSubsetEqualLeft(<HoppCLIError>{
code: "FILE_NOT_FOUND",
});
@@ -12,15 +14,15 @@ describe("checkFilePath", () => {
test("File not of JSON type.", () => {
return expect(
checkFilePath("./src/__tests__/samples/notjson.txt")()
checkFile("./src/__tests__/samples/notjson.txt")()
).resolves.toSubsetEqualLeft(<HoppCLIError>{
code: "FILE_NOT_JSON",
code: "INVALID_FILE_TYPE",
});
});
test("Existing JSON file.", () => {
return expect(
checkFilePath("./src/__tests__/samples/passes.json")()
checkFile("./src/__tests__/samples/passes.json")()
).resolves.toBeRight();
});
});

View File

@@ -37,6 +37,8 @@ const SAMPLE_RESOLVED_RESPONSE = <AxiosResponse>{
headers: [],
};
const SAMPLE_ENVS = { global: [], selected: [] };
describe("collectionsRunner", () => {
beforeEach(() => {
jest.clearAllMocks();
@@ -47,19 +49,24 @@ describe("collectionsRunner", () => {
});
test("Empty HoppCollection.", () => {
return expect(collectionsRunner([])()).resolves.toStrictEqual([]);
return expect(
collectionsRunner({ collections: [], envs: SAMPLE_ENVS })()
).resolves.toStrictEqual([]);
});
test("Empty requests and folders in collection.", () => {
return expect(
collectionsRunner([
{
v: 1,
name: "name",
folders: [],
requests: [],
},
])()
collectionsRunner({
collections: [
{
v: 1,
name: "name",
folders: [],
requests: [],
},
],
envs: SAMPLE_ENVS,
})()
).resolves.toMatchObject([]);
});
@@ -67,14 +74,17 @@ describe("collectionsRunner", () => {
(axios as unknown as jest.Mock).mockResolvedValue(SAMPLE_RESOLVED_RESPONSE);
return expect(
collectionsRunner([
{
v: 1,
name: "collection",
folders: [],
requests: [SAMPLE_HOPP_REQUEST],
},
])()
collectionsRunner({
collections: [
{
v: 1,
name: "collection",
folders: [],
requests: [SAMPLE_HOPP_REQUEST],
},
],
envs: SAMPLE_ENVS,
})()
).resolves.toMatchObject([
{
path: "collection/request",
@@ -89,21 +99,24 @@ describe("collectionsRunner", () => {
(axios as unknown as jest.Mock).mockResolvedValue(SAMPLE_RESOLVED_RESPONSE);
return expect(
collectionsRunner([
{
v: 1,
name: "collection",
folders: [
{
v: 1,
name: "folder",
folders: [],
requests: [SAMPLE_HOPP_REQUEST],
},
],
requests: [],
},
])()
collectionsRunner({
collections: [
{
v: 1,
name: "collection",
folders: [
{
v: 1,
name: "folder",
folders: [],
requests: [SAMPLE_HOPP_REQUEST],
},
],
requests: [],
},
],
envs: SAMPLE_ENVS,
})()
).resolves.toMatchObject([
{
path: "collection/folder/request",

View File

@@ -1,6 +1,8 @@
import { Environment } from "@hoppscotch/data";
import { getEffectiveFinalMetaData } from "../../../utils/getters";
import "@relmify/jest-fp-ts";
const DEFAULT_ENV = <Environment>{
name: "name",
variables: [{ key: "PARAM", value: "parsed_param" }],

View File

@@ -1,12 +1,14 @@
import { HoppCLIError } from "../../../types/errors";
import { parseCollectionData } from "../../../utils/mutators";
import "@relmify/jest-fp-ts";
describe("parseCollectionData", () => {
test("Reading non-existing file.", () => {
return expect(
parseCollectionData("./src/__tests__/samples/notexist.txt")()
parseCollectionData("./src/__tests__/samples/notexist.json")()
).resolves.toSubsetEqualLeft(<HoppCLIError>{
code: "UNKNOWN_ERROR",
code: "FILE_NOT_FOUND",
});
});

View File

@@ -3,6 +3,8 @@ import { EffectiveHoppRESTRequest } from "../../../interfaces/request";
import { HoppCLIError } from "../../../types/errors";
import { getEffectiveRESTRequest } from "../../../utils/pre-request";
import "@relmify/jest-fp-ts";
const DEFAULT_ENV = <Environment>{
name: "name",
variables: [