-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openapi-fetch): add support for arbitrary method
- Loading branch information
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-fetch": minor | ||
--- | ||
|
||
add support for arbitrary method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { createObservedClient } from "../helpers.js"; | ||
import type { paths as get_paths } from "./schemas/get.js"; | ||
import type { paths as post_paths } from "./schemas/post.js"; | ||
|
||
describe("request", () => { | ||
test("sends correct method", async () => { | ||
let method = ""; | ||
const client = createObservedClient<get_paths>({}, async (req) => { | ||
method = req.method; | ||
return Response.json({}); | ||
}); | ||
|
||
await client.request('get', '/posts') | ||
expect(method).toBe("GET"); | ||
}); | ||
|
||
test("sends correct method with params", async () => { | ||
let method = ""; | ||
const client = createObservedClient<post_paths>({}, async (req) => { | ||
method = req.method; | ||
return Response.json({}); | ||
}); | ||
|
||
await client.request('post', "/posts", { | ||
body: { title: "My Post", body: "Post body", publish_date: new Date("2024-06-06T12:00:00Z").getTime() }, | ||
}); | ||
|
||
expect(method).toBe("OPTIONS"); | ||
}); | ||
}); |