-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add patient tests for current route features
- Loading branch information
Showing
2 changed files
with
221 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
entity: patient | ||
connectedFields: ['createdBy', 'updatedBy'] | ||
items: | ||
patient1: | ||
id: 27963f68-ebc1-408a-8bb5-8fbe54671064 | ||
firstName: John | ||
middleName: A | ||
lastName: Doe | ||
dateOfBirth: "2000-10-05T00:00:00.000Z" | ||
createdBy: '@user1' | ||
updatedBy: '@user1' |
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 |
---|---|---|
|
@@ -21,7 +21,9 @@ describe('/api/v1/patients', () => { | |
describe('POST /register', () => { | ||
it('should return an error if not an ADMIN, STAFF or VOLUNTEER user', async (t) => { | ||
const app = await build(t); | ||
const reply = await app | ||
await t.loadFixtures(); | ||
|
||
let reply = await app | ||
.inject() | ||
.post('/api/v1/patients/register') | ||
.payload({ | ||
|
@@ -32,6 +34,20 @@ describe('/api/v1/patients', () => { | |
}); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.UNAUTHORIZED); | ||
|
||
let headers = await t.authenticate('[email protected]', 'test'); | ||
reply = await app | ||
.inject() | ||
.post('/api/v1/patients/register') | ||
.payload({ | ||
firstName: 'John', | ||
middleName: 'A', | ||
lastName: 'Doe', | ||
dateOfBirth: '1990-01-01', | ||
}) | ||
.headers(headers); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.FORBIDDEN); | ||
}); | ||
|
||
it('should allow ADMIN to register a new patient', async (t) => { | ||
|
@@ -51,7 +67,13 @@ describe('/api/v1/patients', () => { | |
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.CREATED); | ||
const result = JSON.parse(reply.body); | ||
assert.ok(result.id); | ||
assert.deepStrictEqual(result, { | ||
id: result.id, | ||
firstName: 'John', | ||
middleName: 'A', | ||
lastName: 'Doe', | ||
dateOfBirth: '1990-01-01', | ||
}); | ||
}); | ||
|
||
it('should allow STAFF to register a new patient', async (t) => { | ||
|
@@ -71,7 +93,13 @@ describe('/api/v1/patients', () => { | |
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.CREATED); | ||
const result = JSON.parse(reply.body); | ||
assert.ok(result.id); | ||
assert.deepStrictEqual(result, { | ||
id: result.id, | ||
firstName: 'John', | ||
middleName: 'A', | ||
lastName: 'Doe', | ||
dateOfBirth: '1990-01-01', | ||
}); | ||
}); | ||
|
||
it('should allow VOLUNTEER to register a new patient', async (t) => { | ||
|
@@ -91,10 +119,15 @@ describe('/api/v1/patients', () => { | |
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.CREATED); | ||
const result = JSON.parse(reply.body); | ||
assert.ok(result.id); | ||
assert.deepStrictEqual(result, { | ||
id: result.id, | ||
firstName: 'John', | ||
middleName: 'A', | ||
lastName: 'Doe', | ||
dateOfBirth: '1990-01-01', | ||
}); | ||
}); | ||
|
||
|
||
it('errors if missing required fields', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
|
@@ -116,6 +149,178 @@ describe('/api/v1/patients', () => { | |
}); | ||
|
||
describe('PATCH /update/:patientId', () => { | ||
it('should return an error if not an ADMIN, STAFF or VOLUNTEER user', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
|
||
let reply = await app | ||
.inject() | ||
.patch('/api/v1/patients/update/27963f68-ebc1-408a-8bb5-8fbe54671064') | ||
.payload({ | ||
firstName: 'John', | ||
middleName: 'A', | ||
lastName: 'Doe', | ||
dateOfBirth: '1990-01-01', | ||
}); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.UNAUTHORIZED); | ||
|
||
let headers = await t.authenticate('[email protected]', 'test'); | ||
reply = await app | ||
.inject() | ||
.patch('/api/v1/patients/update/27963f68-ebc1-408a-8bb5-8fbe54671064') | ||
.payload({ | ||
firstName: 'John', | ||
middleName: 'A', | ||
lastName: 'Doe', | ||
dateOfBirth: '1990-01-01', | ||
}) | ||
.headers(headers); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.FORBIDDEN); | ||
}); | ||
|
||
it('should allow ADMIN to update a patient', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
const headers = await t.authenticate('[email protected]', 'test'); | ||
const reply = await app | ||
.inject() | ||
.patch('/api/v1/patients/update/27963f68-ebc1-408a-8bb5-8fbe54671064') | ||
.payload({ | ||
patientData: { | ||
firstName: 'Jane', | ||
dateOfBirth: '1990-01-01', | ||
}, | ||
}) | ||
.headers(headers); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.OK); | ||
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(reply.body); | ||
assert.deepStrictEqual(id, "27963f68-ebc1-408a-8bb5-8fbe54671064"); | ||
assert.deepStrictEqual(firstName, 'Jane'); | ||
assert.deepStrictEqual(middleName, 'A'); | ||
assert.deepStrictEqual(lastName, 'Doe'); | ||
assert.deepStrictEqual(dateOfBirth, '1990-01-01'); | ||
}); | ||
|
||
it('should allow STAFF to update a patient', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
const headers = await t.authenticate('[email protected]', 'test'); | ||
const reply = await app | ||
.inject() | ||
.patch('/api/v1/patients/update/27963f68-ebc1-408a-8bb5-8fbe54671064') | ||
.payload({ | ||
patientData: { | ||
firstName: 'Jack', | ||
dateOfBirth: '1990-02-01', | ||
}, | ||
}) | ||
.headers(headers); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.OK); | ||
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(reply.body); | ||
assert.deepStrictEqual(id, "27963f68-ebc1-408a-8bb5-8fbe54671064"); | ||
assert.deepStrictEqual(firstName, 'Jack'); | ||
assert.deepStrictEqual(middleName, 'A'); | ||
assert.deepStrictEqual(lastName, 'Doe'); | ||
assert.deepStrictEqual(dateOfBirth, '1990-02-01'); | ||
}); | ||
|
||
it('should allow VOLUNTEER to update a patient', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
const headers = await t.authenticate('[email protected]', 'test'); | ||
const reply = await app | ||
.inject() | ||
.patch('/api/v1/patients/update/27963f68-ebc1-408a-8bb5-8fbe54671064') | ||
.payload({ | ||
patientData: { | ||
firstName: 'Jill', | ||
dateOfBirth: '1990-03-01', | ||
}, | ||
}) | ||
.headers(headers); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.OK); | ||
const { id, firstName, middleName, lastName, dateOfBirth } = JSON.parse(reply.body); | ||
assert.deepStrictEqual(id, "27963f68-ebc1-408a-8bb5-8fbe54671064"); | ||
assert.deepStrictEqual(firstName, 'Jill'); | ||
assert.deepStrictEqual(middleName, 'A'); | ||
assert.deepStrictEqual(lastName, 'Doe'); | ||
assert.deepStrictEqual(dateOfBirth, '1990-03-01'); | ||
}); | ||
|
||
it('should allow ADMIN to update a patient with contact data', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
const headers = await t.authenticate('[email protected]', 'test'); | ||
const reply = await app | ||
.inject() | ||
.patch('/api/v1/patients/update/27963f68-ebc1-408a-8bb5-8fbe54671064') | ||
.payload({ | ||
contactData: { | ||
firstName: 'Jane', | ||
lastName: 'Doe', | ||
phone: '123-456-7890', | ||
relationship: 'Mother', | ||
}, | ||
}) | ||
.headers(headers); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.OK); | ||
const { emergencyContact } = JSON.parse(reply.body); | ||
assert.deepStrictEqual(emergencyContact, { | ||
id: emergencyContact.id, | ||
firstName: 'Jane', | ||
middleName: '', | ||
lastName: 'Doe', | ||
phone: '123-456-7890', | ||
relationship: 'Mother', | ||
}); | ||
|
||
}); | ||
|
||
it('should allow ADMIN to update a patient with medical data', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
const headers = await t.authenticate('[email protected]', 'test'); | ||
const reply = await app | ||
.inject() | ||
.patch('/api/v1/patients/update/27963f68-ebc1-408a-8bb5-8fbe54671064') | ||
.payload({ | ||
medicalData: { | ||
allergies: [ | ||
{ | ||
id: '5c057fc3-15d2-40fc-b664-707d04ba66c2', | ||
}, | ||
], | ||
medications: [ | ||
{ | ||
id: '583c7775-9466-4dab-8a4d-edf1056f097f', | ||
}, | ||
], | ||
conditions: [ | ||
{ | ||
id: '471c8529-81fc-4129-8ca0-f1b7406ed90c', | ||
}, | ||
], | ||
}, | ||
}) | ||
.headers(headers); | ||
|
||
assert.deepStrictEqual(reply.statusCode, StatusCodes.OK); | ||
const { id, firstName, middleName, lastName, dateOfBirth, allergies, medications, conditions } = JSON.parse(reply.body); | ||
assert.deepStrictEqual(id, "27963f68-ebc1-408a-8bb5-8fbe54671064"); | ||
assert.deepStrictEqual(firstName, 'John'); | ||
assert.deepStrictEqual(middleName, 'A'); | ||
assert.deepStrictEqual(lastName, 'Doe'); | ||
assert.deepStrictEqual(dateOfBirth, '2000-10-05'); | ||
assert.deepStrictEqual(allergies[0].id, '5c057fc3-15d2-40fc-b664-707d04ba66c2'); | ||
assert.deepStrictEqual(medications[0].id, '583c7775-9466-4dab-8a4d-edf1056f097f'); | ||
assert.deepStrictEqual(conditions[0].id, '471c8529-81fc-4129-8ca0-f1b7406ed90c'); | ||
}); | ||
|
||
}); | ||
}); |