Skip to content

Commit

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

// Validation
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 Location Installations
*
* GET /api/v2/apps/location_installations.json
* https://developer.zendesk.com/rest_api/docs/support/app_location_installations#list-location-installations
*/
list: () => {
// Ignore any options
return {
method: 'GET',
url: `${url}/api/v2/apps/location_installations.json`,
headers
};
},

/**
* Reorder App Installations For Location
*
* POST /api/v2/apps/location_installations/reorder.json
* https://developer.zendesk.com/rest_api/docs/support/app_location_installations#reorder-app-installations-for-location
*/
reorder: (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/v2/apps/location_installations/reorder.json`,
headers,
data
};
}
};
};
61 changes: 61 additions & 0 deletions tests/src/api/support/app_installation_locations.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const endpoint = require('../../../../src/api/support/app_installation_locations');
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', () => {
expect(endpoint(options)).toBeTruthy();
});

it('should fail with invalid input', () => {
expect(() => endpoint()).toThrowError();
expect(() => endpoint({})).toThrowError();
});
});

describe('list location installations', () => {
it('should process w/ valid input', () => {
expect(endPoint.list()).toEqual({
method: 'GET',
url: `${url}/api/v2/apps/location_installations.json`,
headers
});
});
});

describe('reorder app installations for location', () => {
it('should process w/ valid input', () => {
expect(endPoint.reorder({ data: {} })).toEqual({
method: 'POST',
url: `${url}/api/v2/apps/location_installations/reorder.json`,
headers,
data: {}
});
});

it('should throw error w/ invalid input', () => {
expect(() => endPoint.reorder()).toThrowError();
expect(() => endPoint.reorder({})).toThrowError();
expect(() => endPoint.reorder({ data: 'invalid' })).toThrowError();
});
});
});

0 comments on commit c02e7cd

Please sign in to comment.