Skip to content

Commit

Permalink
built sunshine:object_events
Browse files Browse the repository at this point in the history
  • Loading branch information
androozka committed Jan 28, 2020
1 parent c3edefb commit 1dc89cf
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/api/sunshine/object_events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// const Joi = require('@hapi/joi');
const { validate, prepare } = require('../../utils/options');

// Validation
// const _id = Joi.number().positive();
// 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 Custom Objects Events
*
* GET api/sunshine/objects/events
* https://developer.zendesk.com/rest_api/docs/sunshine/object_events#list-custom-objects-events
*/
list: () => {
// Ignore any options
return {
method: 'GET',
url: `${url}/api/sunshine/objects/events`,
headers
};
}
};
};
45 changes: 45 additions & 0 deletions tests/src/api/sunshine/object_events.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const endpoint = require('../../../../src/api/sunshine/object_events');
const { prepare } = require('../../../../src/utils/options');

describe('object records', () => {
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 Custom Objects Events', () => {
it('should process valid input', () => {
expect(endPoint.list()).toEqual({
method: 'GET',
url: `${url}/api/sunshine/objects/events`,
headers
});
});
});
});

0 comments on commit 1dc89cf

Please sign in to comment.