From e6b10e5188ff604a82167a83fd08781b3e2e5303 Mon Sep 17 00:00:00 2001 From: ElrohirGT Date: Sun, 17 Nov 2024 14:52:12 -0600 Subject: [PATCH] fix: StudentTraumatologicalHistory --- .../index.integration.test.mjs | 32 +++++++++++++++++-- .../index.mjs | 10 ++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/sanitas_backend/src/handlers/UpdateStudentTraumatologicalHistory/index.integration.test.mjs b/sanitas_backend/src/handlers/UpdateStudentTraumatologicalHistory/index.integration.test.mjs index 0875f2a5..70d68f85 100644 --- a/sanitas_backend/src/handlers/UpdateStudentTraumatologicalHistory/index.integration.test.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentTraumatologicalHistory/index.integration.test.mjs @@ -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, @@ -33,7 +33,7 @@ describe("Update Traumatologic History integration tests", () => { const validHeaders = createAuthorizationHeader(createPatientJWT()); let patientId; - beforeAll(async () => { + beforeEach(async () => { patientId = await createTestPatient(); }); @@ -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, { diff --git a/sanitas_backend/src/handlers/UpdateStudentTraumatologicalHistory/index.mjs b/sanitas_backend/src/handlers/UpdateStudentTraumatologicalHistory/index.mjs index 972e4b22..010546ca 100644 --- a/sanitas_backend/src/handlers/UpdateStudentTraumatologicalHistory/index.mjs +++ b/sanitas_backend/src/handlers/UpdateStudentTraumatologicalHistory/index.mjs @@ -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. @@ -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)