Skip to content

Commit 64af6f0

Browse files
author
Ilya Nevolin
committed
bugfixes and cleanup
1 parent 923077a commit 64af6f0

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

spurwing.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ const Spurwing = (function() {
1111
return this
1212
}
1313

14-
this.get_appointment_types = async function(provider_id, clients_can_book) {
15-
return await this.HTTP('GET', this.API_URL + 'appointment_types.json', { provider_id, clients_can_book })
14+
this.get_appointment_types = async function(provider_id, page_size, offset) {
15+
return await this.HTTP('GET', this.API_URL + 'appointment_types.json', { provider_id, page_size, offset })
1616
}
17-
this.get_days_available = async function(provider_id, appointment_type_id, date_from_month, timezone, org_level) {
18-
return await this.HTTP('GET', this.API_URL + 'bookings/days_available.json', { provider_id, appointment_type_id, date_from_month, timezone, org_level })
17+
this.get_days_available = async function(provider_id, appointment_type_id, date_from_month, organization_level, timezone) {
18+
return await this.HTTP('GET', this.API_URL + 'bookings/days_available.json', { provider_id, appointment_type_id, date_from_month, organization_level, timezone })
1919
}
20-
this.get_slots_available = async function(provider_id, appointment_type_id, start_date, end_date, org_level) {
21-
return await this.HTTP('GET', this.API_URL + 'bookings/slots_available.json', { provider_id, appointment_type_id, start_date, end_date, org_level })
20+
this.get_slots_available = async function(provider_id, appointment_type_id, start_date, end_date, organization_level, timezone) {
21+
return await this.HTTP('GET', this.API_URL + 'bookings/slots_available.json', { provider_id, appointment_type_id, start_date, end_date, organization_level, timezone })
2222
}
23-
this.complete_booking = async function(provider_id, appointment_type_id, date, timezone, first_name, last_name, email, phone_number, contact_type) {
24-
return await this.HTTP('POST', this.API_URL + 'bookings/complete_booking.json', { provider_id, appointment_type_id, date, timezone, first_name, last_name, email, phone_number, contact_type })
23+
this.complete_booking = async function(provider_id, appointment_type_id, email, first_name, last_name, date, contact_type, appointment_id, appointment_location_id, timezone, video_chat_url) {
24+
return await this.HTTP('POST', this.API_URL + 'bookings/complete_booking.json', { provider_id, appointment_type_id, email, first_name, last_name, date, contact_type, appointment_id, appointment_location_id, timezone, video_chat_url })
2525
}
26-
this.list_appointments = async function(authorization, page_size, offset, provider_id) {
27-
return await this.HTTP('GET', this.API_URL + 'appointments', { page_size, offset, provider_id }, { authorization: 'Bearer ' + authorization })
26+
this.list_appointments = async function(authorization, page_size, offset, appointment_category, load_attendees, load_providers, load_appointment_type) {
27+
return await this.HTTP('GET', this.API_URL + 'appointments', { page_size, offset, appointment_category, load_attendees, load_providers, load_appointment_type }, { authorization: 'Bearer ' + authorization })
2828
}
29-
this.delete_appointment = async function(appointment_id, authorization) {
29+
this.delete_appointment = async function(authorization, appointment_id) {
3030
return await this.HTTP('DELETE', this.API_URL + 'appointments/' + appointment_id, {}, { authorization: 'Bearer ' + authorization })
3131
}
3232

@@ -66,8 +66,11 @@ const Spurwing = (function() {
6666
if (!obj)
6767
return '';
6868
let urlData = '';
69-
for (let x in obj)
69+
for (let x in obj) {
70+
if (typeof obj[x] === 'undefined' || obj[x] == null)
71+
continue;
7072
urlData = urlData + x + '=' + encodeURIComponent(obj[x]) + '&';
73+
}
7174
urlData = urlData.substr(0, (urlData.length - 1));
7275
return urlData;
7376
}

tests.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const urlParams = new URLSearchParams(window.location.search);
1212
const PID = urlParams.get('pid'); // 'your spurwing provider-id';
1313
const KEY = urlParams.get('key') // 'your spurwing api-key'
1414

15+
if (!PID || !KEY) {
16+
console.error('missing pid / key')
17+
}
18+
1519
async function runner(testname, func) {
1620
try {
1721
console.log(testname, 'STARTED')
@@ -27,34 +31,35 @@ async function runner(testname, func) {
2731

2832
await runner('TEST 1', (async() => {
2933
let sp = new Spurwing();
30-
let tz = "Europe/Brussels";
3134

32-
let A = await sp.get_appointment_types(PID, true)
35+
let A = await sp.get_appointment_types(PID)
3336
console.log({A})
3437
A.should.have.lengthOf(3) // default 3
3538

36-
let B = await sp.get_days_available(PID, A[0].id, dateNow(), tz, false)
39+
let appointment_type_id = A[0].id;
40+
41+
let B = await sp.get_days_available(PID, appointment_type_id)
3742
console.log({B})
3843
expect(B.days_available.length).to.be.at.least(1) // at least one day available this month
3944

40-
let C = await sp.get_slots_available(PID, A[0].id, dateNow(), dateTomorrow(), false)
45+
let C = await sp.get_slots_available(PID, appointment_type_id, dateNow(), dateTomorrow())
4146
console.log({C})
4247
expect(C.slots_available.length).to.be.at.least(10) // each day has 96 15min slots (60*24 / 15 == 96)
4348

4449
let slot = C.slots_available[5].date
45-
let D = await sp.complete_booking(PID, A[0].id, slot, tz, 'Ilya', 'Nevolin', 'ilya2@nevolin.be', '111-111-7777', 'My Contact Type');
50+
let D = await sp.complete_booking(PID, appointment_type_id, 'ilya2@nevolin.be', 'Ilya', 'Nevo', slot, 'Test booking');
4651
console.log({D})
4752
D.should.have.property('appointment')
4853
expect(D.appointment.length).to.equal(60)
4954

50-
let E = await sp.list_appointments(KEY, 1000, 0, PID)
55+
let E = await sp.list_appointments(KEY, 1000, 0)
5156
console.log({E})
5257
E.should.have.property('data')
5358
E.data.should.have.property('appointments')
5459
expect(E.data.appointmentsCount).to.be.at.least(1)
5560

5661
let apid = D.appointment.id;
57-
let F = await sp.delete_appointment(apid, KEY)
62+
let F = await sp.delete_appointment(KEY, apid)
5863
console.log({F})
5964
F.should.have.property('data')
6065
F.data.should.have.property('appointment')
@@ -64,7 +69,7 @@ async function runner(testname, func) {
6469

6570
await runner('TEST 2', (async() => {
6671
let sp = new Spurwing();
67-
let A = await sp.list_appointments(KEY, 1000, 0, PID)
72+
let A = await sp.list_appointments(KEY, 1000, 0)
6873
console.log({A})
6974
A.should.have.property('data')
7075
A.data.should.have.property('appointments')

0 commit comments

Comments
 (0)