-
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
171 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,81 @@ | ||
const Joi = require('@hapi/joi'); | ||
const { validate, prepare } = require('../../utils/options'); | ||
|
||
// Validation | ||
const _params = Joi.string().min(1); | ||
const _id = Joi.number().positive(); | ||
const _ticket_id = Joi.number().positive(); | ||
const _data = Joi.object(); | ||
|
||
// 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 Satisfaction Ratings | ||
* | ||
* GET /api/v2/satisfaction_ratings.json | ||
* https://developer.zendesk.com/rest_api/docs/support/satisfaction_ratings#list-satisfaction-ratings | ||
*/ | ||
list: (options = {}) => { | ||
const { error } = Joi.object({ | ||
params: _params | ||
}).validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { params } = options; | ||
const paramStr = params ? `?${params}` : ''; | ||
return { | ||
method: 'GET', | ||
url: `${url}/api/v2/satisfaction_ratings.json${paramStr}`, | ||
headers | ||
}; | ||
}, | ||
|
||
/** | ||
* Show Satisfaction Rating | ||
* | ||
* GET /api/v2/satisfaction_ratings/{id}.json | ||
* https://developer.zendesk.com/rest_api/docs/support/satisfaction_ratings#show-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_ratings/${id}.json`, | ||
headers | ||
}; | ||
}, | ||
|
||
/** | ||
* Create a Satisfaction Rating | ||
* | ||
* POST /api/v2/tickets/{ticket_id}/satisfaction_rating.json | ||
* https://developer.zendesk.com/rest_api/docs/support/satisfaction_ratings#create-a-satisfaction-rating | ||
*/ | ||
create: (options = {}) => { | ||
const { error } = Joi.object({ | ||
ticket_id: _ticket_id.required(), | ||
data: _data.required() | ||
}).validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { ticket_id, data } = options; | ||
return { | ||
method: 'POST', | ||
url: `${url}/api/v2/tickets/${ticket_id}/satisfaction_rating.json`, | ||
headers, | ||
data | ||
}; | ||
} | ||
}; | ||
}; |
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,90 @@ | ||
const endpoint = require('../../../../src/api/support/satisfaction_ratings'); | ||
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 satisfaction ratings', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.list()).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/satisfaction_ratings.json`, | ||
headers | ||
}); | ||
|
||
expect(endPoint.list({ params: 'score=good' })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/satisfaction_ratings.json?score=good`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => endPoint.list({ params: 123 })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('show satisfaction rating', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.show({ id: 123 })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/satisfaction_ratings/123.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => endPoint.show()).toThrowError(); | ||
expect(() => endPoint.show({})).toThrowError(); | ||
expect(() => endPoint.show({ id: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('create satisfaction rating', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.create({ ticket_id: 123, data: {} })).toEqual({ | ||
method: 'POST', | ||
url: `${url}/api/v2/tickets/123/satisfaction_rating.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => endPoint.create()).toThrowError(); | ||
expect(() => endPoint.create({})).toThrowError(); | ||
expect(() => endPoint.create({ ticket_id: 'invalid' })).toThrowError(); | ||
expect(() => | ||
endPoint.create({ ticket_id: 123, data: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
}); |