Skip to content

Commit

Permalink
chore(test/appointments/create): add test for mandatory field when de…
Browse files Browse the repository at this point in the history
…leting an appointment
  • Loading branch information
oussamaouss committed Aug 24, 2017
1 parent 78f9b86 commit 1c75b9c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/class/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export default class SDK extends Configuration {
if (response.status >= 400) throw new Error("cancelAppointment: Bad response from server")
return response.json()
})
.then(deletedAppointement => {
this._checkErrorCode(deletedAppointement)
return deletedAppointement
})
}

/**
Expand Down
23 changes: 23 additions & 0 deletions test/appointments/cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import test from 'ava'
import sdk from '../../src/lib'
import SDK from '../../src/class/sdk'
import mock from 'fetch-mock'
import {MissingMandatoryParameter} from '../../src/class/exceptions'

let instance = {}

Expand All @@ -13,6 +14,7 @@ test.before(t => {


test('Cancel appointment', t => {
mock.restore()
mock.post(instance.url + instance.routes.cancelAppointment, {"errorCode": null})

return instance.cancelAppointment({
Expand All @@ -22,5 +24,26 @@ test('Cancel appointment', t => {
.then((response) => t.deepEqual(response, {"errorCode": null}))
})

test('Delete appointment throws exception when missing mandatory request parameter', t => {
mock.restore()
mock.post(instance.url + instance.routes.cancelAppointment,
{
"errorCode": "MISSING_MANDATORY_PARAMETER",
"errorMessage": "Missing mandatory parameter : bookingId"
}
)

return instance.cancelAppointment({
"siteCode": "ABC"
})
.catch(e => {
t.is(e instanceof MissingMandatoryParameter, true)
t.is(e.name, `MissingMandatoryParameter`)
t.is(e.message, `Missing mandatoy parameter`)

})

})


// TODO: Tests are missing, you don't test your throwing errors

0 comments on commit 1c75b9c

Please sign in to comment.