Skip to content

Commit

Permalink
Response for files list includes file category
Browse files Browse the repository at this point in the history
fixes MAT-987
flag=none

Test plan:
* The expectation is that the RCS should to be deployed ahead of
the canvas-related changes for this ticket. If the deploy does not
happen in that sequence - RCS before canvas - in canvas the Icon Maker
icons can still be added to the RCE but they get inserted as regular
images.

- Get this commit into your local canvas-rce-api repo and run it
-- Have the docker compose logs available to monitor for errors

- In the canvas-lms repo, using a recent version of master:
-- Go to an rce
-- Select "Saved Icon Maker Icons" from the toolbar menu
-- In the filter section at top, change "Icon Maker Icons" to "All"
-- Click on "Course files > Icon Maker Icons"
* VERIFY:
** No errors in Dev Tools > Console (canvas web page)
** No errors in canvas-rce-api logs
** No results returned for this folder

-- Now click on "Course files > Uploaded Media"
* VERIFY:
** No Console errors & no errors in canvas-rce-api logs
** This folder should return results if you have images uploaded

See also corresponding canvas-lms commit for test plan
https://gerrit.instructure.com/c/canvas-lms/+/302435

Change-Id: I472f50979aa02b3749228ee0f9a6bbaea382ad9d
Reviewed-on: https://gerrit.instructure.com/c/canvas-rce-api/+/302455
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Jake Oeding <[email protected]>
QA-Review: Jake Oeding <[email protected]>
Product-Review: Joe Hernandez <[email protected]>
  • Loading branch information
Joe Hernandez committed Oct 17, 2022
1 parent f104fbc commit a090093
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions app/api/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function canvasResponseHandler(request, response, canvasResponse) {
const files = canvasResponse.body;

response.send({
files: files.map((file) => {
files: files.map(file => {
return {
createdAt: file.created_at,
id: file.id,
Expand All @@ -38,9 +38,10 @@ function canvasResponseHandler(request, response, canvasResponse) {
folderId: file.folder_id,
iframeUrl: file.embedded_iframe_url,
thumbnailUrl: file.thumbnail_url || file.url,
category: file.category
};
}),
bookmark: packageBookmark(request, canvasResponse.bookmark),
bookmark: packageBookmark(request, canvasResponse.bookmark)
});
} else {
response.send(canvasResponse.body);
Expand Down
21 changes: 12 additions & 9 deletions test/service/api/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("Files API", () => {
const query = {
contextType: "course",
contextId: "nomatter",
per_page: 50,
per_page: 50
};
const expectedPath = `/api/v1/folders/${id}/files?per_page=50&include[]=preview_url&use_verifiers=0`;
assert.equal(canvasPath({ params, query }), expectedPath);
Expand All @@ -33,7 +33,7 @@ describe("Files API", () => {
contextType: "course",
contextId: "nomatter",
per_page: 50,
search_term: "banana",
search_term: "banana"
};
const expectedPath = `/api/v1/folders/${id}/files?per_page=50&include[]=preview_url&use_verifiers=0&search_term=banana`;
assert.equal(canvasPath({ params, query }), expectedPath);
Expand All @@ -47,7 +47,7 @@ describe("Files API", () => {
contextId: "nomatter",
per_page: 50,
sort: "created_at",
order: "desc",
order: "desc"
};
const expectedPath = `/api/v1/folders/${id}/files?per_page=50&include[]=preview_url&use_verifiers=0&sort=created_at&order=desc`;
assert.equal(canvasPath({ params, query }), expectedPath);
Expand Down Expand Up @@ -80,11 +80,11 @@ describe("Files API", () => {
request = { get: () => {} };
response = {
status: sinon.spy(),
send: sinon.spy(),
send: sinon.spy()
};
canvasResponse = {
status: 200,
body: [],
body: []
};
});

Expand Down Expand Up @@ -115,6 +115,7 @@ describe("Files API", () => {
folder_id: 1,
embedded_iframe_url: "https://canvas.com/foo/bar",
thumbnail_url: "https://canvas.com/foo/bar/thumbnail",
category: "foo"
};
});

Expand All @@ -138,14 +139,15 @@ describe("Files API", () => {
folderId: 1,
iframeUrl: "https://canvas.com/foo/bar",
thumbnailUrl: "someurl",
category: "foo"
});
});
});

it("creates files array property with items from response body", () => {
canvasResponse.body = [{}, {}, {}];
canvasResponseHandler(request, response, canvasResponse);
response.send.calledWithMatch((val) => {
response.send.calledWithMatch(val => {
return (
Array.isArray(val.files) &&
val.files.length === canvasResponse.body.length
Expand All @@ -168,30 +170,31 @@ describe("Files API", () => {
folderId: 1,
iframeUrl: "https://canvas.com/foo/bar",
thumbnailUrl: "https://canvas.com/foo/bar/thumbnail",
category: "foo"
});
});

it("will use fallbacks for name", () => {
file.display_name = undefined;
canvasResponse.body = [file];
canvasResponseHandler(request, response, canvasResponse);
response.send.calledWithMatch((val) => {
response.send.calledWithMatch(val => {
return sinon.match({ name: file.filename }, val[0]);
});
});

it("has bookmark from canvasResponse", () => {
canvasResponse.bookmark = "foo";
canvasResponseHandler(request, response, canvasResponse);
response.send.calledWithMatch((val) => {
response.send.calledWithMatch(val => {
return /foo/.test(val.bookmark);
});
});

it("has null bookmark if canvasResponse does not have one", () => {
canvasResponse.bookmark = undefined;
canvasResponseHandler(request, response, canvasResponse);
response.send.calledWithMatch((val) => {
response.send.calledWithMatch(val => {
return val.bookmark === null;
});
});
Expand Down

0 comments on commit a090093

Please sign in to comment.