-
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
4 changed files
with
214 additions
and
87 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,102 @@ | ||
const Joi = require('@hapi/joi'); | ||
const { validate, prepare } = require('../../utils/options'); | ||
|
||
// Validation | ||
const _id = Joi.number().min(1); | ||
const _ticket_id = Joi.number().min(1); | ||
const _data = Joi.object(); | ||
|
||
// Initialize Endpoint | ||
module.exports = (options = {}) => { | ||
const { error } = validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { url, headers } = prepare(options); | ||
|
||
return { | ||
/** | ||
* List Comments | ||
* | ||
* GET /api/v2/tickets/{ticket_id}/comments.json | ||
* https://developer.zendesk.com/rest_api/docs/support/ticket_comments#list-comments | ||
*/ | ||
list: (options = {}) => { | ||
const { error } = Joi.object({ | ||
ticket_id: _ticket_id.required() | ||
}).validate(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 | ||
}; | ||
}, | ||
|
||
/** | ||
* List Email CCs for a Comment | ||
* | ||
* GET /api/v2/tickets/{ticket_id}/comments.json?include=users | ||
* https://developer.zendesk.com/rest_api/docs/support/ticket_comments#list-email-ccs-for-a-comment | ||
*/ | ||
emailCCs: (options = {}) => { | ||
const { error } = Joi.object({ | ||
ticket_id: _ticket_id.required() | ||
}).validate(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 String in Comment | ||
* | ||
* PUT /api/v2/tickets/{ticket_id}/comments/{id}/redact.json | ||
* https://developer.zendesk.com/rest_api/docs/support/ticket_comments#redact-string-in-comment | ||
*/ | ||
redact: (options = {}) => { | ||
const { error } = Joi.object({ | ||
ticket_id: _ticket_id.required(), | ||
id: _id.required(), | ||
data: _data.required() | ||
}).validate(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 | ||
}; | ||
}, | ||
|
||
/** | ||
* Make Comment Private | ||
* | ||
* PUT /api/v2/tickets/{ticket_id}/comments/{id}/make_private.json | ||
* https://developer.zendesk.com/rest_api/docs/support/ticket_comments#make-comment-private | ||
*/ | ||
makePrivate: (options = {}) => { | ||
const { error } = Joi.object({ | ||
ticket_id: _ticket_id.required(), | ||
id: _id.required() | ||
}).validate(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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,112 @@ | ||
const endpoint = require('../../../src/api/support/ticket_comments'); | ||
const { prepare } = require('../../../src/utils/options'); | ||
|
||
describe('object types', () => { | ||
let endPoint, options, url, headers; | ||
|
||
beforeEach(() => { | ||
options = { | ||
instance: 'instance', | ||
email: 'user@email.com', | ||
token: 'token' | ||
}; | ||
endPoint = endpoint(options); | ||
({ url, headers } = prepare(options)); | ||
}); | ||
|
||
afterEach(() => { | ||
options = null; | ||
endPoint = null; | ||
url = null; | ||
headers = null; | ||
}); | ||
|
||
describe('init', () => { | ||
it('should setup endpoint object', () => { | ||
const ep = endpoint(options); | ||
expect(ep).toBeTruthy(); | ||
}); | ||
|
||
it('should fail with invalid input', () => { | ||
expect(() => endpoint()).toThrowError(); | ||
expect(() => endpoint({})).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('list comments', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.list({ ticket_id: 123 })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/tickets/123/comments.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => endPoint.list()).toThrowError(); | ||
expect(() => endPoint.list('invalid')).toThrowError(); | ||
expect(() => endPoint.list({ ticket_id: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('list email ccs for a comment', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.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(() => endPoint.emailCCs()).toThrowError(); | ||
expect(() => endPoint.emailCCs('invalid')).toThrowError(); | ||
expect(() => endPoint.emailCCs({ ticket_id: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('redact string in comment', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.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(() => endPoint.redact()).toThrowError(); | ||
expect(() => endPoint.redact('invalid')).toThrowError(); | ||
expect(() => endPoint.redact({ ticket_id: 'invalid' })).toThrowError(); | ||
expect(() => | ||
endPoint.redact({ ticket_id: 123, id: 'invalid' }) | ||
).toThrowError(); | ||
expect(() => | ||
endPoint.redact({ ticket_id: 123, id: 456, data: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('make comment private', () => { | ||
it('should process w/ valid input', () => { | ||
expect(endPoint.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(() => endPoint.makePrivate()).toThrowError(); | ||
expect(() => endPoint.makePrivate('invalid')).toThrowError(); | ||
expect(() => | ||
endPoint.makePrivate({ ticket_id: 'invalid' }) | ||
).toThrowError(); | ||
expect(() => | ||
endPoint.makePrivate({ ticket_id: 123, id: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
}); |