resourcerer 2.0.6 → 2.0.7

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/build/lib/sync.js CHANGED
@@ -14,7 +14,7 @@ export default function (model, options = {}) {
14
14
  });
15
15
  }
16
16
  export function ajax(options) {
17
- const hasParams = !!Object.keys(options.params).length;
17
+ const hasParams = options.params instanceof FormData || !!Object.keys(options.params).length;
18
18
  const hasBodyContent = !/^(?:GET|HEAD)$/.test(options.method || "") && hasParams;
19
19
  const startTime = Date.now();
20
20
  const onRequestComplete = (json, response) => {
@@ -42,7 +42,8 @@ export function ajax(options) {
42
42
  },
43
43
  ...(hasBodyContent ?
44
44
  {
45
- body: typeof options.params === "string" ? options.params
45
+ body: typeof options.params === "string" || options.params instanceof FormData ?
46
+ options.params
46
47
  : options.contentType === MIME_TYPE_JSON ? JSON.stringify(options.params)
47
48
  : ResourcesConfig.stringify(options.params, options),
48
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resourcerer",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "github.com/noahgrant/resourcerer"
package/test/sync.test.js CHANGED
@@ -83,6 +83,16 @@ describe("sync", () => {
83
83
  await library.at(0).save(null, { params: { a: "a", one: 1 }, contentType: "resourcerer/json" });
84
84
  expect(window.fetch.mock.calls[0][0]).toEqual("/library");
85
85
  expect(window.fetch.mock.calls[0][1].body).toEqual("a=a&one=1");
86
+ window.fetch.mockClear();
87
+
88
+ // with body content: FormData
89
+ const formData = new FormData();
90
+
91
+ formData.append("a", 1);
92
+
93
+ await library.at(0).save(null, { params: formData, contentType: "multipart/form-data" });
94
+ expect(window.fetch.mock.calls[0][0]).toEqual("/library");
95
+ expect(window.fetch.mock.calls[0][1].body).toEqual(formData);
86
96
  });
87
97
 
88
98
  it("passes urlOptions to the model to formulate the url path", async () => {