mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-25 01:41:05 -05:00
Added tests for http-request-body
This commit is contained in:
parent
e56d98a91b
commit
95d5b56158
1 changed files with 78 additions and 0 deletions
78
tests/unit/utils/net/http-request-body.spec.ts
Normal file
78
tests/unit/utils/net/http-request-body.spec.ts
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
import { Readable } from "node:stream";
|
||||||
|
import { Blob } from "@/utils/net/blob";
|
||||||
|
import { isHttpRequestBody, isStreamableHttpRequestBody } from "@/utils/net/http-request-body";
|
||||||
|
|
||||||
|
describe("isHttpRequestBody", () => {
|
||||||
|
test("returns true when body is a string", () => {
|
||||||
|
const body = "string body";
|
||||||
|
|
||||||
|
expect(isHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns true when body is a Blob", () => {
|
||||||
|
const body = new Blob(["blob content"]);
|
||||||
|
|
||||||
|
expect(isHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns true when body is a Buffer", () => {
|
||||||
|
const body = Buffer.from("buffer content");
|
||||||
|
|
||||||
|
expect(isHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns true when body is a URLSearchParams", () => {
|
||||||
|
const body = new URLSearchParams({ param: "value" });
|
||||||
|
|
||||||
|
expect(isHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns true when body is a FormData", () => {
|
||||||
|
const body = new FormData();
|
||||||
|
body.append("key", "value");
|
||||||
|
|
||||||
|
expect(isHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns true when body is a ReadableStream", () => {
|
||||||
|
const body = Readable.from("stream content");
|
||||||
|
|
||||||
|
expect(isHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns false when body is not a valid HTTP request body type", () => {
|
||||||
|
expect(isHttpRequestBody({ key: "value" })).toBe(false);
|
||||||
|
expect(isHttpRequestBody(["foo"])).toBe(false);
|
||||||
|
expect(isHttpRequestBody(null)).toBe(false);
|
||||||
|
expect(isHttpRequestBody(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("isStreamableHttpRequestBody", () => {
|
||||||
|
test("returns true when body is a Blob", () => {
|
||||||
|
const body = new Blob(["blob content"]);
|
||||||
|
|
||||||
|
expect(isStreamableHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns true when body is a Buffer", () => {
|
||||||
|
const body = Buffer.from("buffer content");
|
||||||
|
|
||||||
|
expect(isStreamableHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns true when body is a ReadableStream", () => {
|
||||||
|
const body = Readable.from("stream content");
|
||||||
|
|
||||||
|
expect(isStreamableHttpRequestBody(body)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns false when body is not a valid streamable HTTP request body type", () => {
|
||||||
|
expect(isStreamableHttpRequestBody({ key: "value" })).toBe(false);
|
||||||
|
expect(isStreamableHttpRequestBody(["foo"])).toBe(false);
|
||||||
|
expect(isStreamableHttpRequestBody("string body")).toBe(false);
|
||||||
|
expect(isStreamableHttpRequestBody(new URLSearchParams({ param: "value" }))).toBe(false);
|
||||||
|
expect(isStreamableHttpRequestBody(null)).toBe(false);
|
||||||
|
expect(isStreamableHttpRequestBody(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue