This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
AppointmentRepository.test.ts
62 lines (48 loc) · 2.12 KB
/
AppointmentRepository.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import AppointmentRepository from 'clients/db/AppointmentRepository'
import { appointments, patients } from 'config/pouchdb'
import Appointment from 'model/Appointment'
const uuidV4Regex = /^[A-F\d]{8}-[A-F\d]{4}-4[A-F\d]{3}-[89AB][A-F\d]{3}-[A-F\d]{12}$/i
describe('Appointment Repository', () => {
it('should create a repository with the database set to the appointments database', () => {
expect(AppointmentRepository.db).toEqual(appointments)
})
describe('find', () => {
it('should find an appointment by id', async () => {
await appointments.put({ _id: 'id5678' })
const expectedAppointment = await appointments.put({ _id: 'id1234' })
const actualAppointment = await AppointmentRepository.find('id1234')
expect(actualAppointment).toBeDefined()
expect(actualAppointment.id).toEqual(expectedAppointment.id)
await appointments.remove(await appointments.get('id1234'))
await appointments.remove(await appointments.get('id5678'))
})
})
describe('searchPatientAppointments', () => {
it('should escape all special chars from search text', async () => {
await patients.put({ _id: 'id2222' })
await appointments.put({ _id: 'id3333', patientId: 'id2222', location: 'id-]?}(){*[$+.^\\' })
const result = await AppointmentRepository.searchPatientAppointments(
'id2222',
'id-]?}(){*[$+.^\\',
)
expect(result).toHaveLength(1)
expect(result[0].id).toEqual('id3333')
})
})
describe('save', () => {
it('should create an id that is a uuid', async () => {
const newAppointment = await AppointmentRepository.save({
patientId: 'id',
} as Appointment)
expect(uuidV4Regex.test(newAppointment.id)).toBeTruthy()
await appointments.remove(await appointments.get(newAppointment.id))
})
it('should generate a timestamp for created date and last updated date', async () => {
const newAppointment = await AppointmentRepository.save({
patientId: 'id',
} as Appointment)
expect(newAppointment.createdAt).toBeDefined()
expect(newAppointment.updatedAt).toBeDefined()
})
})
})