Skip to content

Commit

Permalink
Add endpoint for rce config
Browse files Browse the repository at this point in the history
Refs: QUIZ-9944
flag=none
Test plan:
  - Run canvas and canvas-rce-api locally
  - Send a get request to http://rce.docker/api/rceConfig with a correct auth token, contextType and contextId parameters
  - Note that the endpoint returns the exact same body that canvas returns from /api/v1/services/rce_config

Change-Id: Ib8fd747f7b46b87b523ab58a4a2cbece97174603
Reviewed-on: https://gerrit.instructure.com/c/canvas-rce-api/+/300728
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Rajmund Csehil <[email protected]>
Reviewed-by: Viktor Szpisják <[email protected]>
QA-Review: Rajmund Csehil <[email protected]>
Product-Review: Rajmund Csehil <[email protected]>
  • Loading branch information
Roland Beres committed Sep 15, 2022
1 parent 1ea3779 commit f104fbc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const assignments = require("./assignments");
const discussions = require("./discussions");
const modules = require("./modules");
const quizzes = require("./quizzes");
const rceConfig = require("./rceConfig");
const wikiPages = require("./wikiPages");
const kaltura = require("./kaltura");
const media_objects = require("./mediaObjects");
Expand Down Expand Up @@ -61,6 +62,12 @@ function init(auth, unsplashController) {
auth,
wrapCanvas(quizzes)
);
app.get(
"/api/rceConfig",
statsdKey("api", "rceConfig"),
auth,
wrapCanvas(rceConfig)
);
app.get(
"/api/wikiPages",
statsdKey("api", "wikiPages"),
Expand Down
23 changes: 23 additions & 0 deletions app/api/rceConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

function canvasPath(request) {
if (!request.query.contextId)
throw new Error("missing contextId parameter from query param");

const queryParamName = (contextType => {
switch (contextType) {
case "course":
return "course_id";
case "user":
return "user_id";
case "group":
return "group_id";
default:
throw new Error(`invalid contextType (${request.query.contextType})`);
}
})(request.query.contextType);

return `/api/v1/services/rce_config?${queryParamName}=${request.query.contextId}`;
}

module.exports = { canvasPath };
44 changes: 44 additions & 0 deletions test/service/api/rceConfig.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use strict";

const assert = require("assert");

const { canvasPath } = require("../../../app/api/rceConfig");

describe("RCE config API", () => {
describe("canvasPath", () => {
it("builds the correct path including with course_id parameter", () => {
const path = canvasPath({
query: { contextType: "course", contextId: "1" }
});
assert.ok(path.match("/api/v1/services/rce_config\\?course_id=1"));
});

it("builds the correct path including with user_id parameter", () => {
const path = canvasPath({
query: { contextType: "user", contextId: "1" }
});
assert.ok(path.match("/api/v1/services/rce_config\\?user_id=1"));
});

it("builds the correct path including with group_id parameter", () => {
const path = canvasPath({
query: { contextType: "group", contextId: "1" }
});
assert.ok(path.match("/api/v1/services/rce_config\\?group_id=1"));
});

it("throws error in case of missing context type", () => {
assert.throws(() => canvasPath({ query: { contextId: "1" } }));
});

it("throws error in case of invalid context type", () => {
assert.throws(() =>
canvasPath({ query: { contextType: "asd", contextId: "1" } })
);
});

it("throws error in case of missing context id", () => {
assert.throws(() => canvasPath({ query: { contextType: "asd" } }));
});
});
});

0 comments on commit f104fbc

Please sign in to comment.