Skip to content

Commit

Permalink
Only allow case managers to access iep router routes, and add two api…
Browse files Browse the repository at this point in the history
… endpoint tests
  • Loading branch information
canjalal committed Oct 17, 2024
1 parent b1e5c2f commit 46ce087
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
32 changes: 32 additions & 0 deletions src/backend/routers/iep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,35 @@ test("edit goal", async (t) => {
t.is(modifiedGoal!.goal_id, goal!.goal_id);
t.is(modifiedGoal?.description, "modified goal 1");
});
test("editGoal - paras do not have access", async (t) => {
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para });

const error = await t.throwsAsync(async () => {
await trpc.iep.editGoal.mutate({
goal_id: "goal_id",
description: "description",
});
});

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

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

const error = await t.throwsAsync(async () => {
await trpc.iep.getGoal.query({
goal_id: "goal_id",
});
});

t.is(
error?.message,
"UNAUTHORIZED",
"Expected an 'unauthorized' error message"
);
});
36 changes: 18 additions & 18 deletions src/backend/routers/iep.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { z } from "zod";
import { hasAuthenticated, router } from "../trpc";
import { hasCaseManager, router } from "../trpc";
import { jsonArrayFrom } from "kysely/helpers/postgres";
import { deleteFile } from "../lib/files";
import { substituteTransactionOnContext } from "../lib/utils/context";
import { TRPCError } from "@trpc/server";

// TODO: define .output() schemas for all procedures
export const iep = router({
addGoal: hasAuthenticated
addGoal: hasCaseManager
.input(
z.object({
iep_id: z.string(),
Expand All @@ -31,7 +31,7 @@ export const iep = router({
return result;
}),

editGoal: hasAuthenticated
editGoal: hasCaseManager
.input(
z.object({
goal_id: z.string(),
Expand Down Expand Up @@ -70,7 +70,7 @@ export const iep = router({
return result;
}),

addSubgoal: hasAuthenticated
addSubgoal: hasCaseManager
.input(
z.object({
// current_level not included, should be calculated as trial data is collected
Expand Down Expand Up @@ -123,7 +123,7 @@ export const iep = router({
return result;
}),

addTask: hasAuthenticated
addTask: hasCaseManager
.input(
z.object({
subgoal_id: z.string(),
Expand All @@ -148,7 +148,7 @@ export const iep = router({

return result;
}),
assignTaskToParas: hasAuthenticated
assignTaskToParas: hasCaseManager
.input(
z.object({
subgoal_id: z.string().uuid(),
Expand All @@ -175,7 +175,7 @@ export const iep = router({
return result;
}),
//Temporary function to easily assign tasks to self for testing
tempAddTaskToSelf: hasAuthenticated
tempAddTaskToSelf: hasCaseManager
.input(
z.object({
subgoal_id: z.string(),
Expand Down Expand Up @@ -217,7 +217,7 @@ export const iep = router({
return result;
}),

addTrialData: hasAuthenticated
addTrialData: hasCaseManager
.input(
z.object({
task_id: z.string(),
Expand Down Expand Up @@ -246,7 +246,7 @@ export const iep = router({
return result;
}),

updateTrialData: hasAuthenticated
updateTrialData: hasCaseManager
.input(
z.object({
trial_data_id: z.string(),
Expand All @@ -271,7 +271,7 @@ export const iep = router({
.execute();
}),

getGoals: hasAuthenticated
getGoals: hasCaseManager
.input(
z.object({
iep_id: z.string(),
Expand All @@ -289,7 +289,7 @@ export const iep = router({
return result;
}),

getGoal: hasAuthenticated
getGoal: hasCaseManager
.input(
z.object({
goal_id: z.string(),
Expand All @@ -307,7 +307,7 @@ export const iep = router({
return result;
}),

getSubgoals: hasAuthenticated
getSubgoals: hasCaseManager
.input(
z.object({
goal_id: z.string(),
Expand All @@ -325,7 +325,7 @@ export const iep = router({
return result;
}),

getSubgoal: hasAuthenticated
getSubgoal: hasCaseManager
.input(
z.object({
subgoal_id: z.string(),
Expand All @@ -342,7 +342,7 @@ export const iep = router({
return result;
}),

getSubgoalsByAssignee: hasAuthenticated
getSubgoalsByAssignee: hasCaseManager
.input(
z.object({
assignee_id: z.string(),
Expand All @@ -361,7 +361,7 @@ export const iep = router({
return result;
}),

getSubgoalAndTrialData: hasAuthenticated
getSubgoalAndTrialData: hasCaseManager
.input(
z.object({
task_id: z.string(),
Expand Down Expand Up @@ -424,7 +424,7 @@ export const iep = router({
return result;
}),

markAsSeen: hasAuthenticated
markAsSeen: hasCaseManager
.input(
z.object({
task_id: z.string(),
Expand All @@ -442,7 +442,7 @@ export const iep = router({
.execute();
}),

attachFileToTrialData: hasAuthenticated
attachFileToTrialData: hasCaseManager
.input(
z.object({
trial_data_id: z.string(),
Expand All @@ -461,7 +461,7 @@ export const iep = router({
.execute();
}),

removeFileFromTrialDataAndDelete: hasAuthenticated
removeFileFromTrialDataAndDelete: hasCaseManager
.input(
z.object({
trial_data_id: z.string(),
Expand Down

0 comments on commit 46ce087

Please sign in to comment.