From c02e7cd52d13506745d42545e66b8e1eac766cab Mon Sep 17 00:00:00 2001 From: androozka Date: Fri, 24 Jan 2020 12:54:48 -0800 Subject: [PATCH] built support:app_installation_locations --- src/api/support/app_installation_locations.js | 51 ++++++++++++++++ .../app_installation_locations.test.js | 61 +++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 src/api/support/app_installation_locations.js create mode 100644 tests/src/api/support/app_installation_locations.test.js diff --git a/src/api/support/app_installation_locations.js b/src/api/support/app_installation_locations.js new file mode 100644 index 0000000..239e2ba --- /dev/null +++ b/src/api/support/app_installation_locations.js @@ -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 + }; + } + }; +}; diff --git a/tests/src/api/support/app_installation_locations.test.js b/tests/src/api/support/app_installation_locations.test.js new file mode 100644 index 0000000..086be54 --- /dev/null +++ b/tests/src/api/support/app_installation_locations.test.js @@ -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(); + }); + }); +});