From a0900935b6bbab66b1c75acd9d545dada424e527 Mon Sep 17 00:00:00 2001 From: Joe Hernandez Date: Mon, 3 Oct 2022 20:33:46 -0500 Subject: [PATCH] Response for files list includes file category 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 Reviewed-by: Jake Oeding QA-Review: Jake Oeding Product-Review: Joe Hernandez --- app/api/files.js | 5 +++-- test/service/api/files.test.js | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/api/files.js b/app/api/files.js index e29bdab..c7a810b 100644 --- a/app/api/files.js +++ b/app/api/files.js @@ -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, @@ -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); diff --git a/test/service/api/files.test.js b/test/service/api/files.test.js index 19750e7..d117ce0 100644 --- a/test/service/api/files.test.js +++ b/test/service/api/files.test.js @@ -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); @@ -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); @@ -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); @@ -80,11 +80,11 @@ describe("Files API", () => { request = { get: () => {} }; response = { status: sinon.spy(), - send: sinon.spy(), + send: sinon.spy() }; canvasResponse = { status: 200, - body: [], + body: [] }; }); @@ -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" }; }); @@ -138,6 +139,7 @@ describe("Files API", () => { folderId: 1, iframeUrl: "https://canvas.com/foo/bar", thumbnailUrl: "someurl", + category: "foo" }); }); }); @@ -145,7 +147,7 @@ describe("Files API", () => { 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 @@ -168,6 +170,7 @@ describe("Files API", () => { folderId: 1, iframeUrl: "https://canvas.com/foo/bar", thumbnailUrl: "https://canvas.com/foo/bar/thumbnail", + category: "foo" }); }); @@ -175,7 +178,7 @@ describe("Files API", () => { 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]); }); }); @@ -183,7 +186,7 @@ describe("Files API", () => { 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); }); }); @@ -191,7 +194,7 @@ describe("Files API", () => { 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; }); });