mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
workign on test folders
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { LocalCourse } from "@/models/local/localCourse";
|
||||
import { CourseDifferences } from "../fileStorage/courseDifferences";
|
||||
import { CourseDifferences } from "../fileStorage/utils/courseDifferences";
|
||||
import { AssignmentSubmissionType } from "@/models/local/assignmnet/assignmentSubmissionType";
|
||||
|
||||
describe("CourseDifferencesChangesTests", () => {
|
||||
@@ -124,7 +124,9 @@ describe("CourseDifferencesChangesTests", () => {
|
||||
|
||||
expect(differences.modules).not.toBeNull();
|
||||
expect(differences.modules).toHaveLength(1);
|
||||
expect(differences.modules?.[0].assignments?.[0].description).toBe("new description");
|
||||
expect(differences.modules?.[0].assignments?.[0].description).toBe(
|
||||
"new description"
|
||||
);
|
||||
});
|
||||
|
||||
it("can properly ignore unchanged modules", () => {
|
||||
@@ -241,7 +243,9 @@ describe("CourseDifferencesChangesTests", () => {
|
||||
|
||||
expect(differences.modules).toHaveLength(1);
|
||||
expect(differences.modules?.[0].assignments).toHaveLength(1);
|
||||
expect(differences.modules?.[0].assignments?.[0].name).toBe("test assignment 2 with a new name");
|
||||
expect(differences.modules?.[0].assignments?.[0].name).toBe(
|
||||
"test assignment 2 with a new name"
|
||||
);
|
||||
});
|
||||
|
||||
it("identical quizzes ignored", () => {
|
||||
@@ -349,7 +353,9 @@ describe("CourseDifferencesChangesTests", () => {
|
||||
|
||||
expect(differences.modules).toHaveLength(1);
|
||||
expect(differences.modules?.[0].quizzes).toHaveLength(1);
|
||||
expect(differences.modules?.[0].quizzes?.[0].lockAt).toBe("12/31/9999 23:59:59");
|
||||
expect(differences.modules?.[0].quizzes?.[0].lockAt).toBe(
|
||||
"12/31/9999 23:59:59"
|
||||
);
|
||||
});
|
||||
|
||||
it("can detect only different quiz when other quizzes stay", () => {
|
||||
@@ -515,7 +521,9 @@ describe("CourseDifferencesChangesTests", () => {
|
||||
|
||||
expect(differences.modules).toHaveLength(1);
|
||||
expect(differences.modules?.[0].pages).toHaveLength(1);
|
||||
expect(differences.modules?.[0].pages?.[0].text).toBe("test description changed");
|
||||
expect(differences.modules?.[0].pages?.[0].text).toBe(
|
||||
"test description changed"
|
||||
);
|
||||
});
|
||||
|
||||
it("different page detected but not same page", () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { LocalCourse } from "@/models/local/localCourse";
|
||||
import { CourseDifferences } from "../fileStorage/courseDifferences";
|
||||
import { CourseDifferences } from "../fileStorage/utils/courseDifferences";
|
||||
|
||||
describe("CourseDifferencesDeletionsTests", () => {
|
||||
it("same module does not get deleted", () => {
|
||||
@@ -37,7 +37,10 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const differences = CourseDifferences.getDeletedChanges(newCourse, oldCourse);
|
||||
const differences = CourseDifferences.getDeletedChanges(
|
||||
newCourse,
|
||||
oldCourse
|
||||
);
|
||||
|
||||
expect(differences.namesOfModulesToDeleteCompletely).toHaveLength(0);
|
||||
});
|
||||
@@ -76,7 +79,10 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const differences = CourseDifferences.getDeletedChanges(newCourse, oldCourse);
|
||||
const differences = CourseDifferences.getDeletedChanges(
|
||||
newCourse,
|
||||
oldCourse
|
||||
);
|
||||
|
||||
expect(differences.namesOfModulesToDeleteCompletely).toHaveLength(1);
|
||||
expect(differences.namesOfModulesToDeleteCompletely[0]).toBe("test module");
|
||||
@@ -105,7 +111,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [],
|
||||
allowedFileUploadExtensions: [],
|
||||
rubric: []
|
||||
rubric: [],
|
||||
},
|
||||
],
|
||||
quizzes: [],
|
||||
@@ -125,7 +131,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [],
|
||||
allowedFileUploadExtensions: [],
|
||||
rubric: []
|
||||
rubric: [],
|
||||
},
|
||||
],
|
||||
quizzes: [],
|
||||
@@ -134,7 +140,10 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const differences = CourseDifferences.getDeletedChanges(newCourse, oldCourse);
|
||||
const differences = CourseDifferences.getDeletedChanges(
|
||||
newCourse,
|
||||
oldCourse
|
||||
);
|
||||
|
||||
expect(differences.namesOfModulesToDeleteCompletely).toHaveLength(0);
|
||||
expect(differences.deleteContentsOfModule).toHaveLength(1);
|
||||
@@ -167,7 +176,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [],
|
||||
allowedFileUploadExtensions: [],
|
||||
rubric: []
|
||||
rubric: [],
|
||||
},
|
||||
],
|
||||
quizzes: [],
|
||||
@@ -187,7 +196,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [],
|
||||
allowedFileUploadExtensions: [],
|
||||
rubric: []
|
||||
rubric: [],
|
||||
},
|
||||
],
|
||||
quizzes: [],
|
||||
@@ -196,7 +205,10 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const differences = CourseDifferences.getDeletedChanges(newCourse, oldCourse);
|
||||
const differences = CourseDifferences.getDeletedChanges(
|
||||
newCourse,
|
||||
oldCourse
|
||||
);
|
||||
|
||||
expect(differences.deleteContentsOfModule).toHaveLength(0);
|
||||
});
|
||||
@@ -224,7 +236,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [],
|
||||
allowedFileUploadExtensions: [],
|
||||
rubric: []
|
||||
rubric: [],
|
||||
},
|
||||
{
|
||||
name: "test assignment 2",
|
||||
@@ -232,7 +244,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [],
|
||||
allowedFileUploadExtensions: [],
|
||||
rubric: []
|
||||
rubric: [],
|
||||
},
|
||||
],
|
||||
quizzes: [],
|
||||
@@ -252,7 +264,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [],
|
||||
allowedFileUploadExtensions: [],
|
||||
rubric: []
|
||||
rubric: [],
|
||||
},
|
||||
{
|
||||
name: "test assignment 2 changed",
|
||||
@@ -260,7 +272,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [],
|
||||
allowedFileUploadExtensions: [],
|
||||
rubric: []
|
||||
rubric: [],
|
||||
},
|
||||
],
|
||||
quizzes: [],
|
||||
@@ -269,7 +281,10 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const differences = CourseDifferences.getDeletedChanges(newCourse, oldCourse);
|
||||
const differences = CourseDifferences.getDeletedChanges(
|
||||
newCourse,
|
||||
oldCourse
|
||||
);
|
||||
|
||||
expect(differences.deleteContentsOfModule).toHaveLength(1);
|
||||
expect(differences.deleteContentsOfModule[0].assignments).toHaveLength(1);
|
||||
@@ -304,7 +319,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
showCorrectAnswers: false,
|
||||
oneQuestionAtATime: false,
|
||||
allowedAttempts: 0,
|
||||
questions: []
|
||||
questions: [],
|
||||
},
|
||||
{
|
||||
name: "Test Quiz 2",
|
||||
@@ -314,7 +329,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
showCorrectAnswers: false,
|
||||
oneQuestionAtATime: false,
|
||||
allowedAttempts: 0,
|
||||
questions: []
|
||||
questions: [],
|
||||
},
|
||||
],
|
||||
pages: [],
|
||||
@@ -336,7 +351,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
showCorrectAnswers: false,
|
||||
oneQuestionAtATime: false,
|
||||
allowedAttempts: 0,
|
||||
questions: []
|
||||
questions: [],
|
||||
},
|
||||
{
|
||||
name: "Test Quiz 3",
|
||||
@@ -346,7 +361,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
showCorrectAnswers: false,
|
||||
oneQuestionAtATime: false,
|
||||
allowedAttempts: 0,
|
||||
questions: []
|
||||
questions: [],
|
||||
},
|
||||
],
|
||||
pages: [],
|
||||
@@ -354,7 +369,10 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
],
|
||||
};
|
||||
|
||||
const differences = CourseDifferences.getDeletedChanges(newCourse, oldCourse);
|
||||
const differences = CourseDifferences.getDeletedChanges(
|
||||
newCourse,
|
||||
oldCourse
|
||||
);
|
||||
|
||||
expect(differences.deleteContentsOfModule).toHaveLength(1);
|
||||
expect(differences.deleteContentsOfModule[0].quizzes).toHaveLength(1);
|
||||
@@ -390,7 +408,7 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
{
|
||||
name: "Test Page 2",
|
||||
text: "test contents",
|
||||
dueAt: "09/07/2024 23:59:00"
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -407,19 +425,22 @@ describe("CourseDifferencesDeletionsTests", () => {
|
||||
{
|
||||
name: "Test Page",
|
||||
text: "test contents",
|
||||
dueAt: "09/07/2024 23:59:00"
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
},
|
||||
{
|
||||
name: "Test Page 3",
|
||||
text: "test contents",
|
||||
dueAt: "09/07/2024 23:59:00"
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const differences = CourseDifferences.getDeletedChanges(newCourse, oldCourse);
|
||||
const differences = CourseDifferences.getDeletedChanges(
|
||||
newCourse,
|
||||
oldCourse
|
||||
);
|
||||
|
||||
expect(differences.deleteContentsOfModule).toHaveLength(1);
|
||||
expect(differences.deleteContentsOfModule[0].pages).toHaveLength(1);
|
||||
|
||||
298
nextjs/src/services/tests/fileStorage.test.ts
Normal file
298
nextjs/src/services/tests/fileStorage.test.ts
Normal file
@@ -0,0 +1,298 @@
|
||||
import path from "path";
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import fs from "fs";
|
||||
import { DayOfWeek, LocalCourse } from "@/models/local/localCourse";
|
||||
import { AssignmentSubmissionType } from "@/models/local/assignmnet/assignmentSubmissionType";
|
||||
import { QuestionType } from "@/models/local/quiz/localQuizQuestion";
|
||||
import { fileStorageService } from "../fileStorage/fileStorageService";
|
||||
|
||||
describe("FileStorageTests", () => {
|
||||
let storageDirectory: string;
|
||||
|
||||
beforeEach(() => {
|
||||
const tempDirectory = path.resolve("./temp");
|
||||
storageDirectory = path.join(tempDirectory, "fileStorageTests");
|
||||
console.log(storageDirectory);
|
||||
|
||||
if (fs.existsSync(storageDirectory)) {
|
||||
fs.rmdirSync(storageDirectory, { recursive: true });
|
||||
}
|
||||
fs.mkdirSync(storageDirectory, { recursive: true });
|
||||
});
|
||||
|
||||
it("empty course can be saved and loaded", async () => {
|
||||
const testCourse: LocalCourse = {
|
||||
settings: {
|
||||
name: "test empty course",
|
||||
assignmentGroups: [],
|
||||
daysOfWeek: [],
|
||||
startDate: "09/07/2024 23:59:00",
|
||||
endDate: "09/07/2024 23:59:00",
|
||||
defaultDueTime: { hour: 1, minute: 59 },
|
||||
},
|
||||
modules: [],
|
||||
};
|
||||
|
||||
await fileStorageService.saveCourseAsync(testCourse);
|
||||
|
||||
const loadedCourses = await fileStorageService.loadSavedCourses();
|
||||
const loadedCourse = loadedCourses.find(
|
||||
(c) => c.settings.name === testCourse.settings.name
|
||||
);
|
||||
|
||||
expect(loadedCourse).toEqual(testCourse);
|
||||
});
|
||||
|
||||
it("course settings can be saved and loaded", async () => {
|
||||
const testCourse: LocalCourse = {
|
||||
settings: {
|
||||
assignmentGroups: [],
|
||||
name: "Test Course with settings",
|
||||
daysOfWeek: [DayOfWeek.Monday, DayOfWeek.Wednesday],
|
||||
startDate: "09/07/2024 23:59:00",
|
||||
endDate: "09/07/2024 23:59:00",
|
||||
defaultDueTime: { hour: 1, minute: 59 },
|
||||
},
|
||||
modules: [],
|
||||
};
|
||||
|
||||
await fileStorageService.saveCourseAsync(testCourse);
|
||||
|
||||
const loadedCourses = await fileStorageService.loadSavedCourses();
|
||||
const loadedCourse = loadedCourses.find(
|
||||
(c) => c.settings.name === testCourse.settings.name
|
||||
);
|
||||
|
||||
expect(loadedCourse?.settings).toEqual(testCourse.settings);
|
||||
});
|
||||
|
||||
it("empty course modules can be saved and loaded", async () => {
|
||||
const testCourse: LocalCourse = {
|
||||
settings: {
|
||||
name: "Test Course with modules",
|
||||
assignmentGroups: [],
|
||||
daysOfWeek: [],
|
||||
startDate: "09/07/2024 23:59:00",
|
||||
endDate: "09/07/2024 23:59:00",
|
||||
defaultDueTime: { hour: 1, minute: 59 },
|
||||
},
|
||||
modules: [
|
||||
{
|
||||
name: "test module 1",
|
||||
assignments: [],
|
||||
quizzes: [],
|
||||
pages: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await fileStorageService.saveCourseAsync(testCourse);
|
||||
|
||||
const loadedCourses = await fileStorageService.loadSavedCourses();
|
||||
const loadedCourse = loadedCourses.find(
|
||||
(c) => c.settings.name === testCourse.settings.name
|
||||
);
|
||||
|
||||
expect(loadedCourse?.modules).toEqual(testCourse.modules);
|
||||
});
|
||||
|
||||
it("course modules with assignments can be saved and loaded", async () => {
|
||||
const testCourse: LocalCourse = {
|
||||
settings: {
|
||||
name: "Test Course with modules and assignments",
|
||||
assignmentGroups: [],
|
||||
daysOfWeek: [],
|
||||
startDate: "09/07/2024 23:59:00",
|
||||
endDate: "09/07/2024 23:59:00",
|
||||
defaultDueTime: { hour: 1, minute: 59 },
|
||||
},
|
||||
modules: [
|
||||
{
|
||||
name: "test module 1 with assignments",
|
||||
assignments: [
|
||||
{
|
||||
name: "test assignment",
|
||||
description: "here is the description",
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
lockAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [AssignmentSubmissionType.ONLINE_UPLOAD],
|
||||
localAssignmentGroupName: "Final Project",
|
||||
rubric: [
|
||||
{ points: 4, label: "do task 1" },
|
||||
{ points: 2, label: "do task 2" },
|
||||
],
|
||||
allowedFileUploadExtensions: []
|
||||
},
|
||||
],
|
||||
quizzes: [],
|
||||
pages: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await fileStorageService.saveCourseAsync(testCourse);
|
||||
|
||||
const loadedCourses = await fileStorageService.loadSavedCourses();
|
||||
const loadedCourse = loadedCourses.find(
|
||||
(c) => c.settings.name === testCourse.settings.name
|
||||
);
|
||||
|
||||
expect(loadedCourse?.modules[0].assignments).toEqual(
|
||||
testCourse.modules[0].assignments
|
||||
);
|
||||
});
|
||||
|
||||
it("course modules with quizzes can be saved and loaded", async () => {
|
||||
const testCourse: LocalCourse = {
|
||||
settings: {
|
||||
name: "Test Course with modules and quiz",
|
||||
assignmentGroups: [],
|
||||
daysOfWeek: [],
|
||||
startDate: "09/07/2024 23:59:00",
|
||||
endDate: "09/07/2024 23:59:00",
|
||||
defaultDueTime: { hour: 1, minute: 59 },
|
||||
},
|
||||
modules: [
|
||||
{
|
||||
name: "test module 1 with quiz",
|
||||
assignments: [],
|
||||
quizzes: [
|
||||
{
|
||||
name: "Test Quiz",
|
||||
description: "quiz description",
|
||||
lockAt: "09/07/2024 12:05:00",
|
||||
dueAt: "09/07/2024 12:05:00",
|
||||
shuffleAnswers: true,
|
||||
oneQuestionAtATime: true,
|
||||
localAssignmentGroupName: "Assignments",
|
||||
questions: [
|
||||
{
|
||||
text: "test essay",
|
||||
questionType: QuestionType.ESSAY,
|
||||
points: 1,
|
||||
answers: [],
|
||||
matchDistractors: []
|
||||
},
|
||||
],
|
||||
showCorrectAnswers: false,
|
||||
allowedAttempts: 0
|
||||
},
|
||||
],
|
||||
pages: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await fileStorageService.saveCourseAsync(testCourse);
|
||||
|
||||
const loadedCourses = await fileStorageService.loadSavedCourses();
|
||||
const loadedCourse = loadedCourses.find(
|
||||
(c) => c.settings.name === testCourse.settings.name
|
||||
);
|
||||
|
||||
expect(loadedCourse?.modules[0].quizzes).toEqual(
|
||||
testCourse.modules[0].quizzes
|
||||
);
|
||||
});
|
||||
|
||||
it("markdown storage fully populated does not lose data", async () => {
|
||||
const testCourse: LocalCourse = {
|
||||
settings: {
|
||||
name: "Test Course with lots of data",
|
||||
assignmentGroups: [],
|
||||
daysOfWeek: [DayOfWeek.Monday, DayOfWeek.Wednesday],
|
||||
startDate: "09/07/2024 23:59:00",
|
||||
endDate: "09/07/2024 23:59:00",
|
||||
defaultDueTime: { hour: 1, minute: 59 },
|
||||
},
|
||||
modules: [
|
||||
{
|
||||
name: "new test module",
|
||||
assignments: [
|
||||
{
|
||||
name: "test assignment",
|
||||
description: "here is the description",
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
lockAt: "09/07/2024 23:59:00",
|
||||
submissionTypes: [AssignmentSubmissionType.ONLINE_UPLOAD],
|
||||
localAssignmentGroupName: "Final Project",
|
||||
rubric: [
|
||||
{ points: 4, label: "do task 1" },
|
||||
{ points: 2, label: "do task 2" },
|
||||
],
|
||||
allowedFileUploadExtensions: []
|
||||
},
|
||||
],
|
||||
quizzes: [
|
||||
{
|
||||
name: "Test Quiz",
|
||||
description: "quiz description",
|
||||
lockAt: "09/07/2024 23:59:00",
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
shuffleAnswers: true,
|
||||
oneQuestionAtATime: false,
|
||||
localAssignmentGroupName: "someId",
|
||||
allowedAttempts: -1,
|
||||
questions: [
|
||||
{
|
||||
text: "test short answer",
|
||||
questionType: QuestionType.SHORT_ANSWER,
|
||||
points: 1,
|
||||
answers: [],
|
||||
matchDistractors: []
|
||||
},
|
||||
],
|
||||
showCorrectAnswers: false
|
||||
},
|
||||
],
|
||||
pages: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await fileStorageService.saveCourseAsync(testCourse);
|
||||
|
||||
const loadedCourses = await fileStorageService.loadSavedCourses();
|
||||
const loadedCourse = loadedCourses.find(
|
||||
(c) => c.settings.name === testCourse.settings.name
|
||||
);
|
||||
|
||||
expect(loadedCourse).toEqual(testCourse);
|
||||
});
|
||||
|
||||
it("markdown storage can persist pages", async () => {
|
||||
const testCourse: LocalCourse = {
|
||||
settings: {
|
||||
name: "Test Course with page",
|
||||
assignmentGroups: [],
|
||||
daysOfWeek: [DayOfWeek.Monday, DayOfWeek.Wednesday],
|
||||
startDate: "09/07/2024 23:59:00",
|
||||
endDate: "09/07/2024 23:59:00",
|
||||
defaultDueTime: { hour: 1, minute: 59 },
|
||||
},
|
||||
modules: [
|
||||
{
|
||||
name: "page test module",
|
||||
assignments: [],
|
||||
quizzes: [],
|
||||
pages: [
|
||||
{
|
||||
name: "test page persistence",
|
||||
dueAt: "09/07/2024 23:59:00",
|
||||
text: "this is some\n## markdown\n",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await fileStorageService.saveCourseAsync(testCourse);
|
||||
|
||||
const loadedCourses = await fileStorageService.loadSavedCourses();
|
||||
const loadedCourse = loadedCourses.find(
|
||||
(c) => c.settings.name === testCourse.settings.name
|
||||
);
|
||||
|
||||
expect(loadedCourse).toEqual(testCourse);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user