mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
pages too
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { LocalAssignment } from "./assignment/localAssignment";
|
||||
import { LocalCoursePage } from "./page/localCoursePage";
|
||||
import { LocalQuiz } from "./quiz/localQuiz";
|
||||
import {
|
||||
dateToMarkdownString,
|
||||
@@ -32,7 +33,6 @@ export const prepAssignmentForNewSemester = (
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
export const prepQuizForNewSemester = (
|
||||
quiz: LocalQuiz,
|
||||
oldSemesterStartDate: string,
|
||||
@@ -45,11 +45,8 @@ export const prepQuizForNewSemester = (
|
||||
...quiz,
|
||||
description: descriptionWithoutGithubClassroom,
|
||||
dueAt:
|
||||
newDateOffset(
|
||||
quiz.dueAt,
|
||||
oldSemesterStartDate,
|
||||
newSemesterStartDate
|
||||
) ?? quiz.dueAt,
|
||||
newDateOffset(quiz.dueAt, oldSemesterStartDate, newSemesterStartDate) ??
|
||||
quiz.dueAt,
|
||||
lockAt: newDateOffset(
|
||||
quiz.lockAt,
|
||||
oldSemesterStartDate,
|
||||
@@ -58,7 +55,20 @@ export const prepQuizForNewSemester = (
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
export const prepPageForNewSemester = (
|
||||
page: LocalCoursePage,
|
||||
oldSemesterStartDate: string,
|
||||
newSemesterStartDate: string
|
||||
): LocalCoursePage => {
|
||||
const updatedText = replaceClassroomUrl(page.text);
|
||||
return {
|
||||
...page,
|
||||
text: updatedText,
|
||||
dueAt:
|
||||
newDateOffset(page.dueAt, oldSemesterStartDate, newSemesterStartDate) ??
|
||||
page.dueAt,
|
||||
};
|
||||
};
|
||||
|
||||
const replaceClassroomUrl = (value: string) => {
|
||||
const classroomPattern =
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { LocalAssignment } from "../assignment/localAssignment";
|
||||
import { prepAssignmentForNewSemester, prepQuizForNewSemester } from "../semesterTransferUtils";
|
||||
import { prepAssignmentForNewSemester, prepPageForNewSemester, prepQuizForNewSemester } from "../semesterTransferUtils";
|
||||
import { LocalQuiz } from "../quiz/localQuiz";
|
||||
import { LocalCoursePage } from "../page/localCoursePage";
|
||||
|
||||
describe("can take an assignment and template it for a new semester", () => {
|
||||
it("can sanitize assignment github classroom repo url", () => {
|
||||
@@ -142,7 +143,7 @@ describe("can offset date based on new semester start", () => {
|
||||
});
|
||||
|
||||
describe("can prep quizzes", () => {
|
||||
it("assignment with new semester start, no lock date", () => {
|
||||
it("quiz gets new lock and due dates", () => {
|
||||
const quiz: LocalQuiz = {
|
||||
name: "Test Quiz",
|
||||
description: `
|
||||
@@ -171,3 +172,24 @@ describe("can prep quizzes", () => {
|
||||
expect(sanitizedQuiz.lockAt).toEqual("01/12/2024 23:59:00");
|
||||
});
|
||||
});
|
||||
|
||||
describe("can prep pages", () => {
|
||||
it("page gets new due date and github url changes", () => {
|
||||
const page: LocalCoursePage = {
|
||||
name: "test title",
|
||||
text: "test text content",
|
||||
dueAt: "08/30/2023 23:59:00",
|
||||
};
|
||||
|
||||
const oldSemesterStartDate = "08/26/2023 23:59:00";
|
||||
const newSemesterStartDate = "01/08/2024 23:59:00";
|
||||
|
||||
const sanitizedPage = prepPageForNewSemester(
|
||||
page,
|
||||
oldSemesterStartDate,
|
||||
newSemesterStartDate
|
||||
);
|
||||
|
||||
expect(sanitizedPage.dueAt).toEqual("01/12/2024 23:59:00");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user