Skip to content

Commit

Permalink
built support.ticket_activities
Browse files Browse the repository at this point in the history
  • Loading branch information
androozka committed Sep 2, 2019
1 parent 18aed24 commit 40473e5
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/v2/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = ({ instance, headers }) => ({
organization_fields: require('./organization_fields')({ instance, headers }),
search: require('./search')({ instance, headers }),
tags: require('./tags')({ instance, headers }),
ticket_activities: require('./ticket_activities')({ instance, headers }),
ticket_comments: require('./ticket_comments')({ instance, headers }),
ticket_fields: require('./ticket_fields')({ instance, headers }),
ticket_forms: require('./ticket_forms')({ instance, headers }),
Expand Down
29 changes: 29 additions & 0 deletions src/v2/support/ticket_activities/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const validate = require('./validate');

module.exports = ({ instance, headers }) => {
const url = `https://${instance}.zendesk.com`;

return {
list: (options = null) => {
if (options) throw new Error('no options are allowed');

return {
method: 'GET',
url: `${url}/api/v2/activities.json`,
headers
};
},

show: (options = {}) => {
const { error } = validate.show(options);
if (error) throw new Error(error.details[0].message);

const { activity_id } = options;
return {
method: 'GET',
url: `${url}/api/v2/activities/${activity_id}.json`,
headers
};
}
};
};
9 changes: 9 additions & 0 deletions src/v2/support/ticket_activities/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Joi = require('@hapi/joi');

const activity_id = Joi.number().min(1);

module.exports = {
list: null, // no options
show: options =>
Joi.validate(options, { activity_id: activity_id.required() })
};
1 change: 1 addition & 0 deletions tests/src/v2/support.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('support api', () => {
test('organization_fields', () => check(support.organization_fields));
test('search', () => check(support.search, 'function'));
test('tags', () => check(support.tags));
test('ticket_activities', () => check(support.ticket_activities));
test('ticket_comments', () => check(support.ticket_comments));
test('ticket_fields', () => check(support.ticket_fields));
test('ticket_forms', () => check(support.ticket_forms));
Expand Down
48 changes: 48 additions & 0 deletions tests/src/v2/support/ticket_activities.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const endpoint = require('../../../../src/v2/support/ticket_activities');

const instance = 'instance';
const url = `https://${instance}.zendesk.com`;
const headers = {
'Content-Type': 'application/json',
Authorization: 'Basic <64bit_encoded_credentials>'
};

describe('end users', () => {
let ticket_activities;

beforeEach(() => (ticket_activities = endpoint({ instance, headers })));
afterEach(() => (ticket_activities = null));

describe('list activities', () => {
it('should process w/ valid input', () => {
expect(ticket_activities.list()).toEqual({
method: 'GET',
url: `${url}/api/v2/activities.json`,
headers
});
});

it('should throw error w/ invalid input', () => {
expect(() => ticket_activities.list('invalid')).toThrowError();
});
});

describe('show activity', () => {
it('should process w/ valid input', () => {
expect(ticket_activities.show({ activity_id: 123 })).toEqual({
method: 'GET',
url: `${url}/api/v2/activities/123.json`,
headers
});
});

it('should throw error w/ invalid input', () => {
expect(() => ticket_activities.show()).toThrowError();
expect(() => ticket_activities.show('invalid')).toThrowError();
expect(() => ticket_activities.show({})).toThrowError();
expect(() =>
ticket_activities.show({ activity_id: 'invalid' })
).toThrowError();
});
});
});

1 comment on commit 40473e5

@androozka
Copy link
Owner Author

@androozka androozka commented on 40473e5 Sep 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolves #31

Please sign in to comment.