-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } })); | ||
}); | ||
}); | ||
}); |