diff --git a/src/api/support/ticket_metric_events.js b/src/api/support/ticket_metric_events.js new file mode 100644 index 0000000..6d178fc --- /dev/null +++ b/src/api/support/ticket_metric_events.js @@ -0,0 +1,35 @@ +const Joi = require('@hapi/joi'); +const { validate, prepare } = require('../../utils/options'); + +// Validation +const _unix_time = 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 ticket metric events + * + * GET /api/v2/incremental/ticket_metric_events.json?start_time={unix_time} + * https://developer.zendesk.com/rest_api/docs/support/ticket_metric_events#list-ticket-metric-events + */ + list: (options = {}) => { + const { error } = Joi.object({ + unix_time: _unix_time.required() + }).validate(options); + if (error) throw new Error(error.details[0].message); + + const { unix_time } = options; + return { + method: 'GET', + url: `${url}/api/v2/incremental/ticket_metric_events.json?start_time=${unix_time}`, + headers + }; + } + }; +}; diff --git a/tests/src/api/support/ticket_metric_events.test.js b/tests/src/api/support/ticket_metric_events.test.js new file mode 100644 index 0000000..5e4742f --- /dev/null +++ b/tests/src/api/support/ticket_metric_events.test.js @@ -0,0 +1,50 @@ +const endpoint = require('../../../../src/api/support/ticket_metric_events'); +const { prepare } = require('../../../../src/utils/options'); + +describe('Ticket Metric Events', () => { + 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 ticket metric events', () => { + it('should process w/ valid input', () => { + expect(endPoint.list({ unix_time: 123 })).toEqual({ + method: 'GET', + url: `${url}/api/v2/incremental/ticket_metric_events.json?start_time=123`, + headers + }); + }); + + it('should throw error w/ invalid input', () => { + expect(() => endPoint.list()).toThrowError(); + expect(() => endPoint.list({})).toThrowError(); + expect(() => endPoint.list({ unix_time: 'invalid' })).toThrowError(); + }); + }); +});