Skip to content

Commit

Permalink
built support:ticket_metric_events
Browse files Browse the repository at this point in the history
  • Loading branch information
androozka committed Feb 1, 2020
1 parent 16ed065 commit 804df54
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/api/support/ticket_metric_events.js
Original file line number Diff line number Diff line change
@@ -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
};
}
};
};
50 changes: 50 additions & 0 deletions tests/src/api/support/ticket_metric_events.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});

0 comments on commit 804df54

Please sign in to comment.