-
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.
Merge pull request #69 from androozka/support-ticket-comments
built support.ticketComments closes #28
- Loading branch information
Showing
5 changed files
with
185 additions
and
1 deletion.
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,57 @@ | ||
const validate = require('../../validators/support/ticketComments'); | ||
|
||
module.exports = ({ instance, headers }) => { | ||
const url = `https://${instance}.zendesk.com`; | ||
|
||
return { | ||
list: (options = {}) => { | ||
const { error } = validate.list(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { ticket_id } = options; | ||
return { | ||
method: 'GET', | ||
url: `${url}/api/v2/tickets/${ticket_id}/comments.json`, | ||
headers | ||
}; | ||
}, | ||
|
||
emailCCs: (options = {}) => { | ||
const { error } = validate.emailCCs(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { ticket_id } = options; | ||
return { | ||
method: 'GET', | ||
url: `${url}/api/v2/tickets/${ticket_id}/comments.json?include=users`, | ||
headers | ||
}; | ||
}, | ||
|
||
redact: (options = {}) => { | ||
const { error } = validate.redact(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { ticket_id, id, data } = options; | ||
return { | ||
method: 'PUT', | ||
url: `${url}/api/v2/tickets/${ticket_id}/comments/${id}/redact.json`, | ||
headers, | ||
data | ||
}; | ||
}, | ||
|
||
makePrivate: (options = {}) => { | ||
const { error } = validate.makePrivate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { ticket_id, id } = options; | ||
return { | ||
method: 'PUT', | ||
url: `${url}/api/v2/tickets/${ticket_id}/comments/${id}/make_private.json`, | ||
headers, | ||
data: {} | ||
}; | ||
} | ||
}; | ||
}; |
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,22 @@ | ||
const Joi = require('@hapi/joi'); | ||
|
||
const id = Joi.number().min(1); | ||
const ticket_id = Joi.number().min(1); | ||
const data = Joi.object(); | ||
|
||
module.exports = { | ||
list: options => Joi.validate(options, { ticket_id: ticket_id.required() }), | ||
emailCCs: options => | ||
Joi.validate(options, { ticket_id: ticket_id.required() }), | ||
redact: options => | ||
Joi.validate(options, { | ||
ticket_id: ticket_id.required(), | ||
id: id.required(), | ||
data: data.required() | ||
}), | ||
makePrivate: options => | ||
Joi.validate(options, { | ||
ticket_id: ticket_id.required(), | ||
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,100 @@ | ||
const endpoint = require('../../../../../../src/api/v2/routes/support/ticketComments'); | ||
|
||
const instance = 'instance'; | ||
const url = `https://${instance}.zendesk.com`; | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
Authorization: 'Basic <64bit_encoded_credentials>' | ||
}; | ||
|
||
describe('ticket comments', () => { | ||
let ticketComments; | ||
|
||
beforeEach(() => (ticketComments = endpoint({ instance, headers }))); | ||
afterEach(() => (ticketComments = null)); | ||
|
||
describe('list comments', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketComments.list({ ticket_id: 123 })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/tickets/123/comments.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketComments.list()).toThrowError(); | ||
expect(() => ticketComments.list('invalid')).toThrowError(); | ||
expect(() => | ||
ticketComments.list({ ticket_id: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('list email ccs for a comment', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketComments.emailCCs({ ticket_id: 123 })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/tickets/123/comments.json?include=users`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketComments.emailCCs()).toThrowError(); | ||
expect(() => ticketComments.emailCCs('invalid')).toThrowError(); | ||
expect(() => | ||
ticketComments.emailCCs({ ticket_id: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('redact string in comment', () => { | ||
it('should process w/ valid input', () => { | ||
expect( | ||
ticketComments.redact({ ticket_id: 123, id: 456, data: {} }) | ||
).toEqual({ | ||
method: 'PUT', | ||
url: `${url}/api/v2/tickets/123/comments/456/redact.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketComments.redact()).toThrowError(); | ||
expect(() => ticketComments.redact('invalid')).toThrowError(); | ||
expect(() => | ||
ticketComments.redact({ ticket_id: 'invalid' }) | ||
).toThrowError(); | ||
expect(() => | ||
ticketComments.redact({ ticket_id: 123, id: 'invalid' }) | ||
).toThrowError(); | ||
expect(() => | ||
ticketComments.redact({ ticket_id: 123, id: 456, data: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('make comment private', () => { | ||
it('should process w/ valid input', () => { | ||
expect(ticketComments.makePrivate({ ticket_id: 123, id: 456 })).toEqual({ | ||
method: 'PUT', | ||
url: `${url}/api/v2/tickets/123/comments/456/make_private.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => ticketComments.makePrivate()).toThrowError(); | ||
expect(() => ticketComments.makePrivate('invalid')).toThrowError(); | ||
expect(() => | ||
ticketComments.makePrivate({ ticket_id: 'invalid' }) | ||
).toThrowError(); | ||
expect(() => | ||
ticketComments.makePrivate({ ticket_id: 123, id: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
}); |
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