From 90fcca7bbee9b338d0b081b674e3d170a2aa2323 Mon Sep 17 00:00:00 2001 From: Adam Teichert Date: Wed, 15 Jan 2025 18:59:21 -0700 Subject: [PATCH] short_answer= making it with answers to canvas (needed to include answer_text) --- .../tests/quizMarkdown/testAnswer.test.ts | 46 ++++++++++++++++++- src/services/canvas/canvasQuizService.ts | 3 +- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/models/local/tests/quizMarkdown/testAnswer.test.ts b/src/models/local/tests/quizMarkdown/testAnswer.test.ts index 8140c23..39a5baf 100644 --- a/src/models/local/tests/quizMarkdown/testAnswer.test.ts +++ b/src/models/local/tests/quizMarkdown/testAnswer.test.ts @@ -1,8 +1,9 @@ -import { getQuestionType } from "@/services/canvas/canvasQuizService"; +import { getAnswers, getQuestionType } from "@/services/canvas/canvasQuizService"; import { QuestionType, zodQuestionType } from "../../quiz/localQuizQuestion"; import { quizMarkdownUtils } from "../../quiz/utils/quizMarkdownUtils"; import { quizQuestionMarkdownUtils } from "../../quiz/utils/quizQuestionMarkdownUtils"; import { describe, it, expect } from "vitest"; +import { LocalCourseSettings } from "../../localCourseSettings"; describe("TextAnswerTests", () => { it("can parse essay", () => { @@ -226,4 +227,47 @@ short_answer= const firstQuestion = quiz.questions[0]; expect(getQuestionType(firstQuestion)).toBe("short_answer_question"); }); + + it("Includes answer_text in answers sent to canvas", () => { + const name = "Test Quiz" + const rawMarkdownQuiz = ` +ShuffleAnswers: true +OneQuestionAtATime: false +DueAt: 08/21/2023 23:59:00 +LockAt: 08/21/2023 23:59:00 +AssignmentGroup: Assignments +AllowedAttempts: -1 +Description: this is the +multi line +description +--- +Which events are triggered when the user clicks on an input field? +*a) test +*b) other +short_answer= +`; + + const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz, name); + const firstQuestion = quiz.questions[0]; + const answers = getAnswers(firstQuestion, { + name: "", + assignmentGroups: [], + daysOfWeek: [], + canvasId: 0, + startDate: "", + endDate: "", + defaultDueTime: { + hour: 0, + minute: 0 + }, + defaultAssignmentSubmissionTypes: [], + defaultFileUploadTypes: [], + holidays: [], + assets: [] + }) + expect(answers).toHaveLength(2); + const firstAnswer = answers[0]; + expect(firstAnswer).toHaveProperty("answer_text"); + }); + }); diff --git a/src/services/canvas/canvasQuizService.ts b/src/services/canvas/canvasQuizService.ts index 8f56498..3b92f05 100644 --- a/src/services/canvas/canvasQuizService.ts +++ b/src/services/canvas/canvasQuizService.ts @@ -12,7 +12,7 @@ import { import { CanvasQuizQuestion } from "@/models/canvas/quizzes/canvasQuizQuestionModel"; import { LocalCourseSettings } from "@/models/local/localCourseSettings"; -const getAnswers = ( +export const getAnswers = ( question: LocalQuizQuestion, settings: LocalCourseSettings ) => { @@ -25,6 +25,7 @@ const getAnswers = ( return question.answers.map((answer) => ({ answer_html: markdownToHTMLSafe(answer.text, settings), answer_weight: answer.correct ? 100 : 0, + answer_text: answer.text, })); };