From 8e90c9ff89d1fdd554afb98e51356560cc9f5c97 Mon Sep 17 00:00:00 2001 From: Weston Dransfield Date: Mon, 14 Mar 2022 12:46:51 -0600 Subject: [PATCH] Pass on category param in files API refs MAT-767 Test Plan: Follow the test plan in the associated canvas-lms commit Change-Id: I1d80fb116ee0a6170186d01e254604b9c8335f1a Reviewed-on: https://gerrit.instructure.com/c/canvas-rce-api/+/287066 Tested-by: Service Cloud Jenkins Reviewed-by: Gonzalo Penaranda QA-Review: Gonzalo Penaranda Product-Review: David Lyons --- app/api/files.js | 3 ++- test/service/api/files.test.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/api/files.js b/app/api/files.js index 0aec18b..e29bdab 100644 --- a/app/api/files.js +++ b/app/api/files.js @@ -4,6 +4,7 @@ const packageBookmark = require("./packageBookmark"); const { fileEmbed } = require("../../shared/mimeClass"); const { getSearch } = require("../utils/search"); const { getSort } = require("../utils/sort"); +const { optionalQuery } = require("../utils/optionalQuery"); function canvasPath(request) { if (request.query.contextType === "user") { @@ -15,7 +16,7 @@ function canvasPath(request) { request.query.per_page }&include[]=preview_url&use_verifiers=0${getSearch(request.query)}${getSort( request.query - )}`; + )}${optionalQuery(request.query, "category")}`; } } diff --git a/test/service/api/files.test.js b/test/service/api/files.test.js index a3696a8..19750e7 100644 --- a/test/service/api/files.test.js +++ b/test/service/api/files.test.js @@ -52,6 +52,24 @@ describe("Files API", () => { 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); }); + + describe("when a category is given", () => { + let params, query; + + const subject = () => canvasPath({ params, query }); + + beforeEach(() => { + params = { folderId: 7 }; + query = { category: "uncategorized" }; + }); + + it("adds the category as a query param", () => { + assert.equal( + subject(), + "/api/v1/folders/7/files?per_page=undefined&include[]=preview_url&use_verifiers=0&category=uncategorized" + ); + }); + }); }); });