-
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
198 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = ({ instance, headers }) => ({ | ||
sunshine: require('./sunshine')({ instance, headers }), | ||
support: require('./support')({ instance, 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,3 @@ | ||
module.exports = ({ instance, headers }) => ({ | ||
object_types: require('./object_types')({ instance, 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,87 @@ | ||
const Joi = require('@hapi/joi'); | ||
|
||
const _key = Joi.string() | ||
.min(2) | ||
.max(32); | ||
const _data = Joi.object({ | ||
key: _key, | ||
schema: Joi.object({ | ||
properties: Joi.object(), | ||
required: Joi.array() | ||
}), | ||
end_users_can_read: Joi.bool() | ||
}); | ||
|
||
module.exports = ({ instance, headers }) => { | ||
const url = `https://${instance}.zendesk.com`; | ||
|
||
return { | ||
list: () => { | ||
// Ignore any options | ||
return { | ||
method: 'GET', | ||
url: `${url}/api/sunshine/objects/types`, | ||
headers | ||
}; | ||
}, | ||
|
||
show: (options = {}) => { | ||
const { error } = Joi.object({ | ||
key: _key.required() | ||
}).validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { key } = options; | ||
return { | ||
method: 'GET', | ||
url: `${url}/api/sunshine/objects/types/${key}`, | ||
headers | ||
}; | ||
}, | ||
|
||
create: (options = {}) => { | ||
const { error } = Joi.object({ | ||
data: _data.required() | ||
}).validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { data } = options; | ||
return { | ||
method: 'POST', | ||
url: `${url}/api/sunshine/objects/types`, | ||
headers, | ||
data | ||
}; | ||
}, | ||
|
||
update: (options = {}) => { | ||
const { error } = Joi.object({ | ||
key: _key.required(), | ||
data: _data.required() | ||
}).validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { key, data } = options; | ||
return { | ||
method: 'PUT', | ||
url: `${url}/api/sunshine/objects/types/${key}`, | ||
headers, | ||
data | ||
}; | ||
}, | ||
|
||
delete: (options = {}) => { | ||
const { error } = Joi.object({ | ||
key: _key.required() | ||
}).validate(options); | ||
if (error) throw new Error(error.details[0].message); | ||
|
||
const { key } = options; | ||
return { | ||
method: 'DELETE', | ||
url: `${url}/api/sunshine/objects/types/${key}`, | ||
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,107 @@ | ||
const endpoint = require('../../../../src/v2/sunshine/object_types'); | ||
|
||
const instance = 'instance'; | ||
const url = `https://${instance}.zendesk.com`; | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
Authorization: 'Basic <64bit_encoded_credentials>' | ||
}; | ||
|
||
describe('object types', () => { | ||
let objectTypes; | ||
|
||
beforeEach(() => (objectTypes = endpoint({ instance, headers }))); | ||
afterEach(() => (objectTypes = null)); | ||
|
||
describe('list object types', () => { | ||
it('should process, ignores additional input', () => { | ||
expect(objectTypes.list()).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/sunshine/objects/types`, | ||
headers | ||
}); | ||
}); | ||
}); | ||
|
||
describe('show object type', () => { | ||
it('should process w/ valid input', () => { | ||
expect(objectTypes.show({ key: 'valid' })).toEqual({ | ||
method: 'GET', | ||
url: `${url}/api/sunshine/objects/types/valid`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => objectTypes.show()).toThrowError(); | ||
expect(() => objectTypes.show({})).toThrowError(); | ||
expect(() => objectTypes.show('invalid')).toThrowError(); | ||
expect(() => objectTypes.show({ key: 123 })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('create object type', () => { | ||
it('should process w/ valid input', () => { | ||
const data = { | ||
key: 'valid', | ||
schema: { | ||
properties: {}, | ||
required: ['valid'] | ||
}, | ||
end_users_can_read: false | ||
}; | ||
|
||
expect(objectTypes.create({ data })).toEqual({ | ||
method: 'POST', | ||
url: `${url}/api/sunshine/objects/types`, | ||
headers, | ||
data | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => objectTypes.create()).toThrowError(); | ||
expect(() => objectTypes.create({})).toThrowError(); | ||
expect(() => objectTypes.create('invalid')).toThrowError(); | ||
expect(() => objectTypes.create({ data: 'invalid' })).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('update custom role', () => { | ||
it('should process w/ valid input', () => { | ||
expect(objectTypes.update({ key: 'valid', data: {} })).toEqual({ | ||
method: 'PUT', | ||
url: `${url}/api/sunshine/objects/types/valid`, | ||
headers, | ||
data: {} | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => objectTypes.update()).toThrowError(); | ||
expect(() => objectTypes.update({})).toThrowError(); | ||
expect(() => objectTypes.update('invalid')).toThrowError(); | ||
expect(() => objectTypes.update({ key: 0 })).toThrowError(); | ||
expect(() => | ||
objectTypes.update({ key: 'valid', data: 'invalid' }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('delete custom role', () => { | ||
it('should process w/ valid input', () => { | ||
expect(objectTypes.delete({ key: 'valid' })).toEqual({ | ||
method: 'DELETE', | ||
url: `${url}/api/sunshine/objects/types/valid`, | ||
headers | ||
}); | ||
}); | ||
|
||
it('should throw error w/ invalid input', () => { | ||
expect(() => objectTypes.delete()).toThrowError(); | ||
expect(() => objectTypes.delete({})).toThrowError(); | ||
expect(() => objectTypes.delete('invalid')).toThrowError(); | ||
expect(() => objectTypes.delete({ key: 123 })).toThrowError(); | ||
}); | ||
}); | ||
}); |