Skip to content

Commit

Permalink
Fix body must be passed as "json" in Got 11
Browse files Browse the repository at this point in the history
  • Loading branch information
exacs committed Feb 10, 2021
1 parent d64e5d2 commit 092f1c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.env
.log

# VS Code specific
.vscode
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = class CanvasAPI {
try {
const result = await this.gotClient(endpoint, {
method,
body,
json: body,
...options,
});

Expand Down
14 changes: 14 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ test("List can handle pagination urls with query strings", async (t) => {
t.is(result.value, "correct");
});

test("requestUrl parses the `body` as JSON automatically", async (t) => {
const server = await createTestServer();

server.post("/endpoint", (req, res) => {
res.send(req.body);
});

const canvas = new Canvas(server.url, "");

const { body } = await canvas.requestUrl("endpoint", "POST", { foo: "bar" });

t.deepEqual(body, { foo: "bar" });
});

test("sendSis fails when file is missing", async (t) => {
const canvas = new Canvas("https://example.instructure.com", "Token");
await t.throwsAsync(() =>
Expand Down

0 comments on commit 092f1c7

Please sign in to comment.