Skip to content

Commit

Permalink
built support.suspended_tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
androozka committed Sep 5, 2019
1 parent c6526f2 commit fe5bf37
Show file tree
Hide file tree
Showing 5 changed files with 206 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 @@ -4,6 +4,7 @@ module.exports = ({ instance, headers }) => ({
organizations: require('./organizations')({ instance, headers }),
organization_fields: require('./organization_fields')({ instance, headers }),
search: require('./search')({ instance, headers }),
suspended_tickets: require('./suspended_tickets')({ instance, headers }),
tags: require('./tags')({ instance, headers }),
ticket_activities: require('./ticket_activities')({ instance, headers }),
ticket_comments: require('./ticket_comments')({ instance, headers }),
Expand Down
77 changes: 77 additions & 0 deletions src/v2/support/suspended_tickets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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/suspended_tickets.json`,
headers
};
},

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

const { id } = options;
return {
method: 'GET',
url: `${url}/api/v2/suspended_tickets/${id}.json`,
headers
};
},

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

const { id } = options;
return {
method: 'PUT',
url: `${url}/api/v2/suspended_tickets/${id}/recover.json`,
headers
};
},

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

const { ids } = options;
return {
method: 'PUT',
url: `${url}/api/v2/suspended_tickets/recover_many.json?ids=${ids}`,
headers
};
},

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

const { id } = options;
return {
method: 'DELETE',
url: `${url}/api/v2/suspended_tickets/${id}.json`,
headers
};
},

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

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

const id = Joi.number().min(1);
const ids = Joi.string().min(3);

module.exports = {
list: null, // no options
show: options => Joi.validate(options, { id: id.required() }),
recover: options => Joi.validate(options, { id: id.required() }),
recover_many: options => Joi.validate(options, { ids: ids.required() }),
delete: options => Joi.validate(options, { id: id.required() }),
delete_many: options => Joi.validate(options, { ids: ids.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 @@ -16,6 +16,7 @@ describe('support api', () => {
test('organizations', () => check(support.organizations));
test('organization_fields', () => check(support.organization_fields));
test('search', () => check(support.search, 'function'));
test('suspended_tickets', () => check(support.suspended_tickets));
test('tags', () => check(support.tags));
test('ticket_activities', () => check(support.ticket_activities));
test('ticket_comments', () => check(support.ticket_comments));
Expand Down
114 changes: 114 additions & 0 deletions tests/src/v2/support/suspended_tickets.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const endpoint = require('../../../../src/v2/support/suspended_tickets');

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

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

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

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

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

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

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

describe('recover suspended ticket', () => {
it('should process w/ valid input', () => {
expect(suspended_tickets.recover({ id: 123 })).toEqual({
method: 'PUT',
url: `${url}/api/v2/suspended_tickets/123/recover.json`,
headers
});
});

it('should throw error w/ invalid input', () => {
expect(() => suspended_tickets.recover()).toThrowError();
expect(() => suspended_tickets.recover('invalid')).toThrowError();
expect(() => suspended_tickets.recover({})).toThrowError();
expect(() => suspended_tickets.recover({ id: 'invalid' })).toThrowError();
});
});

describe('recover multiple suspended tickets', () => {
it('should process w/ valid input', () => {
expect(suspended_tickets.recover_many({ ids: '1,2,3' })).toEqual({
method: 'PUT',
url: `${url}/api/v2/suspended_tickets/recover_many.json?ids=1,2,3`,
headers
});
});

it('should throw error w/ invalid input', () => {
expect(() => suspended_tickets.recover_many()).toThrowError();
expect(() => suspended_tickets.recover_many('invalid')).toThrowError();
expect(() => suspended_tickets.recover_many({})).toThrowError();
expect(() => suspended_tickets.recover_many({ ids: 0 })).toThrowError();
});
});

describe('delete suspended ticket', () => {
it('should process w/ valid input', () => {
expect(suspended_tickets.delete({ id: 123 })).toEqual({
method: 'DELETE',
url: `${url}/api/v2/suspended_tickets/123.json`,
headers
});
});

it('should throw error w/ invalid input', () => {
expect(() => suspended_tickets.delete()).toThrowError();
expect(() => suspended_tickets.delete('invalid')).toThrowError();
expect(() => suspended_tickets.delete({})).toThrowError();
expect(() => suspended_tickets.delete({ id: 'invalid' })).toThrowError();
});
});

describe('delete multiple suspended tickets', () => {
it('should process w/ valid input', () => {
expect(suspended_tickets.delete_many({ ids: '1,2,3' })).toEqual({
method: 'DELETE',
url: `${url}/api/v2/suspended_tickets/destroy_many.json?ids=1,2,3`,
headers
});
});

it('should throw error w/ invalid input', () => {
expect(() => suspended_tickets.delete_many()).toThrowError();
expect(() => suspended_tickets.delete_many('invalid')).toThrowError();
expect(() => suspended_tickets.delete_many({})).toThrowError();
expect(() => suspended_tickets.delete_many({ ids: 0 })).toThrowError();
});
});
});

0 comments on commit fe5bf37

Please sign in to comment.