Skip to content

Commit

Permalink
fix: StudentTraumatologicalHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
ElrohirGT committed Nov 17, 2024
1 parent aeb6603 commit e6b10e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeAll, describe, expect, test } from "@jest/globals";
import { beforeEach, describe, expect, test } from "@jest/globals";
import axios from "axios";
import {
createAuthorizationHeader,
Expand Down Expand Up @@ -33,7 +33,7 @@ describe("Update Traumatologic History integration tests", () => {
const validHeaders = createAuthorizationHeader(createPatientJWT());
let patientId;

beforeAll(async () => {
beforeEach(async () => {
patientId = await createTestPatient();
});

Expand All @@ -53,6 +53,34 @@ describe("Update Traumatologic History integration tests", () => {
expect(medicalHistory.traumas.data[0].whichBone).toBe("Femur");
});

test("Can have 3+ antecedents", async () => {
const traumatologicHistoryData = generateValidUpdate(patientId);
let response = await axios.post(API_URL, traumatologicHistoryData, {
headers: validHeaders,
});
expect(response.status).toBe(200);

traumatologicHistoryData.medicalHistory.traumas.data.push({
whichBone: "Femur",
year: "2020",
treatment: "Cali",
});
response = await axios.post(API_URL, traumatologicHistoryData, {
headers: validHeaders,
});
expect(response.status).toBe(200);

traumatologicHistoryData.medicalHistory.traumas.data.unshift({
whichBone: "Femur",
year: "2013",
treatment: "Oral",
});
response = await axios.post(API_URL, traumatologicHistoryData, {
headers: validHeaders,
});
expect(response.status).toBe(200);
});

test("Can't modify existing data", async () => {
const traumatologicHistoryData = generateValidUpdate(patientId);
await axios.post(API_URL, traumatologicHistoryData, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { getPgClient, isDoctor, SCHEMA_NAME, transaction } from "db-conn";
import { logger, withRequest } from "logging";
import { createResponse } from "utils";
import { mapToAPITraumatologicHistory } from "utils";
import {
decodeJWT,
requestDataEditsDBData,
toSafeEvent,
} from "utils/index.mjs";
import { decodeJWT, requestIsSuperset, toSafeEvent } from "utils/index.mjs";

/**
* Handles the HTTP POST request to update or create the traumatologic history for a specific patient.
Expand Down Expand Up @@ -103,8 +99,8 @@ export const handler = async (event, context) => {
logger.info({ oldData }, "Data of the patient in DB currently...");
logger.info({ newData }, "Data coming in...");

const repeatingData = requestDataEditsDBData(newData, oldData);
if (repeatingData) {
const onlyAddsData = requestIsSuperset(oldData, newData, logger);
if (!onlyAddsData) {
logger.error("Student trying to update info already saved!");
const response = responseBuilder
.setStatusCode(403)
Expand Down

0 comments on commit e6b10e5

Please sign in to comment.