-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
129 lines (103 loc) · 3.81 KB
/
tests.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright Spurwing.io and Healthie Inc.
* Released under the MIT license
* https://www.spurwing.io/
*/
// chai testing framework: https://www.chaijs.com/guide/styles/
chai.should();
const expect = chai.expect;
const urlParams = new URLSearchParams(window.location.search);
const PID = urlParams.get('pid'); // 'your spurwing provider-id';
const KEY = urlParams.get('key') // 'your spurwing api-key'
if (!PID || !KEY) {
console.error('missing pid / key')
}
async function runner(testname, func) {
try {
console.log(testname, 'STARTED')
await func()
console.log(testname, 'PASSED')
} catch (err) {
console.error(testname, 'FAILED')
// console.error(err)
throw err;
}
}
(async () => {
await runner('TEST 1', (async() => {
let sp = new Spurwing();
let A = await sp.get_appointment_types(PID)
console.log({A})
expect(A.length).to.be.at.least(1)
let appointment_type_id = A[0].id;
let B = await sp.get_days_available(PID, appointment_type_id)
console.log({B})
expect(B.days_available.length).to.be.at.least(1) // at least one day available this month
let C = await sp.get_slots_available(PID, appointment_type_id, dateNow(), dateTomorrow())
console.log({C})
expect(C.slots_available.length).to.be.at.least(10) // each day has 96 15min slots (60*24 / 15 == 96)
let slot = C.slots_available[5].date
let D = await sp.complete_booking(PID, appointment_type_id, '[email protected]', 'Ilya', 'Nevo', slot, 'Test booking');
console.log({D})
D.should.have.property('appointment')
expect(D.appointment.length).to.equal(60)
let E = await sp.list_appointments(KEY, 1000, 0)
console.log({E})
E.should.have.property('data')
E.data.should.have.property('appointments')
expect(E.data.appointmentsCount).to.be.at.least(1)
let apid = D.appointment.id;
let F = await sp.delete_appointment(KEY, apid)
console.log({F})
F.should.have.property('data')
F.data.should.have.property('appointment')
F.data.appointment.id.should.equal(D.appointment.id)
F.errors.should.have.lengthOf(0)
}));
await runner('TEST 2', (async() => {
let sp = new Spurwing();
let A = await sp.list_appointments(KEY, 1000, 0)
console.log({A})
A.should.have.property('data')
A.data.should.have.property('appointments')
}));
await runner('TEST 3', (async() => {
let sp = new Spurwing();
let A = await sp.get_appointment_types(PID)
console.log({A})
expect(A.length).to.be.at.least(1)
let appointment_type_id = A[3].id;
let B = await sp.create_group_appointment(KEY, PID, appointment_type_id, dateTomorrow() + ' 16:00:00')
console.log({B})
B.should.have.property('data')
B.data.should.have.property('appointment')
B.data.appointment.should.have.property('id')
let apid = B.data.appointment.id
async function add_attendee(fn, ln, email) {
let D = await sp.complete_booking(PID, appointment_type_id, email, fn, ln, null, null, apid);
console.log({D})
D.should.have.property('appointment')
}
await add_attendee('john', 'G', '[email protected]')
await add_attendee('bill', 'H', '[email protected]')
let E = await sp.list_appointments(KEY, 1000, 0)
console.log({E})
let F = await sp.delete_appointment(KEY, apid)
console.log({F})
F.should.have.property('data')
F.data.should.have.property('appointment')
F.data.appointment.id.should.equal(apid)
F.errors.should.have.lengthOf(0)
}));
})();
//////////////////////////////
////// helper functions //////
//////////////////////////////
function dateNow() {
let d = new Date();
return d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
}
function dateTomorrow() {
let d = new Date();
d.setDate(d.getDate() + 1);
return d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
}