Skip to content

Commit

Permalink
Also add position related to DDAH assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kozin committed May 28, 2021
1 parent 228110a commit 35157be
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions frontend/src/tests/instructor-permission-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,42 @@ export function instructorsPermissionTests(api) {
expect(respSwitchToInstOnlyUser).toHaveStatus("success");
}

async function createDDAH() {
const assignments = databaseSeeder.seededData.assignments;
/**
* Restores the active user to the default user (the user logged during test setup in beforeAll).
*
* @returns {Promise<void>}
*/
async function restoreDefaultUser() {
let respSwitchBackUser = await apiPOST(
`/debug/active_user`,
defaultUser
);
expect(respSwitchBackUser).toHaveStatus("success");
}

/**
* TODO: write comment.
*
*
* @returns {Promise<void>}
*/
async function createDDAH(intsructorId) {
// We first need to update position to include our instructor
const existingPosition = databaseSeeder.seededData.positions[0];
const updatedPosition = {
...existingPosition,
instructor_ids: [...existingPosition.instructor_ids, intsructorId],
}
const respUpdatePosition = await apiPOST(`/admin/positions`, updatedPosition);
expect(respUpdatePosition).toHaveStatus("success");

// We then proceed to create a DDAh for that position
switchToInstructorOnlyUser()
const assignments = await apiGET(`/admin/sessions/${session.id}/assignments`);
expect(assignments).toHaveStatus("success");
expect(assignments.payload.length).toBeGreaterThan(0);
const newDdah = {
assignment_id: assignments[0].id,
assignment_id: assignments.payload[0].id,
duties: [
{
order: 2,
Expand All @@ -56,23 +88,11 @@ export function instructorsPermissionTests(api) {
],
};

restoreDefaultUser()
const respCreateDDAH = await apiPOST(`/admin/ddahs`, newDdah);
expect(respCreateDDAH).toHaveStatus("success");
}

/**
* Restores the active user to the default user (the user logged during test setup in beforeAll).
*
* @returns {Promise<void>}
*/
async function restoreDefaultUser() {
let respSwitchBackUser = await apiPOST(
`/debug/active_user`,
defaultUser
);
expect(respSwitchBackUser).toHaveStatus("success");
}

beforeAll(async () => {
await databaseSeeder.seed(api);
await databaseSeeder.seedForInstructors(api);
Expand Down Expand Up @@ -510,11 +530,12 @@ export function instructorsPermissionTests(api) {
utorid: instructorUser.utorid
};
await apiPOST(`/admin/instructors`, instructorObject);
await createDDAH();

await switchToInstructorOnlyUser();
let resp = await apiGET(`/instructor/sessions/${session.id}/ddahs`);
expect(resp).toHaveStatus("success");
expect(resp.payload).toHaveLength(0)
expect(resp.payload).toHaveLength(1)
});

it.todo("fetch Ddahs a position associated with self");
Expand Down

0 comments on commit 35157be

Please sign in to comment.