mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
some more tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import path from "path";
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import fs from "fs";
|
||||
import { promises as fs } from "fs";
|
||||
import {
|
||||
DayOfWeek,
|
||||
LocalCourse,
|
||||
@@ -11,13 +11,14 @@ import { fileStorageService } from "../fileStorage/fileStorageService";
|
||||
import { basePath } from "../fileStorage/utils/fileSystemUtils";
|
||||
|
||||
describe("FileStorageTests", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
const storageDirectory =
|
||||
process.env.STORAGE_DIRECTORY ?? "/tmp/canvasManagerTests";
|
||||
if (fs.existsSync(storageDirectory)) {
|
||||
fs.rmdirSync(storageDirectory, { recursive: true });
|
||||
}
|
||||
fs.mkdirSync(storageDirectory, { recursive: true });
|
||||
try {
|
||||
await fs.access(storageDirectory);
|
||||
await fs.rm(storageDirectory, { recursive: true });
|
||||
} catch (error) {}
|
||||
await fs.mkdir(storageDirectory, { recursive: true });
|
||||
});
|
||||
|
||||
it("course settings can be saved and loaded", async () => {
|
||||
@@ -57,9 +58,49 @@ describe("FileStorageTests", () => {
|
||||
|
||||
it("invalid quizzes do not get loaded", async () => {
|
||||
const courseName = "testCourse";
|
||||
const invalidQuizMarkdown = "not a quiz";
|
||||
const moduleName = "testModule";
|
||||
const validQuizMarkdown = `Name: validQuiz
|
||||
LockAt: 08/28/2024 23:59:00
|
||||
DueAt: 08/28/2024 23:59:00
|
||||
Password:
|
||||
ShuffleAnswers: true
|
||||
ShowCorrectAnswers: false
|
||||
OneQuestionAtATime: false
|
||||
AssignmentGroup: Assignments
|
||||
AllowedAttempts: -1
|
||||
Description: Repeat this quiz until you can complete it without notes/help.
|
||||
---
|
||||
Points: 0.25
|
||||
|
||||
An empty string is
|
||||
|
||||
a) truthy
|
||||
*b) falsy
|
||||
`;
|
||||
const invalidQuizMarkdown = "name: testQuiz\n---\nnot a quiz";
|
||||
await fileStorageService.createCourseFolderForTesting(courseName);
|
||||
await fileStorageService.modules.createModule(courseName, "testModule");
|
||||
// fs.writeFile(`${basePath}/${courseName}/testModule/testQuiz.md`, invalidQuizMarkdown)
|
||||
await fileStorageService.modules.createModule(courseName, moduleName);
|
||||
|
||||
await fs.mkdir(`${basePath}/${courseName}/${moduleName}/quizzes`, {
|
||||
recursive: true,
|
||||
});
|
||||
await fs.writeFile(
|
||||
`${basePath}/${courseName}/${moduleName}/quizzes/testQuiz.md`,
|
||||
invalidQuizMarkdown
|
||||
);
|
||||
await fs.writeFile(
|
||||
`${basePath}/${courseName}/${moduleName}/quizzes/validQuiz.md`,
|
||||
validQuizMarkdown
|
||||
);
|
||||
|
||||
const quizzes = await fileStorageService.quizzes.getQuizzes(
|
||||
courseName,
|
||||
moduleName
|
||||
);
|
||||
const quizNames = quizzes.map((q) => q.name);
|
||||
|
||||
expect(quizNames).not.includes("testQuiz");
|
||||
expect(quizNames).include("validQuiz");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user