-
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
5 changed files
with
206 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
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,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 | ||
}; | ||
} | ||
}; | ||
}; |
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,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() }) | ||
}; |
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
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,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(); | ||
}); | ||
}); | ||
}); |