Skip to content

Commit

Permalink
Add specs to test authentication of each of case_maanger router endpo…
Browse files Browse the repository at this point in the history
…ints
  • Loading branch information
canjalal committed Oct 17, 2024
1 parent 013b29e commit 2c020f8
Showing 1 changed file with 128 additions and 1 deletion.
129 changes: 128 additions & 1 deletion src/backend/routers/case_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@/backend/lib/db_helpers/case_manager";
import { UserType } from "@/types/auth";

test("getMyStudents", async (t) => {
test("getMyStudents - can fetch students", async (t) => {
const { trpc, db, seed } = await getTestServer(t, {
authenticateAs: UserType.CaseManager,
});
Expand All @@ -29,6 +29,20 @@ test("getMyStudents", async (t) => {
t.is(myStudents[0].student_id, student_id);
});

test("getMyStudents - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.case_manager.getMyStudents.query();
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});

test("getMyStudentsAndIepInfo - student does not have IEP", async (t) => {
const { trpc, db, seed } = await getTestServer(t, {
authenticateAs: UserType.CaseManager,
Expand Down Expand Up @@ -82,6 +96,20 @@ test("getMyStudentsAndIepInfo - student has IEP", async (t) => {
t.deepEqual(myStudentsAfter[0].end_date, iep.end_date);
});

test("getMyStudentsAndIepInfo - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.case_manager.getMyStudentsAndIepInfo.query();
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});

test("addStudent - student doesn't exist in db", async (t) => {
const { trpc, db } = await getTestServer(t, {
authenticateAs: UserType.CaseManager,
Expand Down Expand Up @@ -278,6 +306,25 @@ test("addStudent - invalid email", async (t) => {
}
});

test("addStudent - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.case_manager.addStudent.mutate({
first_name: "Foo",
last_name: "Bar",
email: "invalid-email",
grade: 6,
});
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});

test("removeStudent", async (t) => {
const { trpc, db, seed } = await getTestServer(t, {
authenticateAs: UserType.CaseManager,
Expand Down Expand Up @@ -306,6 +353,22 @@ test("removeStudent", async (t) => {
t.is(after.length, 0);
});

test("removeStudent - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.case_manager.removeStudent.mutate({
student_id: "student_id",
});
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});

test("getMyParas", async (t) => {
const { trpc, db, seed } = await getTestServer(t, {
authenticateAs: UserType.CaseManager,
Expand All @@ -326,6 +389,20 @@ test("getMyParas", async (t) => {
t.is(myParas.length, 1);
});

test("getMyParas - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.case_manager.getMyParas.query();
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});

test("addStaff", async (t) => {
const { trpc } = await getTestServer(t, {
authenticateAs: UserType.CaseManager,
Expand All @@ -351,6 +428,24 @@ test("addStaff", async (t) => {
t.is(createdPara.email, newParaData.email);
});

test("addStaff - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.case_manager.addStaff.mutate({
first_name: "Foo",
last_name: "Bar",
email: "foo@bar.com",
});
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});

test("addPara", async (t) => {
const { trpc, seed } = await getTestServer(t, {
authenticateAs: UserType.CaseManager,
Expand All @@ -367,6 +462,22 @@ test("addPara", async (t) => {
t.is(myParas.length, 1);
});

test("addPara - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.case_manager.addPara.mutate({
para_id: "para_id",
});
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});

test("removePara", async (t) => {
const { trpc, db, seed } = await getTestServer(t, {
authenticateAs: UserType.CaseManager,
Expand All @@ -390,3 +501,19 @@ test("removePara", async (t) => {
myParas = await trpc.case_manager.getMyParas.query();
t.is(myParas.length, 0);
});

test("removePara - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.case_manager.removePara.mutate({
para_id: "para_id",
});
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});

0 comments on commit 2c020f8

Please sign in to comment.