Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Mar 20, 2024
1 parent d5ba01b commit 0ac987f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 142 deletions.
Expand Up @@ -72,6 +72,7 @@ describe("Test `hopp test <file>` command:", () => {
{ fileName: "coll-v1-req-v0.json", collVersion: 1, reqVersion: 0 },
{ fileName: "coll-v1-req-v1.json", collVersion: 1, reqVersion: 1 },
{ fileName: "coll-v2-req-v2.json", collVersion: 2, reqVersion: 2 },
{ fileName: "coll-v2-req-v3.json", collVersion: 2, reqVersion: 3 },
];

testFixtures.forEach(({ collVersion, fileName, reqVersion }) => {
Expand Down

This file was deleted.

@@ -0,0 +1,54 @@
{
"v": 2,
"name": "coll-v2",
"folders": [],
"requests": [
{
"v": "3",
"endpoint": "https://httpbin.org/get",
"headers": [
{
"key": "Inactive-Header",
"value": "Inactive Header",
"active": false
},
{
"key": "Authorization",
"value": "Bearer token123",
"active": true
}
],
"params": [
{
"key": "key",
"value": "value",
"active": true
},
{
"key": "inactive-key",
"value": "inactive-param",
"active": false
}
],
"name": "req-v3",
"method": "GET",
"preRequestScript": "",
"testScript": "pw.test(\"Asserts request params\", () => {\n pw.expect(pw.response.body.args.key).toBe(\"value\")\n pw.expect(pw.response.body.args[\"inactive-key\"]).toBe(undefined)\n})\n\npw.test(\"Asserts request headers\", () => {\n pw.expect(pw.response.body.headers[\"Authorization\"]).toBe(\"Bearer token123\")\n pw.expect(pw.response.body.headers[\"Inactive-Header\"]).toBe(undefined)\n})",
"body": {
"contentType": null,
"body": null
},
"auth": {
"authType": "bearer",
"authActive": true,
"token": "token123"
},
"requestVariables": []
}
],
"auth": {
"authType": "inherit",
"authActive": true
},
"headers": []
}
44 changes: 0 additions & 44 deletions packages/hoppscotch-cli/src/utils/checks.ts
@@ -1,5 +1,3 @@
import { HoppCollection, isHoppRESTRequest } from "@hoppscotch/data";
import * as A from "fp-ts/Array";
import { CommanderError } from "commander";
import { HoppCLIError, HoppErrnoException } from "../types/errors";

Expand All @@ -14,48 +12,6 @@ export const hasProperty = <P extends PropertyKey>(
prop: P
): target is Record<P, unknown> => prop in target;

/**
* Typeguard to check valid Hoppscotch REST Collection.
* @param param The object to be checked.
* @returns True, if unknown parameter is valid Hoppscotch REST Collection;
* False, otherwise.
*/
export const isRESTCollection = (param: unknown): param is HoppCollection => {
if (!!param && typeof param === "object") {
if (!hasProperty(param, "v") || typeof param.v !== "number") {
return false;
}
if (!hasProperty(param, "name") || typeof param.name !== "string") {
return false;
}
if (hasProperty(param, "id") && typeof param.id !== "string") {
return false;
}
if (!hasProperty(param, "requests") || !Array.isArray(param.requests)) {
return false;
} else {
// Checks each requests array to be valid HoppRESTRequest.
const checkRequests = A.every(isHoppRESTRequest)(param.requests);
if (!checkRequests) {
return false;
}
}
if (!hasProperty(param, "folders") || !Array.isArray(param.folders)) {
return false;
} else {
// Checks each folder to be valid REST collection.
const checkFolders = A.every(isRESTCollection)(param.folders);
if (!checkFolders) {
return false;
}
}

return true;
}

return false;
};

/**
* Checks if given error data is of type HoppCLIError, based on existence
* of code property.
Expand Down
20 changes: 7 additions & 13 deletions packages/hoppscotch-cli/src/utils/mutators.ts
@@ -1,18 +1,11 @@
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data";
import fs from "fs/promises";
import { FormDataEntry } from "../types/request";
import { error } from "../types/errors";
import { isRESTCollection, isHoppErrnoException } from "./checks";
import {
GQLHeader,
HoppCollection,
HoppGQLAuth,
HoppGQLRequest,
HoppRESTAuth,
HoppRESTHeaders,
HoppRESTRequest,
} from "@hoppscotch/data";
import { z } from "zod";
import { entityReference } from "verzod";
import { z } from "zod";

import { error } from "../types/errors";
import { FormDataEntry } from "../types/request";
import { isHoppErrnoException } from "./checks";

/**
* Parses array of FormDataEntry to FormData.
Expand Down Expand Up @@ -93,6 +86,7 @@ export async function parseCollectionData(
const requestSchemaParsedResult = z
.array(entityReference(HoppRESTRequest))
.safeParse(collection.requests);

if (!requestSchemaParsedResult.success) {
throw error({
code: "MALFORMED_COLLECTION",
Expand Down
1 change: 0 additions & 1 deletion packages/hoppscotch-data/src/collection/index.ts
Expand Up @@ -8,7 +8,6 @@ import { translateToNewRequest } from "../rest"
import { translateToGQLRequest } from "../graphql"

const versionedObject = z.object({
// v is a stringified number
v: z.number(),
})

Expand Down

0 comments on commit 0ac987f

Please sign in to comment.