-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Jira [Link al issue en Jira](Link%20al%20clickup) ## Descripción <!-- Ingresa una descripción de la PR aquí --> ## Tasks <!-- Asegúrate de cumplir todas estas tareas antes de hacer la PR. --> - \[x] Asignate a tí mismo dentro de la PR. - \[x] Asegúrate que el nombre de la PR siga el formato de [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). - \[x] Añade una breve descripción de la escencia de tus cambios en tu PR. - \[x] Agrega el link al issue de Jira. - \[x] Asegurate que la PR pase todos los chequeos de CI. - \[x] Ponle las tags correspondientes a tu PR. Backend: PRs que modifican lógica relacionada al backend. Frontend: PRs que modifican lógica relacionada al frontend. Database: PRs que modifican lógica relacionada a la base de datos. Wiki: PRs que editan la wiki. Nix: PRs que modifican el entorno de desarrollo en Nix. CI/CD: PRs relacionadas con la CI/CD pipeline.
- Loading branch information
Showing
36 changed files
with
723 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...tas_backend/src/handlers/PatientCreatePatient/patient-create-patient.integration.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import axios from "axios"; | ||
import { | ||
createAuthorizationHeader, | ||
createDoctorJWT, | ||
createInvalidJWT, | ||
createPatientJWT, | ||
generateUniqueCUI, | ||
LOCAL_API_URL, | ||
} from "../testHelpers.mjs"; | ||
|
||
const API_URL = `${LOCAL_API_URL}/patient/create`; | ||
|
||
function generateValidUpdate(cui) { | ||
return { | ||
cui, | ||
names: "Juan", | ||
lastNames: "Pérez", | ||
isWoman: false, | ||
birthdate: "1990-01-01", | ||
phone: "55247856", | ||
insurance: "El Roble", | ||
}; | ||
} | ||
|
||
describe("Create Patient Record Integration Tests", () => { | ||
const validHeaders = createAuthorizationHeader(createPatientJWT()); | ||
|
||
test("Normal case: Create a new patient record", async () => { | ||
const patientData = generateValidUpdate(generateUniqueCUI()); | ||
const response = await axios.post(API_URL, patientData, { | ||
headers: validHeaders, | ||
}); | ||
|
||
const expectedResponse = expect.any(Number); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.data).toEqual(expectedResponse); | ||
}); | ||
|
||
test("Create a new patient record without CUI (should fail)", async () => { | ||
const patientData = generateValidUpdate(generateUniqueCUI()); | ||
patientData.cui = undefined; | ||
|
||
const response = await axios.post(API_URL, patientData, { | ||
headers: validHeaders, | ||
validateStatus: () => true, // So axios doesn't throw an error for status >= 400 | ||
}); | ||
|
||
// Verify the error is as expected | ||
expect(response.status).toBe(400); | ||
expect(response.data.error).toBe("CUI is empty"); | ||
}); | ||
|
||
test("Create a new patient record with duplicate CUI (should fail)", async () => { | ||
const uniqueCUI = generateUniqueCUI(); | ||
const patientData1 = { | ||
cui: uniqueCUI, | ||
names: "Juan", | ||
lastNames: "Pérez", | ||
isWoman: false, | ||
birthdate: "1990-01-01", | ||
phone: "55247856", | ||
insurance: "El Roble", | ||
}; | ||
const patientData2 = { | ||
cui: uniqueCUI, | ||
names: "Carlos", | ||
lastNames: "González", | ||
isWoman: false, | ||
birthdate: "1985-05-05", | ||
phone: "55247856", | ||
insurance: "El Roble", | ||
}; | ||
|
||
await axios.post(API_URL, patientData1, { headers: validHeaders }); | ||
|
||
const response = await axios.post(API_URL, patientData2, { | ||
headers: validHeaders, | ||
validateStatus: () => true, // So axios doesn't throw an error for status >= 400 | ||
}); | ||
|
||
// Verify the error is as expected | ||
expect(response.status).toBe(409); | ||
expect(response.data.error).toBe("CUI already exists."); | ||
}); | ||
|
||
test("Can't create a new patient with incomplete data", async () => { | ||
const data = { | ||
cui: generateUniqueCUI(), | ||
names: "Juan", | ||
lastNames: "Pérez", | ||
}; | ||
|
||
const response = await axios.post(API_URL, data, { | ||
validateStatus: () => true, | ||
headers: validHeaders, | ||
}); | ||
expect(response.status).toBe(400); | ||
expect(response.data.error).toBe("Gender (isWoman) is required."); | ||
}); | ||
|
||
test("a doctor can't call the endpoint", async () => { | ||
const postData = generateValidUpdate(generateUniqueCUI()); | ||
const specialHeaders = createAuthorizationHeader(createDoctorJWT()); | ||
|
||
const response = await axios.post(API_URL, postData, { | ||
headers: specialHeaders, | ||
validateStatus: () => true, | ||
}); | ||
|
||
console.log(response.data); | ||
|
||
expect(response.status).toBe(401); | ||
expect(response.data.error).toEqual("Unauthorized, you're a doctor!"); | ||
}); | ||
|
||
test("can't be called by a malformed JWT", async () => { | ||
const postData = generateValidUpdate(generateUniqueCUI()); | ||
const specialHeaders = createAuthorizationHeader(createInvalidJWT()); | ||
|
||
const response = await axios.post(API_URL, postData, { | ||
headers: specialHeaders, | ||
validateStatus: () => true, | ||
}); | ||
|
||
expect(response.status).toBe(400); | ||
expect(response.data).toEqual({ error: "JWT couldn't be parsed" }); | ||
}); | ||
}); |
Oops, something went wrong.