-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const validate = require('../../validators/support/ticketForms'); | ||
|
||
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/ticket_forms.json`, | ||
headers | ||
}; | ||
}, | ||
|
||
create: (options = {}) => { | ||
const { error } = validate.create(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { data } = options; | ||
return { | ||
method: 'POST', | ||
url: `${url}/api/v2/ticket_forms.json`, | ||
headers, | ||
data | ||
}; | ||
}, | ||
|
||
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/ticket_forms/${id}.json`, | ||
headers | ||
}; | ||
}, | ||
|
||
show_many: (options = {}) => { | ||
const { error } = validate.show_many(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { ids } = options; | ||
return { | ||
method: 'GET', | ||
url: `${url}/api/v2/ticket_forms/show_many.json?ids=${ids}`, | ||
headers | ||
}; | ||
}, | ||
|
||
update: (options = {}) => { | ||
const { error } = validate.update(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { id, data } = options; | ||
return { | ||
method: 'PUT', | ||
url: `${url}/api/v2/ticket_forms/${id}.json`, | ||
headers, | ||
data | ||
}; | ||
}, | ||
|
||
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/ticket_forms/${id}.json`, | ||
headers | ||
}; | ||
}, | ||
|
||
reorder: (options = {}) => { | ||
const { error } = validate.reorder(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { data } = options; | ||
return { | ||
method: 'PUT', | ||
url: `${url}/api/v2/ticket_forms/reorder.json`, | ||
headers, | ||
data | ||
}; | ||
}, | ||
|
||
clone: (options = {}) => { | ||
const { error } = validate.clone(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { id } = options; | ||
return { | ||
method: 'POST', | ||
url: `${url}/api/v2/ticket_forms/${id}/clone.json`, | ||
headers | ||
}; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const Joi = require('@hapi/joi'); | ||
|
||
const id = Joi.number().min(1); | ||
const ids = Joi.string().min(3); | ||
const data = Joi.object(); | ||
|
||
module.exports = { | ||
list: null, // no options | ||
create: options => Joi.validate(options, { data: data.required() }), | ||
show: options => Joi.validate(options, { id: id.required() }), | ||
show_many: options => Joi.validate(options, { ids: ids.required() }), | ||
update: options => | ||
Joi.validate(options, { id: id.required(), data: data.required() }), | ||
delete: options => Joi.validate(options, { id: id.required() }), | ||
reorder: options => Joi.validate(options, { data: data.required() }), | ||
clone: options => Joi.validate(options, { id: id.required() }) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
const endpoint = require('../../../../../../src/api/v2/routes/support/ticketForms'); | ||
|
||
const instance = 'instance'; | ||
const url = `https://${instance}.zendesk.com`; | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
Authorization: 'Basic <64bit_encoded_credentials>' | ||
}; | ||
|
||
describe('ticket forms', () => { | ||
let ticketForms; | ||
|
||
beforeEach(() => (ticketForms = endpoint({ instance, headers }))); | ||
afterEach(() => (ticketForms = null)); | ||
|
||
describe('list ticket forms', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketForms.list()).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/ticket_forms.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketForms.list('invalid')).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('create ticket forms', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketForms.create({ data: {} })).toEqual({ | ||
method: 'POST', | ||
url: `${url}/api/v2/ticket_forms.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketForms.create()).toThrowError(); | ||
expect(() => ticketForms.create({})).toThrowError(); | ||
expect(() => ticketForms.create('invalid')).toThrowError(); | ||
expect(() => ticketForms.create({ data: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('show ticket form', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketForms.show({ id: 123 })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/ticket_forms/123.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketForms.show()).toThrowError(); | ||
expect(() => ticketForms.show({})).toThrowError(); | ||
expect(() => ticketForms.show('invalid')).toThrowError(); | ||
expect(() => ticketForms.show({ id: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('show many ticket forms', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketForms.show_many({ ids: '1,2,3' })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/ticket_forms/show_many.json?ids=1,2,3`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketForms.show_many()).toThrowError(); | ||
expect(() => ticketForms.show_many({})).toThrowError(); | ||
expect(() => ticketForms.show_many('invalid')).toThrowError(); | ||
expect(() => ticketForms.show_many({ ids: 0 })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('update ticket forms', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketForms.update({ id: 123, data: {} })).toEqual({ | ||
method: 'PUT', | ||
url: `${url}/api/v2/ticket_forms/123.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketForms.update()).toThrowError(); | ||
expect(() => ticketForms.update({})).toThrowError(); | ||
expect(() => ticketForms.update('invalid')).toThrowError(); | ||
expect(() => ticketForms.update({ id: 0 })).toThrowError(); | ||
expect(() => ticketForms.update({ id: 'invalid' })).toThrowError(); | ||
expect(() => | ||
ticketForms.update({ id: 123, data: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('delete ticket form', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketForms.delete({ id: 123 })).toEqual({ | ||
method: 'DELETE', | ||
url: `${url}/api/v2/ticket_forms/123.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketForms.delete()).toThrowError(); | ||
expect(() => ticketForms.delete({})).toThrowError(); | ||
expect(() => ticketForms.delete('invalid')).toThrowError(); | ||
expect(() => ticketForms.delete({ id: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('reorder ticket forms', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketForms.reorder({ data: {} })).toEqual({ | ||
method: 'PUT', | ||
url: `${url}/api/v2/ticket_forms/reorder.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketForms.reorder()).toThrowError(); | ||
expect(() => ticketForms.reorder({})).toThrowError(); | ||
expect(() => ticketForms.reorder('invalid')).toThrowError(); | ||
expect(() => ticketForms.reorder({ data: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('clone an already existing ticket form', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketForms.clone({ id: 123 })).toEqual({ | ||
method: 'POST', | ||
url: `${url}/api/v2/ticket_forms/123/clone.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketForms.clone()).toThrowError(); | ||
expect(() => ticketForms.clone({})).toThrowError(); | ||
expect(() => ticketForms.clone('invalid')).toThrowError(); | ||
expect(() => ticketForms.clone({ id: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
}); |
083c00f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closes #8