diff --git a/src/parse.ts b/src/parse.ts index b6e87378..73f824aa 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -81,8 +81,6 @@ export function parse(options: EndpointDefaults): RequestOptions { } else { if (Object.keys(remainingParameters).length) { body = remainingParameters; - } else { - headers["content-length"] = 0; } } } diff --git a/test/endpoint.test.ts b/test/endpoint.test.ts index 819ee089..633e5b50 100644 --- a/test/endpoint.test.ts +++ b/test/endpoint.test.ts @@ -144,7 +144,7 @@ describe("endpoint()", () => { }); }); - it("Put without request body", () => { + it("PUT without request body", () => { const options = endpoint("PUT /user/starred/{owner}/{repo}", { headers: { authorization: `token 0000000000000000000000000000000000000001`, @@ -154,15 +154,71 @@ describe("endpoint()", () => { }); expect(options).toEqual({ + body: "", method: "PUT", url: "https://api.github.com/user/starred/octocat/hello-world", headers: { authorization: `token 0000000000000000000000000000000000000001`, accept: "application/vnd.github.v3+json", - "content-length": 0, "user-agent": userAgent, }, + }); + }); + + it("DELETE without request body", () => { + const options = endpoint("DELETE /user/following/{username}", { + headers: { + authorization: `token 0000000000000000000000000000000000000001`, + }, + username: "octocat", + }); + + expect(options).toEqual({ + method: "DELETE", + url: "https://api.github.com/user/following/octocat", + headers: { + authorization: `token 0000000000000000000000000000000000000001`, + accept: "application/vnd.github.v3+json", + "user-agent": userAgent, + }, + }); + }); + + it("POST without request body", () => { + const options = endpoint("POST /widgets", { + headers: { + authorization: `token 0000000000000000000000000000000000000001`, + }, + }); + + expect(options).toEqual({ + method: "POST", + url: "https://api.github.com/widgets", + headers: { + authorization: `token 0000000000000000000000000000000000000001`, + accept: "application/vnd.github.v3+json", + "user-agent": userAgent, + }, + }); + }); + + it("PATCH without request body", () => { + const options = endpoint("PATCH /widgets/{id}", { + headers: { + authorization: `token 0000000000000000000000000000000000000001`, + }, + id: "my-widget", + }); + + expect(options).toEqual({ body: "", + method: "PATCH", + url: "https://api.github.com/widgets/my-widget", + headers: { + authorization: `token 0000000000000000000000000000000000000001`, + accept: "application/vnd.github.v3+json", + "user-agent": userAgent, + }, }); });