error checking update

This commit is contained in:
2025-09-01 08:51:32 -06:00
parent 523a05d45e
commit ecb5f6d70f
2 changed files with 44 additions and 1 deletions

View File

@@ -40,10 +40,53 @@ describe("AssignmentHtmlTest", () => {
{ {
source: "insert_github_classroom_url", source: "insert_github_classroom_url",
destination: "findme", destination: "findme",
strict: true,
}, },
], ],
}); });
expect(html).toContain(`href="findme"`); expect(html).toContain(`href="findme"`);
}); });
it("assignment without text in description does not throw error", () => {
const name = "test assignment";
const assignment: LocalAssignment = {
name,
description: `here is the description without a classroom url`,
dueAt: "08/21/2023 23:59:00",
lockAt: "08/21/2023 23:59:00",
submissionTypes: [AssignmentSubmissionType.ONLINE_UPLOAD],
localAssignmentGroupName: "Final Project",
rubric: [],
allowedFileUploadExtensions: [],
githubClassroomAssignmentShareLink: "findme",
};
const settings: LocalCourseSettings = {
name: "test empty course",
assignmentGroups: [],
daysOfWeek: [DayOfWeek.Monday, DayOfWeek.Wednesday],
startDate: "07/09/2024 23:59:00",
endDate: "07/09/2024 23:59:00",
defaultDueTime: { hour: 1, minute: 59 },
canvasId: 0,
defaultAssignmentSubmissionTypes: [],
defaultFileUploadTypes: [],
holidays: [],
assets: [],
};
expect(() => {
markdownToHTMLSafe({
markdownString: assignment.description,
settings,
convertImages: false,
replaceText: [
{
source: "insert_github_classroom_url",
destination: "shouldn't be here",
strict: true,
},
],
});
}).not.toThrow();
});
}); });

View File

@@ -92,7 +92,7 @@ export function markdownToHTMLSafe({
const html = markdownToHtmlNoImages(markdownString); const html = markdownToHtmlNoImages(markdownString);
const replacedHtml = replaceText.reduce( const replacedHtml = replaceText.reduce(
(acc, { source, destination, strict = false }) => { (acc, { source, destination, strict = false }) => {
if (strict) { if (strict && acc.includes(source)) {
if (typeof destination === "undefined" || destination === null) { if (typeof destination === "undefined" || destination === null) {
throw new Error( throw new Error(
`Text replacement failed: destination is undefined for source "${source}"` `Text replacement failed: destination is undefined for source "${source}"`