-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 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,50 @@ | ||
const Joi = require('@hapi/joi'); | ||
const { validate, prepare } = require('../../utils/options'); | ||
|
||
// Validation | ||
const _id = Joi.number().positive(); | ||
|
||
// Initialize Endpoint | ||
module.exports = (options = {}) => { | ||
const { error } = validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { url, headers } = prepare(options); | ||
|
||
return { | ||
/** | ||
* List Reasons for Satisfaction Rating | ||
* | ||
* GET /api/v2/satisfaction_reasons.json | ||
* https://developer.zendesk.com/rest_api/docs/support/satisfaction_reasons#list-reasons-for-satisfaction-rating | ||
*/ | ||
list: () => { | ||
// Ignore any options | ||
return { | ||
method: 'GET', | ||
url: `${url}/api/v2/satisfaction_reasons.json`, | ||
headers | ||
}; | ||
}, | ||
|
||
/** | ||
* Show Reason for Satisfaction Rating | ||
* | ||
* GET /api/v2/satisfaction_reasons/{id}.json | ||
* https://developer.zendesk.com/rest_api/docs/support/satisfaction_reasons#show-reason-for-satisfaction-rating | ||
*/ | ||
show: (options = {}) => { | ||
const { error } = Joi.object({ | ||
id: _id.required() | ||
}).validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { id } = options; | ||
return { | ||
method: 'GET', | ||
url: `${url}/api/v2/satisfaction_reasons/${id}.json`, | ||
headers | ||
}; | ||
} | ||
}; | ||
}; |
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,60 @@ | ||
const endpoint = require('../../../../src/api/support/satisfaction_reasons'); | ||
const { prepare } = require('../../../../src/utils/options'); | ||
|
||
describe('ticket skips', () => { | ||
let endPoint, options, url, headers; | ||
|
||
beforeEach(() => { | ||
options = { | ||
instance: 'instance', | ||
email: 'user@email.com', | ||
token: 'token' | ||
}; | ||
endPoint = endpoint(options); | ||
({ url, headers } = prepare(options)); | ||
}); | ||
|
||
afterEach(() => { | ||
options = null; | ||
endPoint = null; | ||
url = null; | ||
headers = null; | ||
}); | ||
|
||
describe('init', () => { | ||
it('should setup endpoint object', () => { | ||
expect(endpoint(options)).toBeTruthy(); | ||
}); | ||
|
||
it('should fail with invalid input', () => { | ||
expect(() => endpoint()).toThrowError(); | ||
expect(() => endpoint({})).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('list reasons for satisfaction rating', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.list()).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/satisfaction_reasons.json`, | ||
headers | ||
}); | ||
}); | ||
}); | ||
|
||
describe('show reason for satisfaction rating', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.show({ id: 123 })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/satisfaction_reasons/123.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => endPoint.show()).toThrowError(); | ||
expect(() => endPoint.show({})).toThrowError(); | ||
expect(() => endPoint.show({ id: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
}); |