-
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
233 additions
and
12 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,80 @@ | ||
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/organization_fields.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/organization_fields/${id}.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/organization_fields.json`, | ||
headers, | ||
data | ||
}; | ||
}, | ||
|
||
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/organization_fields/${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/organization_fields/${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/organization_fields/reorder.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const Joi = require('@hapi/joi'); | ||
|
||
const id = Joi.number().min(1); | ||
const data = Joi.object(); | ||
|
||
module.exports = { | ||
list: null, // no options | ||
show: options => Joi.validate(options, { id: id.required() }), | ||
create: options => Joi.validate(options, { data: data.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() }) | ||
}; |
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,127 @@ | ||
const endpoint = require('../../../../src/v2/support/organization_fields'); | ||
|
||
const instance = 'instance'; | ||
const url = `https://${instance}.zendesk.com`; | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
Authorization: 'Basic <64bit_encoded_credentials>' | ||
}; | ||
|
||
describe('organizations', () => { | ||
let organization_fields; | ||
|
||
beforeEach(() => (organization_fields = endpoint({ instance, headers }))); | ||
afterEach(() => (organization_fields = null)); | ||
|
||
describe('list organization fields', () => { | ||
it('should process w/ valid input', () => { | ||
expect(organization_fields.list()).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/organization_fields.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => organization_fields.list('invalid')).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('show organization field', () => { | ||
it('should process w/ valid input', () => { | ||
expect(organization_fields.show({ id: 123 })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/v2/organization_fields/123.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => organization_fields.show()).toThrowError(); | ||
expect(() => organization_fields.show({})).toThrowError(); | ||
expect(() => organization_fields.show('invalid')).toThrowError(); | ||
expect(() => organization_fields.show({ id: 0 })).toThrowError(); | ||
expect(() => organization_fields.show({ id: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('create organization fields', () => { | ||
it('should process w/ valid input', () => { | ||
expect(organization_fields.create({ data: {} })).toEqual({ | ||
method: 'POST', | ||
url: `${url}/api/v2/organization_fields.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => organization_fields.create()).toThrowError(); | ||
expect(() => organization_fields.create({})).toThrowError(); | ||
expect(() => organization_fields.create('invalid')).toThrowError(); | ||
expect(() => | ||
organization_fields.create({ ids: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('update organization fields', () => { | ||
it('should process w/ valid input', () => { | ||
expect(organization_fields.update({ id: 123, data: {} })).toEqual({ | ||
method: 'PUT', | ||
url: `${url}/api/v2/organization_fields/123.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => organization_fields.update()).toThrowError(); | ||
expect(() => organization_fields.update({})).toThrowError(); | ||
expect(() => organization_fields.update('invalid')).toThrowError(); | ||
expect(() => | ||
organization_fields.update({ data: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('delete organization fields', () => { | ||
it('should process w/ valid input', () => { | ||
expect(organization_fields.delete({ id: 123 })).toEqual({ | ||
method: 'DELETE', | ||
url: `${url}/api/v2/organization_fields/123.json`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => organization_fields.delete()).toThrowError(); | ||
expect(() => organization_fields.delete({})).toThrowError(); | ||
expect(() => organization_fields.delete('invalid')).toThrowError(); | ||
expect(() => organization_fields.delete({ id: 0 })).toThrowError(); | ||
expect(() => | ||
organization_fields.delete({ id: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('reorder organization field', () => { | ||
it('should process w/ valid input', () => { | ||
expect(organization_fields.reorder({ data: {} })).toEqual({ | ||
method: 'PUT', | ||
url: `${url}/api/v2/organization_fields/reorder.json`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => organization_fields.reorder()).toThrowError(); | ||
expect(() => organization_fields.reorder({})).toThrowError(); | ||
expect(() => organization_fields.reorder('invalid')).toThrowError(); | ||
expect(() => | ||
organization_fields.reorder({ data: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
}); |
7667122
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.
resolves #45