Skip to content

Commit

Permalink
added check and test for IEP end dates (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-h-li authored Jul 24, 2024
1 parent 07ddc07 commit 4fd2ba0
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/backend/db/migrations/1_initial-migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ CREATE TABLE "iep" (
case_manager_id UUID REFERENCES "user" (user_id),
start_date DATE NOT NULL,
end_date DATE NOT NULL,
CHECK (end_date >= start_date),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

Expand All @@ -79,8 +80,8 @@ CREATE TABLE "goal" (
CREATE TABLE "subgoal" (
subgoal_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), -- TODO: add index to allow reordering
goal_id UUID REFERENCES "goal" (goal_id),
status TEXT NOT NULL DEFAULT 'In Progress'
CHECK (status IN ('In Progress', 'Complete')),
status TEXT NOT NULL DEFAULT 'In Progress'
CHECK (status IN ('In Progress', 'Complete')),
description TEXT NOT NULL,
setup TEXT NOT NULL,
instructions TEXT NOT NULL DEFAULT '',
Expand Down
72 changes: 72 additions & 0 deletions src/backend/routers/student.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,75 @@ test("getActiveStudentIep - return only one iep object", async (t) => {
t.deepEqual(studentWithIep?.start_date, addedIep.start_date);
t.deepEqual(studentWithIep?.end_date, addedIep.end_date);
});

test("checkAddedIEPEndDates", async (t) => {
const { trpc, seed } = await getTestServer(t, {
authenticateAs: "case_manager",
});
const start_date = new Date("2023-01-01");
const end_date = new Date("2022-01-01");

await t.throwsAsync(async () => {
await trpc.student.addIep.mutate({
student_id: seed.student.student_id,
start_date: start_date,
end_date: end_date,
});
});

const got = await trpc.student.getIeps.query({
student_id: seed.student.student_id,
});

t.is(got.length, 0);
});

test("checkEditedIEPEndDates", async (t) => {
const { trpc, seed } = await getTestServer(t, {
authenticateAs: "case_manager",
});

await trpc.case_manager.addStudent.mutate({
first_name: seed.student.first_name,
last_name: seed.student.last_name,
email: seed.student.email,
grade: seed.student.grade,
});

const myStudents = await trpc.case_manager.getMyStudents.query();
const student_id = myStudents[0].student_id;

const iep = await trpc.student.addIep.mutate({
student_id: student_id,
start_date: new Date("2023-01-01"),
end_date: new Date("2023-12-31"),
});

let got = await trpc.student.getIeps.query({
student_id: student_id,
});

t.is(got.length, 1);
t.is(got[0].student_id, iep.student_id);
t.deepEqual(got[0].start_date, iep.start_date);
t.deepEqual(got[0].end_date, iep.end_date);

const updated_start_date = new Date(parseISO("2023-01-01"));
const updated_end_date = new Date(parseISO("2022-01-01"));
await t.throwsAsync(async () => {
await trpc.student.editIep.mutate({
student_id: student_id,
start_date: updated_start_date,
end_date: updated_end_date,
});
});

got = await trpc.student.getIeps.query({
student_id: student_id,
});

t.is(got.length, 1);
t.is(got[0].student_id, iep.student_id);
t.deepEqual(got[0].start_date, iep.start_date);
t.deepEqual(got[0].end_date, iep.end_date);
});

0 comments on commit 4fd2ba0

Please sign in to comment.