pentatrion-design 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/fetch.js CHANGED
@@ -25,12 +25,17 @@ export async function fetchAPI(urlObjOrString, enhancedOptions = {}, baseUrl, ba
25
25
  url.searchParams.set(name, typeof value === "object" ? JSON.stringify(value) : value.toString());
26
26
  }
27
27
  }
28
- if (body && typeof body !== "string" && !(body instanceof FormData)) {
29
- options.headers = {
30
- ...(options.headers = {}),
31
- "Content-Type": "application/json",
32
- };
33
- options.body = JSON.stringify(body);
28
+ if (body) {
29
+ if (typeof body !== "string" && !(body instanceof FormData)) {
30
+ options.headers = {
31
+ ...(options.headers = {}),
32
+ "Content-Type": "application/json",
33
+ };
34
+ options.body = JSON.stringify(body);
35
+ }
36
+ else {
37
+ options.body = body;
38
+ }
34
39
  }
35
40
  if (baseOptions) {
36
41
  const { headers: baseHeaders = {}, ...baseRest } = baseOptions;
package/lib/fetch.test.js CHANGED
@@ -81,4 +81,20 @@ describe("fetchAPI", () => {
81
81
  },
82
82
  });
83
83
  });
84
+ test("keep body unchanged if already stringified", async ({ expect }) => {
85
+ const mock = vi.fn().mockResolvedValue(get200Response());
86
+ vi.stubGlobal("fetch", mock);
87
+ await fetchAPI("/user", {
88
+ headers: {
89
+ "Content-Type": "x-www-form-urlencoded",
90
+ },
91
+ body: "name=dupond&id=3",
92
+ });
93
+ expect(mock).toHaveBeenCalledWith("http://localhost:3000/user", {
94
+ body: "name=dupond&id=3",
95
+ headers: {
96
+ "Content-Type": "x-www-form-urlencoded",
97
+ },
98
+ });
99
+ });
84
100
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pentatrion-design",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "Hugues Tavernier",