Generate Fern TypeSscript SDK (#3785)
This commit is contained in:
committed by
GitHub
parent
d55b9637c4
commit
2062adac66
53
skyvern-ts/client/tests/unit/fetcher/makeRequest.test.ts
Normal file
53
skyvern-ts/client/tests/unit/fetcher/makeRequest.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { makeRequest } from "../../../src/core/fetcher/makeRequest";
|
||||
|
||||
describe("Test makeRequest", () => {
|
||||
const mockPostUrl = "https://httpbin.org/post";
|
||||
const mockGetUrl = "https://httpbin.org/get";
|
||||
const mockHeaders = { "Content-Type": "application/json" };
|
||||
const mockBody = JSON.stringify({ key: "value" });
|
||||
|
||||
let mockFetch: import("vitest").Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
mockFetch = vi.fn();
|
||||
mockFetch.mockResolvedValue(new Response(JSON.stringify({ test: "successful" }), { status: 200 }));
|
||||
});
|
||||
|
||||
it("should handle POST request correctly", async () => {
|
||||
const response = await makeRequest(mockFetch, mockPostUrl, "POST", mockHeaders, mockBody);
|
||||
const responseBody = await response.json();
|
||||
expect(responseBody).toEqual({ test: "successful" });
|
||||
expect(mockFetch).toHaveBeenCalledTimes(1);
|
||||
const [calledUrl, calledOptions] = mockFetch.mock.calls[0];
|
||||
expect(calledUrl).toBe(mockPostUrl);
|
||||
expect(calledOptions).toEqual(
|
||||
expect.objectContaining({
|
||||
method: "POST",
|
||||
headers: mockHeaders,
|
||||
body: mockBody,
|
||||
credentials: undefined,
|
||||
}),
|
||||
);
|
||||
expect(calledOptions.signal).toBeDefined();
|
||||
expect(calledOptions.signal).toBeInstanceOf(AbortSignal);
|
||||
});
|
||||
|
||||
it("should handle GET request correctly", async () => {
|
||||
const response = await makeRequest(mockFetch, mockGetUrl, "GET", mockHeaders, undefined);
|
||||
const responseBody = await response.json();
|
||||
expect(responseBody).toEqual({ test: "successful" });
|
||||
expect(mockFetch).toHaveBeenCalledTimes(1);
|
||||
const [calledUrl, calledOptions] = mockFetch.mock.calls[0];
|
||||
expect(calledUrl).toBe(mockGetUrl);
|
||||
expect(calledOptions).toEqual(
|
||||
expect.objectContaining({
|
||||
method: "GET",
|
||||
headers: mockHeaders,
|
||||
body: undefined,
|
||||
credentials: undefined,
|
||||
}),
|
||||
);
|
||||
expect(calledOptions.signal).toBeDefined();
|
||||
expect(calledOptions.signal).toBeInstanceOf(AbortSignal);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user