From bff07f0e8580b392a88897b12e636d3d63091fbe Mon Sep 17 00:00:00 2001 From: androozka Date: Tue, 21 Jan 2020 21:26:27 -0800 Subject: [PATCH] build support:satisfaction_reasons --- src/api/support/satisfaction_reasons.js | 50 ++++++++++++++++ .../api/support/satisfaction_reasons.test.js | 60 +++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/api/support/satisfaction_reasons.js create mode 100644 tests/src/api/support/satisfaction_reasons.test.js diff --git a/src/api/support/satisfaction_reasons.js b/src/api/support/satisfaction_reasons.js new file mode 100644 index 0000000..3f38b23 --- /dev/null +++ b/src/api/support/satisfaction_reasons.js @@ -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 + }; + } + }; +}; diff --git a/tests/src/api/support/satisfaction_reasons.test.js b/tests/src/api/support/satisfaction_reasons.test.js new file mode 100644 index 0000000..795476b --- /dev/null +++ b/tests/src/api/support/satisfaction_reasons.test.js @@ -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(); + }); + }); +});