Skip to content

Commit

Permalink
Forward "category" on file uploads
Browse files Browse the repository at this point in the history
refs MAT-631

Test Plan
- Check out this commit, g/283585 (canvas), and g/283594 (canvas)
- In Canvas, create a button & icon
- In Canvas rails console, inspect the Attachment record created
  for the button & icon
- Verify the category of the attachment is "buttons_and_icons"

Change-Id: Icb851ebcbb5a5fdace0b39d2d82b938d090fb459
Reviewed-on: https://gerrit.instructure.com/c/canvas-rce-api/+/283596
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Joe Hernandez <[email protected]>
QA-Review: Joe Hernandez <[email protected]>
Product-Review: Weston Dransfield <[email protected]>
  • Loading branch information
westonkd committed Jan 26, 2022
1 parent d47a9cb commit d40f142
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
3 changes: 2 additions & 1 deletion app/api/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function transformBody(body) {
contentType: body.file.type || body.file.contentType || undefined,
parent_folder_id: body.file.parentFolderId,
on_duplicate: body.onDuplicate || "rename",
success_include: ["preview_url"]
success_include: ["preview_url"],
category: body.category || undefined,
};

return canvasUploadPreflightBody;
Expand Down
56 changes: 37 additions & 19 deletions test/service/api/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const sinon = require("sinon");
const {
canvasPath,
canvasResponseHandler,
transformBody
transformBody,
} = require("../../../app/api/upload");

describe("Upload API", () => {
Expand All @@ -14,8 +14,8 @@ describe("Upload API", () => {
const path = canvasPath({
body: {
contextType: "course",
contextId: 47
}
contextId: 47,
},
});
assert(path === `/api/v1/courses/47/files`);
});
Expand All @@ -24,8 +24,8 @@ describe("Upload API", () => {
const path = canvasPath({
body: {
contextType: "group",
contextId: 47
}
contextId: 47,
},
});
assert(path === `/api/v1/groups/47/files`);
});
Expand All @@ -34,8 +34,8 @@ describe("Upload API", () => {
const path = canvasPath({
body: {
contextType: "user",
contextId: 47
}
contextId: 47,
},
});
assert(path === `/api/v1/users/47/files`);
});
Expand All @@ -47,15 +47,15 @@ describe("Upload API", () => {
beforeEach(() => {
request = {
protocol: "http",
get: () => "canvashost"
get: () => "canvashost",
};
response = {
status: sinon.spy(),
send: sinon.spy()
send: sinon.spy(),
};
canvasResponse = {
status: 200,
body: []
body: [],
};
});

Expand All @@ -77,19 +77,19 @@ describe("Upload API", () => {
name: "filename",
size: 42,
type: "jpeg",
parentFolderId: 1
parentFolderId: 1,
},
...overrides
...overrides,
};
}

it("reshapes the body to the format canvas wants", () => {
const fixed = transformBody(getBody({onDuplicate: 'overwrite'}));
const fixed = transformBody(getBody({ onDuplicate: "overwrite" }));
assert.equal(fixed.name, "filename");
assert.equal(fixed.size, 42);
assert.equal(fixed.contentType, "jpeg");
assert.equal(fixed.parent_folder_id, 1);
assert.equal(fixed.on_duplicate, 'overwrite')
assert.equal(fixed.on_duplicate, "overwrite");
});

it("renames files on duplicate instead of overwriting them", () => {
Expand All @@ -111,13 +111,31 @@ describe("Upload API", () => {
});

describe('when "onDuplicate" is undefined', () => {
const overrides = {onDuplicate: undefined}
const overrides = { onDuplicate: undefined };

const subject = () => transformBody(getBody(overrides))
const subject = () => transformBody(getBody(overrides));

it('defaults duplication strategy to "rename"', () => {
assert.equal(subject().on_duplicate, 'rename')
})
})
assert.equal(subject().on_duplicate, "rename");
});
});

describe('when "category" is specified', () => {
const overrides = { category: "buttons_and_icons" };

const subject = () => transformBody(getBody(overrides));

it("sets the category in the body", () => {
assert.equal(subject().category, "buttons_and_icons");
});
});

describe('when "category" is not specified', () => {
const subject = () => transformBody(getBody());

it("sets the category in the body", () => {
assert.equal(subject().category, undefined);
});
});
});
});

0 comments on commit d40f142

Please sign in to comment.