diff --git a/README.md b/README.md index 7f20103..8c03a39 100644 --- a/README.md +++ b/README.md @@ -16,57 +16,50 @@ A JS library for interacting with the Zendesk API. - Send prepared object directly to axios 🤯 - Mirrors [Zendesk's API documentation](https://developer.zendesk.com/rest_api/docs/zendesk-apis/resources) 👀 -## Installing +_**Note**: Only v2 framework, [v1 deprecated](https://support.zendesk.com/hc/en-us/articles/360002106888-Removal-of-Zendesk-Apps-framework-v1)_ -### Using npm +## Installing ```bash +# using npm npm install @androozka/zendesk-api-js -``` - -### Using yarn -```bash +# using yarn yarn add @androozka/zendesk-api-js ``` ## Usage -### Suggested libraries +### Getting Started ```javascript -const base64 = require("js-base64").Base64; -const axios = require("axios"); +const axios = require('axios'); // Suggested library +const zdApi = require('@androozka/zendesk-api-js'); ``` -### Zendesk account information +### Zendesk Info ```javascript -const instance = ""; // Name of Zendesk instance -const email = ""; // Email address of Zendesk user -const token = ""; // Generated Zendesk token - -const encoded = base64.encode(`${email}/token:${token}`); - -const headers = { - "Content-Type": "application/json", - Authorization: `Basic ${encoded}` +const options = { + instance: '', // Zendesk subdomain + email: '', // User account to perform requests + password: '', // Password for user account + token: '' // Generated Zendesk token }; +/* Note: Either "password" or "token" is required */ ``` -### Choose framework version +### Initalize ```javascript -const zdApi = require("@androozka/zendesk-api-js"); -const zaf_v2 = zdApi.v2({ instance, headers }); -``` - -- _**Note**: Only v2, [v1 being deprecated](https://support.zendesk.com/hc/en-us/articles/360002106888-Removal-of-Zendesk-Apps-framework-v1)_ +// Load entire library +const { support, sunshine } = zdApi.init(options); -### Selecting API endpoints +// Load entire API +const { tickets, groups } = zdApi.support.init(options); -```javascript -const { support, sunshine } = zaf_v2; +// Load specific endpoint +const endpoint = zdApi.support.tickets.init(options); ``` ## Examples @@ -75,8 +68,9 @@ const { support, sunshine } = zaf_v2; ```javascript try { + const tags = zdApi.support.tags.init(options); const data = { tags: ['tag_1', 'tag_2', ... ] } - const req = support.tags.add({ type: 'tickets', id: 123, data }); + const req = tags.add({ type: 'tickets', id: 123, data }); const res = await axios(req); } catch (error) { // ... @@ -89,7 +83,13 @@ try { Search, Users, End Users, Groups, Group Memberships, Custom Agent Roles, Organizations, Organization Subscriptions, Organization Memberships, Tickets, Ticket Import, Suspended Tickets, Ticket Comments, Ticket Metrics, Ticket Activities, Tags, Views, Ticket Forms, Ticket Fields, User Fields, Organization Fields -#### Under Construction +### Sunshine API + +Custom Object Types, Custom Object Records + +### Under Construction + +#### Support - [ ] Brands - [ ] User Identities diff --git a/index.js b/index.js index 8b92067..be527bd 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,20 @@ -module.exports = { - v2: ({ instance, headers }) => require('./src/v2')({ instance, headers }) +// array list for each folder in src +const fs = require('fs'); +const validate = require('./src/validate'); + +// Load all APIs +const zdAPIs = {}; +const endpoints = fs.readdirSync('./src').filter(i => i !== 'validate.js'); +endpoints.forEach(i => (zdAPIs[i] = require(`./src/${i}`))); + +const init = (options = {}) => { + const { error } = validate(options); + if (error) throw new Error(error.details[0].message); + + const api = {}; + endpoints.forEach(i => (api[i] = zdAPIs[i].init(options))); + + return api; }; + +module.exports = { init, ...zdAPIs }; diff --git a/package.json b/package.json index 86403b4..7753ea2 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "src/*" ], "dependencies": { - "@hapi/joi": "^16.1.1" + "@hapi/joi": "^16.1.1", + "js-base64": "^2.5.1" }, "devDependencies": { "@types/jest": "^24.0.18", diff --git a/src/api/sunshine/object_records.js b/src/api/sunshine/object_records.js new file mode 100644 index 0000000..b373e4f --- /dev/null +++ b/src/api/sunshine/object_records.js @@ -0,0 +1,178 @@ +const Joi = require('@hapi/joi'); +const { validate, prepare } = require('../../utils/options'); + +// Validation +const _object_type = Joi.string().min(1); +const _type = Joi.string().min(1); +const _id = Joi.number().min(1); +const _ids = Joi.string().min(1); +const _relationship_type = Joi.string().min(1); +const _external_id = Joi.string().min(1); +const _external_ids = Joi.string().min(1); +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 Object Records (by Object Type, IDs, or Relationship) + * + * GET /api/sunshine/objects/records?type={object_type} + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#list-object-records-by-type + * + * GET /api/sunshine/objects/records?ids={id, id, ...} + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#list-object-records-by-id + * + * GET /api/sunshine/objects/records/{id}/related/{relationship_type} + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#list-related-object-records + */ + list: (options = {}) => { + const { error } = Joi.object({ + object_type: _object_type, + ids: _ids, + id: _id, + relationship_type: _relationship_type + }).validate(options); + if (error) throw new Error(error.details[0].message); + + const { object_type, ids, id, relationship_type } = options; + if (!object_type && !ids && !(id && relationship_type)) + throw new Error( + 'object_type, ids, or id with relationship_type required' + ); + + return { + method: 'GET', + url: `${url}/api/sunshine/objects/records${ + object_type + ? `?type=${object_type}` + : ids + ? `?ids=${ids}` + : `/${id}/related/${relationship_type}` + }`, + headers + }; + }, + + /** + * Show Object Record (by ID, External ID, or External IDs) + * + * GET /api/sunshine/objects/records/{id} + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#show-object-record + * + * GET /api/sunshine/objects/records?type={object_type}&external_id={id} + * GET /api/sunshine/objects/records?type={object_type}&external_ids={id, id, ...} + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#show-object-record-by-external-id + * + */ + show: (options = {}) => { + const { error } = Joi.object({ + id: _id, + object_type: _object_type, + external_id: _external_id, + external_ids: _external_ids + }).validate(options); + if (error) throw new Error(error.details[0].message); + + const { id, object_type, external_id, external_ids } = options; + if (!id && !object_type) throw new Error('id or object_type required'); + if (object_type && !external_id && !external_ids) + throw new Error( + 'object_type requires either external_id or external_ids set' + ); + + return { + method: 'GET', + url: `${url}/api/sunshine/objects/records${ + id + ? `/${id}` + : `?type=${object_type}&external_id${ + external_id ? `=${external_id}` : `s=${external_ids}` + }` + }`, + headers + }; + }, + + /** + * Create Object Record + * + * POST /api/sunshine/objects/records + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#create-object-record + */ + 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/records`, + headers, + data + }; + }, + + /** + * Update Object Record (or Set by External ID) + * + * PATCH /api/sunshine/objects/records/{id} + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#update-object-record + * + * PATCH /api/sunshine/objects/records + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#set-object-record-by-external-id + */ + update: (options = {}) => { + const { error } = Joi.object({ + id: _id, + data: _data.required() + }).validate(options); + if (error) throw new Error(error.details[0].message); + + const { id, data } = options; + return { + method: 'PATCH', + url: `${url}/api/sunshine/objects/records${id ? `/${id}` : ''}`, + headers, + data + }; + }, + + /** + * Delete Object Record + * + * DELETE /api/sunshine/objects/records/{id} + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#delete-object-record + * + * DELETE /api/sunshine/objects/records?external_id={external_id}&type={type} + * https://developer.zendesk.com/rest_api/docs/sunshine/resources#delete-object-record-by-external-id + */ + delete: (options = {}) => { + const { error } = Joi.object({ + id: _id, + external_id: _external_id, + type: _type + }).validate(options); + if (error) throw new Error(error.details[0].message); + + const { id, external_id, type } = options; + if (!id && !(external_id && type)) + throw new Error('id or external_id with type required'); + + return { + method: 'DELETE', + url: `${url}/api/sunshine/objects/records${ + id ? `/${id}` : `?external_id=${external_id}&type=${type}` + }`, + headers + }; + } + }; +}; diff --git a/src/v2/sunshine/object_types.js b/src/api/sunshine/object_types.js similarity index 64% rename from src/v2/sunshine/object_types.js rename to src/api/sunshine/object_types.js index 260d9b9..1f806d7 100644 --- a/src/v2/sunshine/object_types.js +++ b/src/api/sunshine/object_types.js @@ -1,5 +1,7 @@ const Joi = require('@hapi/joi'); +const { validate, prepare } = require('../../utils/options'); +// Validation const _key = Joi.string() .min(2) .max(32); @@ -12,10 +14,20 @@ const _data = Joi.object({ end_users_can_read: Joi.bool() }); -module.exports = ({ instance, headers }) => { - const url = `https://${instance}.zendesk.com`; +// 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 Object Types + * + * GET /api/sunshine/objects/types + * https://developer.zendesk.com/rest_api/docs/sunshine/resource_types#list-object-types + */ list: () => { // Ignore any options return { @@ -25,6 +37,12 @@ module.exports = ({ instance, headers }) => { }; }, + /** + * Show Object Type + * + * GET /api/sunshine/objects/types/{key} + * https://developer.zendesk.com/rest_api/docs/sunshine/resource_types#show-object-type + */ show: (options = {}) => { const { error } = Joi.object({ key: _key.required() @@ -39,6 +57,10 @@ module.exports = ({ instance, headers }) => { }; }, + /** + * Create Object Type + * https://developer.zendesk.com/rest_api/docs/sunshine/resource_types#create-object-type + */ create: (options = {}) => { const { error } = Joi.object({ data: _data.required() @@ -54,6 +76,10 @@ module.exports = ({ instance, headers }) => { }; }, + /** + * Update Object Type + * https://developer.zendesk.com/rest_api/docs/sunshine/resource_types#update-object-type + */ update: (options = {}) => { const { error } = Joi.object({ key: _key.required(), @@ -70,6 +96,10 @@ module.exports = ({ instance, headers }) => { }; }, + /** + * Delete Object Type + * https://developer.zendesk.com/rest_api/docs/sunshine/resource_types#delete-object-type + */ delete: (options = {}) => { const { error } = Joi.object({ key: _key.required() diff --git a/src/v2/support/custom_agent_roles/index.js b/src/api/support/custom_agent_roles/index.js similarity index 100% rename from src/v2/support/custom_agent_roles/index.js rename to src/api/support/custom_agent_roles/index.js diff --git a/src/v2/support/custom_agent_roles/validate.js b/src/api/support/custom_agent_roles/validate.js similarity index 100% rename from src/v2/support/custom_agent_roles/validate.js rename to src/api/support/custom_agent_roles/validate.js diff --git a/src/v2/support/end_users/index.js b/src/api/support/end_users/index.js similarity index 100% rename from src/v2/support/end_users/index.js rename to src/api/support/end_users/index.js diff --git a/src/v2/support/end_users/validate.js b/src/api/support/end_users/validate.js similarity index 100% rename from src/v2/support/end_users/validate.js rename to src/api/support/end_users/validate.js diff --git a/src/v2/support/group_memberships/index.js b/src/api/support/group_memberships/index.js similarity index 100% rename from src/v2/support/group_memberships/index.js rename to src/api/support/group_memberships/index.js diff --git a/src/v2/support/group_memberships/validate.js b/src/api/support/group_memberships/validate.js similarity index 100% rename from src/v2/support/group_memberships/validate.js rename to src/api/support/group_memberships/validate.js diff --git a/src/v2/support/groups/index.js b/src/api/support/groups/index.js similarity index 100% rename from src/v2/support/groups/index.js rename to src/api/support/groups/index.js diff --git a/src/v2/support/groups/validate.js b/src/api/support/groups/validate.js similarity index 100% rename from src/v2/support/groups/validate.js rename to src/api/support/groups/validate.js diff --git a/src/v2/support/organization_fields/index.js b/src/api/support/organization_fields/index.js similarity index 100% rename from src/v2/support/organization_fields/index.js rename to src/api/support/organization_fields/index.js diff --git a/src/v2/support/organization_fields/validate.js b/src/api/support/organization_fields/validate.js similarity index 100% rename from src/v2/support/organization_fields/validate.js rename to src/api/support/organization_fields/validate.js diff --git a/src/v2/support/organization_memberships/index.js b/src/api/support/organization_memberships/index.js similarity index 100% rename from src/v2/support/organization_memberships/index.js rename to src/api/support/organization_memberships/index.js diff --git a/src/v2/support/organization_memberships/validate.js b/src/api/support/organization_memberships/validate.js similarity index 100% rename from src/v2/support/organization_memberships/validate.js rename to src/api/support/organization_memberships/validate.js diff --git a/src/v2/support/organization_subscriptions/index.js b/src/api/support/organization_subscriptions/index.js similarity index 100% rename from src/v2/support/organization_subscriptions/index.js rename to src/api/support/organization_subscriptions/index.js diff --git a/src/v2/support/organization_subscriptions/validate.js b/src/api/support/organization_subscriptions/validate.js similarity index 100% rename from src/v2/support/organization_subscriptions/validate.js rename to src/api/support/organization_subscriptions/validate.js diff --git a/src/v2/support/organizations/index.js b/src/api/support/organizations/index.js similarity index 100% rename from src/v2/support/organizations/index.js rename to src/api/support/organizations/index.js diff --git a/src/v2/support/organizations/validate.js b/src/api/support/organizations/validate.js similarity index 100% rename from src/v2/support/organizations/validate.js rename to src/api/support/organizations/validate.js diff --git a/src/v2/support/search/index.js b/src/api/support/search/index.js similarity index 100% rename from src/v2/support/search/index.js rename to src/api/support/search/index.js diff --git a/src/v2/support/search/validate.js b/src/api/support/search/validate.js similarity index 100% rename from src/v2/support/search/validate.js rename to src/api/support/search/validate.js diff --git a/src/v2/support/suspended_tickets/index.js b/src/api/support/suspended_tickets/index.js similarity index 100% rename from src/v2/support/suspended_tickets/index.js rename to src/api/support/suspended_tickets/index.js diff --git a/src/v2/support/suspended_tickets/validate.js b/src/api/support/suspended_tickets/validate.js similarity index 100% rename from src/v2/support/suspended_tickets/validate.js rename to src/api/support/suspended_tickets/validate.js diff --git a/src/v2/support/tags/index.js b/src/api/support/tags/index.js similarity index 100% rename from src/v2/support/tags/index.js rename to src/api/support/tags/index.js diff --git a/src/v2/support/tags/validate.js b/src/api/support/tags/validate.js similarity index 100% rename from src/v2/support/tags/validate.js rename to src/api/support/tags/validate.js diff --git a/src/v2/support/ticket_activities/index.js b/src/api/support/ticket_activities/index.js similarity index 100% rename from src/v2/support/ticket_activities/index.js rename to src/api/support/ticket_activities/index.js diff --git a/src/v2/support/ticket_activities/validate.js b/src/api/support/ticket_activities/validate.js similarity index 100% rename from src/v2/support/ticket_activities/validate.js rename to src/api/support/ticket_activities/validate.js diff --git a/src/v2/support/ticket_comments/index.js b/src/api/support/ticket_comments/index.js similarity index 100% rename from src/v2/support/ticket_comments/index.js rename to src/api/support/ticket_comments/index.js diff --git a/src/v2/support/ticket_comments/validate.js b/src/api/support/ticket_comments/validate.js similarity index 100% rename from src/v2/support/ticket_comments/validate.js rename to src/api/support/ticket_comments/validate.js diff --git a/src/v2/support/ticket_fields/index.js b/src/api/support/ticket_fields/index.js similarity index 100% rename from src/v2/support/ticket_fields/index.js rename to src/api/support/ticket_fields/index.js diff --git a/src/v2/support/ticket_fields/validate.js b/src/api/support/ticket_fields/validate.js similarity index 100% rename from src/v2/support/ticket_fields/validate.js rename to src/api/support/ticket_fields/validate.js diff --git a/src/v2/support/ticket_forms/index.js b/src/api/support/ticket_forms/index.js similarity index 100% rename from src/v2/support/ticket_forms/index.js rename to src/api/support/ticket_forms/index.js diff --git a/src/v2/support/ticket_forms/validate.js b/src/api/support/ticket_forms/validate.js similarity index 100% rename from src/v2/support/ticket_forms/validate.js rename to src/api/support/ticket_forms/validate.js diff --git a/src/v2/support/ticket_import/index.js b/src/api/support/ticket_import/index.js similarity index 100% rename from src/v2/support/ticket_import/index.js rename to src/api/support/ticket_import/index.js diff --git a/src/v2/support/ticket_import/validate.js b/src/api/support/ticket_import/validate.js similarity index 100% rename from src/v2/support/ticket_import/validate.js rename to src/api/support/ticket_import/validate.js diff --git a/src/v2/support/ticket_metrics/index.js b/src/api/support/ticket_metrics/index.js similarity index 100% rename from src/v2/support/ticket_metrics/index.js rename to src/api/support/ticket_metrics/index.js diff --git a/src/v2/support/ticket_metrics/validate.js b/src/api/support/ticket_metrics/validate.js similarity index 100% rename from src/v2/support/ticket_metrics/validate.js rename to src/api/support/ticket_metrics/validate.js diff --git a/src/v2/support/tickets/index.js b/src/api/support/tickets/index.js similarity index 100% rename from src/v2/support/tickets/index.js rename to src/api/support/tickets/index.js diff --git a/src/v2/support/tickets/validate.js b/src/api/support/tickets/validate.js similarity index 100% rename from src/v2/support/tickets/validate.js rename to src/api/support/tickets/validate.js diff --git a/src/v2/support/user_fields/index.js b/src/api/support/user_fields/index.js similarity index 100% rename from src/v2/support/user_fields/index.js rename to src/api/support/user_fields/index.js diff --git a/src/v2/support/user_fields/validate.js b/src/api/support/user_fields/validate.js similarity index 100% rename from src/v2/support/user_fields/validate.js rename to src/api/support/user_fields/validate.js diff --git a/src/v2/support/user_identities/index.js b/src/api/support/user_identities/index.js similarity index 100% rename from src/v2/support/user_identities/index.js rename to src/api/support/user_identities/index.js diff --git a/src/v2/support/user_identities/validate.js b/src/api/support/user_identities/validate.js similarity index 100% rename from src/v2/support/user_identities/validate.js rename to src/api/support/user_identities/validate.js diff --git a/src/v2/support/user_passwords/index.js b/src/api/support/user_passwords/index.js similarity index 100% rename from src/v2/support/user_passwords/index.js rename to src/api/support/user_passwords/index.js diff --git a/src/v2/support/user_passwords/validate.js b/src/api/support/user_passwords/validate.js similarity index 100% rename from src/v2/support/user_passwords/validate.js rename to src/api/support/user_passwords/validate.js diff --git a/src/v2/support/users/index.js b/src/api/support/users/index.js similarity index 100% rename from src/v2/support/users/index.js rename to src/api/support/users/index.js diff --git a/src/v2/support/users/validate.js b/src/api/support/users/validate.js similarity index 100% rename from src/v2/support/users/validate.js rename to src/api/support/users/validate.js diff --git a/src/v2/support/views/index.js b/src/api/support/views/index.js similarity index 100% rename from src/v2/support/views/index.js rename to src/api/support/views/index.js diff --git a/src/v2/support/views/validate.js b/src/api/support/views/validate.js similarity index 100% rename from src/v2/support/views/validate.js rename to src/api/support/views/validate.js diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..784f3aa --- /dev/null +++ b/src/index.js @@ -0,0 +1,24 @@ +const fs = require('fs'); +const path = require('path'); +const { validate } = require('./utils/options'); +const load = require('./utils/load'); + +// Read folders to list APIs ('/src/api/*') +const APIs = fs.readdirSync(path.resolve(__dirname, 'api')); + +// Load each API (support, sunshine, ...) +const zdAPIs = {}; +APIs.forEach(api => (zdAPIs[api] = load(api))); + +// Initialize each API +const init = (options = {}) => { + const { error } = validate(options); + if (error) throw new Error(error.details[0].message); + + const initialized = {}; + zdAPIs.forEach(api => (initialized[api] = zdAPIs[api].init(options))); + + return initialized; +}; + +module.exports = { init, ...zdAPIs }; diff --git a/src/utils/headers/generate.js b/src/utils/headers/generate.js new file mode 100644 index 0000000..c2e3cbe --- /dev/null +++ b/src/utils/headers/generate.js @@ -0,0 +1,30 @@ +const Joi = require('@hapi/joi'); +const base64 = require('js-base64').Base64; + +const _instance = Joi.string(); +const _email = Joi.string().email(); +const _password = Joi.string().min(1); +const _token = Joi.string().min(1); + +module.exports = (options = {}) => { + const { error } = Joi.object({ + instance: _instance, + email: _email.required(), + password: _password, + token: _token + }) + .xor('password', 'token') + .validate(options); + if (error) throw new Error(error.details[0].message); + + // Allow for either 'password' or 'token' for authentication + const { email, password, token } = options; + const auth = token ? `${email}/token:${token}` : `${email}:${password}`; + const encoded = base64.encode(auth); + + // default to 'application/json', override when needed + return { + 'Content-Type': 'application/json', + Authorization: `Basic ${encoded}` + }; +}; diff --git a/src/utils/headers/index.js b/src/utils/headers/index.js new file mode 100644 index 0000000..64ea721 --- /dev/null +++ b/src/utils/headers/index.js @@ -0,0 +1,11 @@ +const fs = require('fs'); +const path = require('path'); + +const actions = {}; +const files = fs + .readdirSync(__dirname) + .filter(i => !['index.js'].includes(i)) + .map(i => i.slice(0, -3)); +files.forEach(file => (actions[file] = require(path.resolve(__dirname, file)))); + +module.exports = actions; diff --git a/src/utils/load.js b/src/utils/load.js new file mode 100644 index 0000000..372e000 --- /dev/null +++ b/src/utils/load.js @@ -0,0 +1,31 @@ +const fs = require('fs'); +const path = require('path'); +const { validate } = require('./options'); + +module.exports = folder => { + // Read folder to list endpoints of API ('/src/api/{folder}/*') + const endpoints = fs + .readdirSync(path.resolve(__dirname, '../api', folder)) + .map(i => i.slice(0, -3)); + + // Load each endpoint file + const api = {}; + endpoints.forEach(endpoint => { + api[endpoint] = require(path.resolve('../', folder, endpoint)); + }); + + // Initialize each endpoint + const init = (options = {}) => { + const { error } = validate(options); + if (error) throw new Error(error.details[0].message); + + const initialized = {}; + endpoints.forEach(endpoint => { + initialized[endpoint] = api[endpoint](options); + }); + + return initialized; + }; + + return { init, ...api }; +}; diff --git a/src/utils/options/index.js b/src/utils/options/index.js new file mode 100644 index 0000000..25ce668 --- /dev/null +++ b/src/utils/options/index.js @@ -0,0 +1,12 @@ +const fs = require('fs'); +const path = require('path'); + +const actions = {}; +const files = fs + .readdirSync(__dirname) + .filter(i => !['index.js'].includes(i)) + .map(i => i.slice(0, -3)); + +files.forEach(file => (actions[file] = require(path.resolve(__dirname, file)))); + +module.exports = actions; diff --git a/src/utils/options/prepare.js b/src/utils/options/prepare.js new file mode 100644 index 0000000..931fb85 --- /dev/null +++ b/src/utils/options/prepare.js @@ -0,0 +1,13 @@ +const validate = require('./validate'); +const generate = require('../headers/generate'); + +module.exports = (options = {}) => { + const { error } = validate(options); + if (error) throw new Error(error.details[0].message); + + const { instance, email, password, token } = options; + const url = `https://${instance}.zendesk.com`; + const headers = generate({ email, password, token }); + + return { url, headers }; +}; diff --git a/src/utils/options/validate.js b/src/utils/options/validate.js new file mode 100644 index 0000000..2c92906 --- /dev/null +++ b/src/utils/options/validate.js @@ -0,0 +1,16 @@ +const Joi = require('@hapi/joi'); + +const instance = Joi.string().min(1); +const email = Joi.string().email(); +const password = Joi.string().min(1); +const token = Joi.string().min(1); + +module.exports = options => + Joi.object({ + instance: instance.required(), + email: email.required(), + password, + token + }) + .xor('password', 'token') + .validate(options); diff --git a/src/v2/index.js b/src/v2/index.js deleted file mode 100644 index c7b28df..0000000 --- a/src/v2/index.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = ({ instance, headers }) => ({ - sunshine: require('./sunshine')({ instance, headers }), - support: require('./support')({ instance, headers }) -}); diff --git a/src/v2/sunshine/index.js b/src/v2/sunshine/index.js deleted file mode 100644 index 63879e8..0000000 --- a/src/v2/sunshine/index.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = ({ instance, headers }) => ({ - object_types: require('./object_types')({ instance, headers }) -}); diff --git a/src/v2/support/index.js b/src/v2/support/index.js deleted file mode 100644 index ade6e21..0000000 --- a/src/v2/support/index.js +++ /dev/null @@ -1,31 +0,0 @@ -module.exports = ({ instance, headers }) => ({ - custom_agent_roles: require('./custom_agent_roles')({ instance, headers }), - end_users: require('./end_users')({ instance, headers }), - group_memberships: require('./group_memberships')({ instance, headers }), - groups: require('./groups')({ instance, headers }), - organizations: require('./organizations')({ instance, headers }), - organization_fields: require('./organization_fields')({ instance, headers }), - organization_memberships: require('./organization_memberships')({ - instance, - headers - }), - organization_subscriptions: require('./organization_subscriptions')({ - instance, - headers - }), - search: require('./search')({ instance, headers }), - suspended_tickets: require('./suspended_tickets')({ instance, headers }), - tags: require('./tags')({ instance, headers }), - ticket_activities: require('./ticket_activities')({ instance, headers }), - ticket_comments: require('./ticket_comments')({ instance, headers }), - ticket_fields: require('./ticket_fields')({ instance, headers }), - ticket_forms: require('./ticket_forms')({ instance, headers }), - ticket_import: require('./ticket_import')({ instance, headers }), - ticket_metrics: require('./ticket_metrics')({ instance, headers }), - tickets: require('./tickets')({ instance, headers }), - user_fields: require('./user_fields')({ instance, headers }), - user_identities: require('./user_identities')({ instance, headers }), - user_passwords: require('./user_passwords')({ instance, headers }), - users: require('./users')({ instance, headers }), - views: require('./views')({ instance, headers }) -}); diff --git a/tests/api/sunshine/object_types.test.js b/tests/api/sunshine/object_types.test.js new file mode 100644 index 0000000..a08597d --- /dev/null +++ b/tests/api/sunshine/object_types.test.js @@ -0,0 +1,118 @@ +const endpoint = require('../../../src/api/sunshine/object_types'); +const { prepare } = require('../../../src/utils/options'); + +describe('object types', () => { + let object_types, options, url, headers; + + beforeEach(() => { + options = { + instance: 'instance', + email: 'user@email.com', + token: 'token' + }; + object_types = endpoint(options); + ({ url, headers } = prepare(options)); + }); + + afterEach(() => { + options = null; + object_types = 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 object types', () => { + it('should process without input', () => { + expect(object_types.list()).toEqual({ + method: 'GET', + url: `${url}/api/sunshine/objects/types`, + headers + }); + }); + }); + + describe('show object type', () => { + it('should process valid input', () => { + expect(object_types.show({ key: 'valid' })).toEqual({ + method: 'GET', + url: `${url}/api/sunshine/objects/types/valid`, + headers + }); + }); + + it('should fail with invalid input', () => { + expect(() => object_types.show()).toThrowError(); + expect(() => object_types.show({})).toThrowError(); + expect(() => object_types.show('invalid')).toThrowError(); + expect(() => object_types.show({ key: 123 })).toThrowError(); + }); + }); + + describe('create object type', () => { + it('should process valid input', () => { + const data = {}; + expect(object_types.create({ data })).toEqual({ + method: 'POST', + url: `${url}/api/sunshine/objects/types`, + headers, + data + }); + }); + + it('should fail with invalid input', () => { + expect(() => object_types.create()).toThrowError(); + expect(() => object_types.create({})).toThrowError(); + expect(() => object_types.create({ data: 'invalid' })).toThrowError(); + expect(() => object_types.create({ data: 123 })).toThrowError(); + }); + }); + + describe('update object type', () => { + it('should process valid input', () => { + expect(object_types.update({ key: 'valid', data: {} })).toEqual({ + method: 'PUT', + url: `${url}/api/sunshine/objects/types/valid`, + headers, + data: {} + }); + }); + + it('should fail with invalid input', () => { + expect(() => object_types.update()).toThrowError(); + expect(() => object_types.update({})).toThrowError(); + expect(() => object_types.update({ key: 123 })).toThrowError(); + expect(() => object_types.update({ key: 'valid' })).toThrowError(); + expect(() => + object_types.update({ key: 'valid', data: 'invalid' }) + ).toThrowError(); + }); + }); + + describe('delete object type', () => { + it('should process valid input', () => { + expect(object_types.delete({ key: 'valid' })).toEqual({ + method: 'DELETE', + url: `${url}/api/sunshine/objects/types/valid`, + headers + }); + }); + + it('should fail with invalid input', () => { + expect(() => object_types.delete()).toThrowError(); + expect(() => object_types.delete({})).toThrowError(); + expect(() => object_types.delete({ key: 123 })).toThrowError(); + }); + }); +}); diff --git a/tests/package.test.js b/tests/package.test.js deleted file mode 100644 index ee01b94..0000000 --- a/tests/package.test.js +++ /dev/null @@ -1,20 +0,0 @@ -const pkg = require('..'); - -describe('package', () => { - let instance, headers; - - beforeEach(() => { - instance = 'test'; - headers = {}; - }); - - afterEach(() => { - instance = ''; - headers = null; - }); - - test('zaf v2', () => { - expect(typeof pkg.v2).toBe('function'); - expect(typeof pkg.v2({ instance, headers })).toBe('object'); - }); -}); diff --git a/tests/src/v2.test.js b/tests/src/v2.test.js deleted file mode 100644 index 213c961..0000000 --- a/tests/src/v2.test.js +++ /dev/null @@ -1,13 +0,0 @@ -const v2 = require('../../src/v2'); - -const instance = ''; -const headers = {}; - -describe('zaf v2', () => { - let zaf; - - beforeEach(() => (zaf = v2({ instance, headers }))); - afterEach(() => (zaf = null)); - - test('support api', () => expect(zaf.support).toBeDefined()); -}); diff --git a/tests/src/v2/sunshine/object_types.test.js b/tests/src/v2/sunshine/object_types.test.js deleted file mode 100644 index db03737..0000000 --- a/tests/src/v2/sunshine/object_types.test.js +++ /dev/null @@ -1,107 +0,0 @@ -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(); - }); - }); -}); diff --git a/tests/src/v2/support.test.js b/tests/src/v2/support.test.js deleted file mode 100644 index 70ff5b2..0000000 --- a/tests/src/v2/support.test.js +++ /dev/null @@ -1,39 +0,0 @@ -const endpoint = require('../../../src/v2/support'); - -const instance = 'instance'; -const headers = {}; - -const check = (type, compare = 'object') => expect(typeof type).toBe(compare); - -describe('support api', () => { - let support; - - beforeEach(() => (support = endpoint({ instance, headers }))); - afterEach(() => (support = null)); - - test('custom_agent_roles', () => check(support.custom_agent_roles)); - test('end_users', () => check(support.end_users)); - test('group_memberships', () => check(support.group_memberships)); - test('groups', () => check(support.groups)); - test('organizations', () => check(support.organizations)); - test('organization_fields', () => check(support.organization_fields)); - test('organization_subscriptions', () => - check(support.organization_subscriptions)); - test('organization_memberships', () => - check(support.organization_memberships)); - test('search', () => check(support.search, 'function')); - test('suspended_tickets', () => check(support.suspended_tickets)); - test('tags', () => check(support.tags)); - test('ticket_activities', () => check(support.ticket_activities)); - test('ticket_comments', () => check(support.ticket_comments)); - test('ticket_fields', () => check(support.ticket_fields)); - test('ticket_forms', () => check(support.ticket_forms)); - test('ticket_import', () => check(support.ticket_import)); - test('ticket_metrics', () => check(support.ticket_metrics)); - test('tickets', () => check(support.tickets)); - test('user_fields', () => check(support.user_fields)); - test('user_identities', () => check(support.user_identities)); - test('user_passwords', () => check(support.user_passwords)); - test('users', () => check(support.users)); - test('views', () => check(support.views)); -}); diff --git a/tests/src/v2/support/custom_agent_roles.test.js b/tests/src/v2/support/custom_agent_roles.test.js deleted file mode 100644 index a934760..0000000 --- a/tests/src/v2/support/custom_agent_roles.test.js +++ /dev/null @@ -1,103 +0,0 @@ -const endpoint = require('../../../../src/v2/support/custom_agent_roles'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('custom agent roles', () => { - let customAgentRoles; - - beforeEach(() => (customAgentRoles = endpoint({ instance, headers }))); - afterEach(() => (customAgentRoles = null)); - - describe('list custom roles', () => { - it('should process w/ valid input', () => { - expect(customAgentRoles.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/custom_roles.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => customAgentRoles.list('invalid')).toThrowError(); - }); - }); - - describe('show custom role', () => { - it('should process w/ valid input', () => { - expect(customAgentRoles.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/custom_roles/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => customAgentRoles.show()).toThrowError(); - expect(() => customAgentRoles.show({})).toThrowError(); - expect(() => customAgentRoles.show('invalid')).toThrowError(); - expect(() => customAgentRoles.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('create custom role', () => { - it('should process w/ valid input', () => { - expect(customAgentRoles.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/custom_roles.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => customAgentRoles.create()).toThrowError(); - expect(() => customAgentRoles.create({})).toThrowError(); - expect(() => customAgentRoles.create('invalid')).toThrowError(); - expect(() => customAgentRoles.create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('update custom role', () => { - it('should process w/ valid input', () => { - expect(customAgentRoles.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/custom_roles/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => customAgentRoles.update()).toThrowError(); - expect(() => customAgentRoles.update({})).toThrowError(); - expect(() => customAgentRoles.update('invalid')).toThrowError(); - expect(() => customAgentRoles.update({ id: 0 })).toThrowError(); - expect(() => customAgentRoles.update({ id: 'invalid' })).toThrowError(); - expect(() => - customAgentRoles.update({ id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('delete custom role', () => { - it('should process w/ valid input', () => { - expect(customAgentRoles.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/custom_roles/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => customAgentRoles.delete()).toThrowError(); - expect(() => customAgentRoles.delete({})).toThrowError(); - expect(() => customAgentRoles.delete('invalid')).toThrowError(); - expect(() => customAgentRoles.delete({ id: 'invalid' })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/end_users.test.js b/tests/src/v2/support/end_users.test.js deleted file mode 100644 index 95ff1e0..0000000 --- a/tests/src/v2/support/end_users.test.js +++ /dev/null @@ -1,53 +0,0 @@ -const endpoint = require('../../../../src/v2/support/end_users'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('end users', () => { - let end_users; - - beforeEach(() => (end_users = endpoint({ instance, headers }))); - afterEach(() => (end_users = null)); - - describe('show user', () => { - it('should process w/ valid input', () => { - expect(end_users.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/end_users/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => end_users.show()).toThrowError(); - expect(() => end_users.show('invalid')).toThrowError(); - expect(() => end_users.show({})).toThrowError(); - expect(() => end_users.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('update user', () => { - it('should process w/ valid input', () => { - expect(end_users.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/end_users/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => end_users.update()).toThrowError(); - expect(() => end_users.update('invalid')).toThrowError(); - expect(() => end_users.update({})).toThrowError(); - expect(() => end_users.update({ id: 'invalid' })).toThrowError(); - expect(() => - end_users.update({ id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/group_memberships.test.js b/tests/src/v2/support/group_memberships.test.js deleted file mode 100644 index c9b5fdd..0000000 --- a/tests/src/v2/support/group_memberships.test.js +++ /dev/null @@ -1,208 +0,0 @@ -const endpoint = require('../../../../src/v2/support/group_memberships'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('group memberships', () => { - let groupMemberships; - - beforeEach(() => (groupMemberships = endpoint({ instance, headers }))); - afterEach(() => (groupMemberships = null)); - - describe('list memberships', () => { - it('should process w/ valid input', () => { - expect(groupMemberships.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/group_memberships.json`, - headers - }); - - expect(groupMemberships.list({ user_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/group_memberships.json`, - headers - }); - - expect(groupMemberships.list({ group_id: 456 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/groups/456/memberships.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groupMemberships.list('invalid')).toThrowError(); - expect(() => - groupMemberships.list({ user_id: 'invalid' }) - ).toThrowError(); - expect(() => - groupMemberships.list({ group_id: 'invalid' }) - ).toThrowError(); - expect(() => - groupMemberships.list({ user_id: 123, group_id: 456 }) - ).toThrowError(); - }); - }); - - describe('list assignable memberships', () => { - it('should process w/ valid input', () => { - expect(groupMemberships.assignable()).toEqual({ - method: 'GET', - url: `${url}/api/v2/group_memberships/assignable.json`, - headers - }); - - expect(groupMemberships.assignable({ group_id: 456 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/groups/456/memberships/assignable.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groupMemberships.assignable('invalid')).toThrowError(); - expect(() => - groupMemberships.assignable({ group_id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('show membership', () => { - it('should process w/ valid input', () => { - expect(groupMemberships.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/group_memberships/123.json`, - headers - }); - - expect(groupMemberships.show({ id: 123, user_id: 456 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/456/group_memberships/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groupMemberships.show()).toThrowError(); - expect(() => groupMemberships.show('invalid')).toThrowError(); - expect(() => groupMemberships.show({})).toThrowError(); - expect(() => - groupMemberships.show({ user_id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('create membership', () => { - it('should process w/ valid input', () => { - expect(groupMemberships.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/group_memberships.json`, - headers, - data: {} - }); - - expect(groupMemberships.create({ user_id: 123, data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/123/group_memberships.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groupMemberships.create()).toThrowError(); - expect(() => groupMemberships.create('invalid')).toThrowError(); - expect(() => groupMemberships.create({})).toThrowError(); - expect(() => groupMemberships.create({ data: 'invalid' })).toThrowError(); - expect(() => - groupMemberships.create({ user_id: 'invalid', data: {} }) - ).toThrowError(); - }); - }); - - describe('bulk create memberships', () => { - it('should process w/ valid input', () => { - expect(groupMemberships.create_many({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/group_memberships/create_many.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groupMemberships.create_many()).toThrowError(); - expect(() => groupMemberships.create_many('invalid')).toThrowError(); - expect(() => groupMemberships.create_many({})).toThrowError(); - expect(() => - groupMemberships.create_many({ data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('delete membership', () => { - it('should process w/ valid input', () => { - expect(groupMemberships.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/group_memberships/123.json`, - headers - }); - - expect(groupMemberships.delete({ id: 123, user_id: 456 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/users/456/group_memberships/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groupMemberships.delete()).toThrowError(); - expect(() => groupMemberships.delete('invalid')).toThrowError(); - expect(() => groupMemberships.delete({})).toThrowError(); - expect(() => groupMemberships.delete({ id: 'invalid' })).toThrowError(); - expect(() => - groupMemberships.delete({ id: 123, user_id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('bulk delete memberships', () => { - it('should process w/ valid input', () => { - expect(groupMemberships.delete_many({ ids: '1,2,3' })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/group_memberships/destroy_many.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groupMemberships.delete_many()).toThrowError(); - expect(() => groupMemberships.delete_many('invalid')).toThrowError(); - expect(() => groupMemberships.delete_many({})).toThrowError(); - expect(() => groupMemberships.delete_many({ ids: 0 })).toThrowError(); - }); - }); - - describe('set membership as default', () => { - it('should process w/ valid input', () => { - expect( - groupMemberships.default({ user_id: 123, membership_id: 456 }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/group_memberships/456/make_default.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groupMemberships.default()).toThrowError(); - expect(() => groupMemberships.default('invalid')).toThrowError(); - expect(() => groupMemberships.default({})).toThrowError(); - expect(() => groupMemberships.default({ ids: 0 })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/groups.test.js b/tests/src/v2/support/groups.test.js deleted file mode 100644 index 77695be..0000000 --- a/tests/src/v2/support/groups.test.js +++ /dev/null @@ -1,128 +0,0 @@ -const endpoint = require('../../../../src/v2/support/groups'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('groups', () => { - let groups; - - beforeEach(() => (groups = endpoint({ instance, headers }))); - afterEach(() => (groups = null)); - - describe('list groups', () => { - it('should process w/ valid input', () => { - expect(groups.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/groups.json`, - headers - }); - - expect(groups.list({})).toEqual({ - method: 'GET', - url: `${url}/api/v2/groups.json`, - headers - }); - - expect(groups.list({ user_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/groups.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groups.list('invalid')).toThrowError(); - expect(() => groups.list({ invalid: 123 })).toThrowError(); - expect(() => groups.list({ user_id: 'invalid' })).toThrowError(); - }); - }); - - describe('show assignable groups', () => { - it('should process w/ valid input', () => { - expect(groups.show_assignable()).toEqual({ - method: 'GET', - url: `${url}/api/v2/groups/assignable.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groups.show_assignable('invalid')).toThrowError(); - }); - }); - - describe('show group', () => { - it('should process w/ valid input', () => { - expect(groups.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/groups/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groups.show()).toThrowError(); - expect(() => groups.show({})).toThrowError(); - expect(() => groups.show('invalid')).toThrowError(); - expect(() => groups.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('create group', () => { - it('should process w/ valid input', () => { - expect(groups.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/groups.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groups.create()).toThrowError(); - expect(() => groups.create({})).toThrowError(); - expect(() => groups.create('invalid')).toThrowError(); - expect(() => groups.create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('update group', () => { - it('should process w/ valid input', () => { - expect(groups.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/groups/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groups.update()).toThrowError(); - expect(() => groups.update('invalid')).toThrowError(); - expect(() => groups.update({})).toThrowError(); - expect(() => groups.update({ id: 'invalid' })).toThrowError(); - expect(() => groups.update({ id: 123, data: 'invalid' })).toThrowError(); - }); - }); - - describe('delete group', () => { - it('should process w/ valid input', () => { - expect(groups.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/groups/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => groups.delete()).toThrowError(); - expect(() => groups.delete({})).toThrowError(); - expect(() => groups.delete('invalid')).toThrowError(); - expect(() => groups.delete({ id: 'invalid' })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/organization_fields.test.js b/tests/src/v2/support/organization_fields.test.js deleted file mode 100644 index 4abf2d0..0000000 --- a/tests/src/v2/support/organization_fields.test.js +++ /dev/null @@ -1,127 +0,0 @@ -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(); - }); - }); -}); diff --git a/tests/src/v2/support/organization_memberships.test.js b/tests/src/v2/support/organization_memberships.test.js deleted file mode 100644 index 34f6af2..0000000 --- a/tests/src/v2/support/organization_memberships.test.js +++ /dev/null @@ -1,199 +0,0 @@ -const endpoint = require("../../../../src/v2/support/organization_memberships"); - -const instance = "instance"; -const url = `https://${instance}.zendesk.com`; -const headers = { - "Content-Type": "application/json", - Authorization: "Basic <64bit_encoded_credentials>" -}; - -describe("organization memberships", () => { - let organizationMemberships; - - beforeEach(() => (organizationMemberships = endpoint({ instance, headers }))); - afterEach(() => (organizationMemberships = null)); - - describe("list memberships", () => { - it("should process w/ valid input", () => { - expect(organizationMemberships.list()).toEqual({ - method: "GET", - url: `${url}/api/v2/organization_memberships.json`, - headers - }); - - expect(organizationMemberships.list({ user_id: 123 })).toEqual({ - method: "GET", - url: `${url}/api/v2/users/123/organization_memberships.json`, - headers - }); - - expect(organizationMemberships.list({ organization_id: 456 })).toEqual({ - method: "GET", - url: `${url}/api/v2/organizations/456/organization_memberships.json`, - headers - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationMemberships.list("invalid")).toThrowError(); - expect(() => - organizationMemberships.list({ user_id: "invalid" }) - ).toThrowError(); - expect(() => - organizationMemberships.list({ organization_id: "invalid" }) - ).toThrowError(); - expect(() => - organizationMemberships.list({ user_id: 123, organization_id: 456 }) - ).toThrowError(); - }); - }); - - describe("show membership", () => { - it("should process w/ valid input", () => { - expect(organizationMemberships.show({ id: 123 })).toEqual({ - method: "GET", - url: `${url}/api/v2/organization_memberships/123.json`, - headers - }); - - expect(organizationMemberships.show({ id: 123, user_id: 456 })).toEqual({ - method: "GET", - url: `${url}/api/v2/users/456/organization_memberships/123.json`, - headers - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationMemberships.show()).toThrowError(); - expect(() => organizationMemberships.show("invalid")).toThrowError(); - expect(() => organizationMemberships.show({})).toThrowError(); - expect(() => - organizationMemberships.show({ user_id: "invalid" }) - ).toThrowError(); - }); - }); - - describe("create membership", () => { - it("should process w/ valid input", () => { - expect(organizationMemberships.create({ data: {} })).toEqual({ - method: "POST", - url: `${url}/api/v2/organization_memberships.json`, - headers, - data: {} - }); - - expect( - organizationMemberships.create({ user_id: 123, data: {} }) - ).toEqual({ - method: "POST", - url: `${url}/api/v2/users/123/organization_memberships.json`, - headers, - data: {} - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationMemberships.create()).toThrowError(); - expect(() => organizationMemberships.create("invalid")).toThrowError(); - expect(() => organizationMemberships.create({})).toThrowError(); - expect(() => - organizationMemberships.create({ data: "invalid" }) - ).toThrowError(); - expect(() => - organizationMemberships.create({ user_id: "invalid", data: {} }) - ).toThrowError(); - }); - }); - - describe("bulk create memberships", () => { - it("should process w/ valid input", () => { - expect(organizationMemberships.create_many({ data: {} })).toEqual({ - method: "POST", - url: `${url}/api/v2/organization_memberships/create_many.json`, - headers, - data: {} - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationMemberships.create_many()).toThrowError(); - expect(() => - organizationMemberships.create_many("invalid") - ).toThrowError(); - expect(() => organizationMemberships.create_many({})).toThrowError(); - expect(() => - organizationMemberships.create_many({ data: "invalid" }) - ).toThrowError(); - }); - }); - - describe("delete membership", () => { - it("should process w/ valid input", () => { - expect(organizationMemberships.delete({ id: 123 })).toEqual({ - method: "DELETE", - url: `${url}/api/v2/organization_memberships/123.json`, - headers - }); - - expect(organizationMemberships.delete({ id: 123, user_id: 456 })).toEqual( - { - method: "DELETE", - url: `${url}/api/v2/users/456/organization_memberships/123.json`, - headers - } - ); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationMemberships.delete()).toThrowError(); - expect(() => organizationMemberships.delete("invalid")).toThrowError(); - expect(() => organizationMemberships.delete({})).toThrowError(); - expect(() => - organizationMemberships.delete({ id: "invalid" }) - ).toThrowError(); - expect(() => - organizationMemberships.delete({ id: 123, user_id: "invalid" }) - ).toThrowError(); - }); - }); - - describe("bulk delete memberships", () => { - it("should process w/ valid input", () => { - expect(organizationMemberships.delete_many({ ids: "1,2,3" })).toEqual({ - method: "DELETE", - url: `${url}/api/v2/organization_memberships/destroy_many.json?ids=1,2,3`, - headers - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationMemberships.delete_many()).toThrowError(); - expect(() => - organizationMemberships.delete_many("invalid") - ).toThrowError(); - expect(() => organizationMemberships.delete_many({})).toThrowError(); - expect(() => - organizationMemberships.delete_many({ ids: 0 }) - ).toThrowError(); - }); - }); - - describe("set membership as default", () => { - it("should process w/ valid input", () => { - expect( - organizationMemberships.default({ id: 123, membership_id: 456 }) - ).toEqual({ - method: "PUT", - url: `${url}/api/v2/users/123/organization_memberships/456/make_default.json`, - headers - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationMemberships.default()).toThrowError(); - expect(() => organizationMemberships.default("invalid")).toThrowError(); - expect(() => organizationMemberships.default({})).toThrowError(); - expect(() => organizationMemberships.default({ ids: 0 })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/organization_subscriptions.test.js b/tests/src/v2/support/organization_subscriptions.test.js deleted file mode 100644 index 5218750..0000000 --- a/tests/src/v2/support/organization_subscriptions.test.js +++ /dev/null @@ -1,107 +0,0 @@ -const endpoint = require("../../../../src/v2/support/organization_subscriptions"); - -const instance = "instance"; -const url = `https://${instance}.zendesk.com`; -const headers = { - "Content-Type": "application/json", - Authorization: "Basic <64bit_encoded_credentials>" -}; - -describe("organization subscriptions", () => { - let organizationSubscriptions; - - beforeEach( - () => (organizationSubscriptions = endpoint({ instance, headers })) - ); - afterEach(() => (organizationSubscriptions = null)); - - describe("list subscriptions", () => { - it("should process w/ valid input", () => { - expect(organizationSubscriptions.list()).toEqual({ - method: "GET", - url: `${url}/api/v2/organization_subscriptions.json`, - headers - }); - - expect(organizationSubscriptions.list({ user_id: 123 })).toEqual({ - method: "GET", - url: `${url}/api/v2/users/123/organization_subscriptions.json`, - headers - }); - - expect(organizationSubscriptions.list({ organization_id: 456 })).toEqual({ - method: "GET", - url: `${url}/api/v2/organizations/456/subscriptions.json`, - headers - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationSubscriptions.list("invalid")).toThrowError(); - expect(() => - organizationSubscriptions.list({ user_id: "invalid" }) - ).toThrowError(); - expect(() => - organizationSubscriptions.list({ organization_id: "invalid" }) - ).toThrowError(); - expect(() => - organizationSubscriptions.list({ user_id: 123, organization_id: 456 }) - ).toThrowError(); - }); - }); - - describe("show subscriptions", () => { - it("should process w/ valid input", () => { - expect(organizationSubscriptions.show({ id: 123 })).toEqual({ - method: "GET", - url: `${url}/api/v2/organization_subscriptions/123.json`, - headers - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationSubscriptions.show()).toThrowError(); - expect(() => organizationSubscriptions.show("invalid")).toThrowError(); - expect(() => organizationSubscriptions.show({})).toThrowError(); - }); - }); - - describe("create subscription", () => { - it("should process w/ valid input", () => { - expect(organizationSubscriptions.create({ data: {} })).toEqual({ - method: "POST", - url: `${url}/api/v2/organization_subscriptions.json`, - headers, - data: {} - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationSubscriptions.create()).toThrowError(); - expect(() => organizationSubscriptions.create("invalid")).toThrowError(); - expect(() => organizationSubscriptions.create({})).toThrowError(); - expect(() => - organizationSubscriptions.create({ data: "invalid" }) - ).toThrowError(); - }); - }); - - describe("delete subscription", () => { - it("should process w/ valid input", () => { - expect(organizationSubscriptions.delete({ id: 123 })).toEqual({ - method: "DELETE", - url: `${url}/api/v2/organization_subscriptions/123.json`, - headers - }); - }); - - it("should throw error w/ invalid input", () => { - expect(() => organizationSubscriptions.delete()).toThrowError(); - expect(() => organizationSubscriptions.delete("invalid")).toThrowError(); - expect(() => organizationSubscriptions.delete({})).toThrowError(); - expect(() => - organizationSubscriptions.delete({ id: "invalid" }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/organizations.test.js b/tests/src/v2/support/organizations.test.js deleted file mode 100644 index 6a18edd..0000000 --- a/tests/src/v2/support/organizations.test.js +++ /dev/null @@ -1,306 +0,0 @@ -const endpoint = require('../../../../src/v2/support/organizations'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('organizations', () => { - let organizations; - - beforeEach(() => (organizations = endpoint({ instance, headers }))); - afterEach(() => (organizations = null)); - - describe('list organizations', () => { - it('should process w/ valid input', () => { - expect(organizations.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations.json`, - headers - }); - - expect(organizations.list({ user_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/organizations.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.list('invalid')).toThrowError(); - expect(() => organizations.list({ user_id: 'invalid' })).toThrowError(); - }); - }); - - describe('autocomplete organizations', () => { - it('should process w/ valid input', () => { - expect(organizations.autocomplete({ name: 'name' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/autocomplete.json?name=name`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.autocomplete()).toThrowError(); - expect(() => organizations.autocomplete({})).toThrowError(); - expect(() => organizations.autocomplete('invalid')).toThrowError(); - expect(() => organizations.autocomplete({ name: 0 })).toThrowError(); - expect(() => organizations.autocomplete({ name: '' })).toThrowError(); - }); - }); - - describe("show organizations's related information", () => { - it('should process w/ valid input', () => { - expect(organizations.related({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/123/related.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.related()).toThrowError(); - expect(() => organizations.related({})).toThrowError(); - expect(() => organizations.related('invalid')).toThrowError(); - expect(() => organizations.related({ id: 0 })).toThrowError(); - expect(() => organizations.related({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('show organization', () => { - it('should process w/ valid input', () => { - expect(organizations.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.show()).toThrowError(); - expect(() => organizations.show({})).toThrowError(); - expect(() => organizations.show('invalid')).toThrowError(); - expect(() => organizations.show({ id: 0 })).toThrowError(); - expect(() => organizations.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('show many organizations', () => { - it('should process w/ valid input', () => { - expect(organizations.show_many({ ids: '1,2,3' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/show_many.json?ids=1,2,3`, - headers - }); - - expect(organizations.show_many({ external_ids: '4,5,6' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/show_many.json?external_ids=4,5,6`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.show_many()).toThrowError(); - expect(() => organizations.show_many({})).toThrowError(); - expect(() => organizations.show_many('invalid')).toThrowError(); - expect(() => organizations.show_many({ ids: 0 })).toThrowError(); - expect(() => organizations.show_many({ external_ids: 0 })).toThrowError(); - expect(() => - organizations.show_many({ ids: '1,2,3', external_ids: '4,5,6' }) - ).toThrowError(); - }); - }); - - describe('create organization', () => { - it('should process w/ valid input', () => { - expect(organizations.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/organizations.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.create()).toThrowError(); - expect(() => organizations.create({})).toThrowError(); - expect(() => organizations.create('invalid')).toThrowError(); - expect(() => organizations.create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('create many organizations', () => { - it('should process w/ valid input', () => { - expect(organizations.create_many({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/organizations/create_many.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.create_many()).toThrowError(); - expect(() => organizations.create_many({})).toThrowError(); - expect(() => organizations.create_many('invalid')).toThrowError(); - expect(() => - organizations.create_many({ data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('create or update organization', () => { - it('should process w/ valid input', () => { - expect(organizations.create_or_update({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/organizations/create_or_update.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.create_or_update()).toThrowError(); - expect(() => organizations.create_or_update({})).toThrowError(); - expect(() => organizations.create_or_update('invalid')).toThrowError(); - expect(() => - organizations.create_or_update({ data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('update organization', () => { - it('should process w/ valid input', () => { - expect(organizations.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/organizations/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.update()).toThrowError(); - expect(() => organizations.update({})).toThrowError(); - expect(() => organizations.update('invalid')).toThrowError(); - expect(() => organizations.update({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('update many organizations', () => { - it('should process w/ valid input', () => { - expect(organizations.update_many({ data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/organizations/update_many.json`, - headers, - data: {} - }); - - expect(organizations.update_many({ ids: '1,2,3', data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/organizations/update_many.json?ids=1,2,3`, - headers, - data: {} - }); - - expect( - organizations.update_many({ external_ids: '4,5,6', data: {} }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/organizations/update_many.json?external_ids=4,5,6`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.update_many()).toThrowError(); - expect(() => organizations.update_many({})).toThrowError(); - expect(() => organizations.update_many('invalid')).toThrowError(); - expect(() => - organizations.update_many({ data: 'invalid' }) - ).toThrowError(); - expect(() => - organizations.update_many({ ids: 0, data: {} }) - ).toThrowError(); - expect(() => - organizations.update_many({ external_ids: 0, data: {} }) - ).toThrowError(); - expect(() => - organizations.update_many({ - ids: '1,2,3', - external_ids: '4,5,6', - data: {} - }) - ).toThrowError(); - }); - }); - - describe('delete organization', () => { - it('should process w/ valid input', () => { - expect(organizations.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/organizations/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.delete()).toThrowError(); - expect(() => organizations.delete({})).toThrowError(); - expect(() => organizations.delete('invalid')).toThrowError(); - expect(() => organizations.delete({ id: 0 })).toThrowError(); - expect(() => organizations.delete({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('bulk delete organizations', () => { - it('should process w/ valid input', () => { - expect(organizations.delete_many({ ids: '1,2,3' })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/organizations/destroy_many.json?ids=1,2,3`, - headers - }); - - expect(organizations.delete_many({ external_ids: '4,5,6' })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/organizations/destroy_many.json?external_ids=4,5,6`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.delete_many()).toThrowError(); - expect(() => organizations.delete_many({})).toThrowError(); - expect(() => organizations.delete_many('invalid')).toThrowError(); - expect(() => organizations.delete_many({ ids: 0 })).toThrowError(); - expect(() => - organizations.delete_many({ external_ids: 0 }) - ).toThrowError(); - expect(() => - organizations.delete_many({ ids: '1,2,3', external_ids: '4,5,6' }) - ).toThrowError(); - }); - }); - - describe('search organization by external id', () => { - it('should process w/ valid input', () => { - expect(organizations.search({ external_id: '123' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/search.json?external_id=123`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => organizations.search()).toThrowError(); - expect(() => organizations.search({})).toThrowError(); - expect(() => organizations.search('invalid')).toThrowError(); - expect(() => organizations.search({ external_id: 0 })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/search.test.js b/tests/src/v2/support/search.test.js deleted file mode 100644 index aed35af..0000000 --- a/tests/src/v2/support/search.test.js +++ /dev/null @@ -1,33 +0,0 @@ -const endpoint = require('../../../../src/v2/support/search'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('search', () => { - let search; - - beforeAll(() => (search = endpoint({ instance, headers }))); - afterAll(() => (search = null)); - - describe('list search results', () => { - it('should process w/ valid input', () => { - expect(search({ search_string: 'query' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/search.json?query=query`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => search()).toThrowError(); - expect(() => search({})).toThrowError(); - expect(() => search('invalid')).toThrowError(); - expect(() => search({ search_string: 123 })).toThrowError(); - expect(() => search({ search_string: '' })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/suspended_tickets.test.js b/tests/src/v2/support/suspended_tickets.test.js deleted file mode 100644 index 3a8c87c..0000000 --- a/tests/src/v2/support/suspended_tickets.test.js +++ /dev/null @@ -1,114 +0,0 @@ -const endpoint = require('../../../../src/v2/support/suspended_tickets'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('end users', () => { - let suspended_tickets; - - beforeEach(() => (suspended_tickets = endpoint({ instance, headers }))); - afterEach(() => (suspended_tickets = null)); - - describe('list suspended tickets', () => { - it('should process w/ valid input', () => { - expect(suspended_tickets.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/suspended_tickets.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => suspended_tickets.list('invalid')).toThrowError(); - }); - }); - - describe('show suspended ticket', () => { - it('should process w/ valid input', () => { - expect(suspended_tickets.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/suspended_tickets/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => suspended_tickets.show()).toThrowError(); - expect(() => suspended_tickets.show('invalid')).toThrowError(); - expect(() => suspended_tickets.show({})).toThrowError(); - expect(() => suspended_tickets.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('recover suspended ticket', () => { - it('should process w/ valid input', () => { - expect(suspended_tickets.recover({ id: 123 })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/suspended_tickets/123/recover.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => suspended_tickets.recover()).toThrowError(); - expect(() => suspended_tickets.recover('invalid')).toThrowError(); - expect(() => suspended_tickets.recover({})).toThrowError(); - expect(() => suspended_tickets.recover({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('recover multiple suspended tickets', () => { - it('should process w/ valid input', () => { - expect(suspended_tickets.recover_many({ ids: '1,2,3' })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/suspended_tickets/recover_many.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => suspended_tickets.recover_many()).toThrowError(); - expect(() => suspended_tickets.recover_many('invalid')).toThrowError(); - expect(() => suspended_tickets.recover_many({})).toThrowError(); - expect(() => suspended_tickets.recover_many({ ids: 0 })).toThrowError(); - }); - }); - - describe('delete suspended ticket', () => { - it('should process w/ valid input', () => { - expect(suspended_tickets.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/suspended_tickets/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => suspended_tickets.delete()).toThrowError(); - expect(() => suspended_tickets.delete('invalid')).toThrowError(); - expect(() => suspended_tickets.delete({})).toThrowError(); - expect(() => suspended_tickets.delete({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('delete multiple suspended tickets', () => { - it('should process w/ valid input', () => { - expect(suspended_tickets.delete_many({ ids: '1,2,3' })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/suspended_tickets/destroy_many.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => suspended_tickets.delete_many()).toThrowError(); - expect(() => suspended_tickets.delete_many('invalid')).toThrowError(); - expect(() => suspended_tickets.delete_many({})).toThrowError(); - expect(() => suspended_tickets.delete_many({ ids: 0 })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/tags.test.js b/tests/src/v2/support/tags.test.js deleted file mode 100644 index 678a4d9..0000000 --- a/tests/src/v2/support/tags.test.js +++ /dev/null @@ -1,200 +0,0 @@ -const endpoint = require('../../../../src/v2/support/tags'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('tags', () => { - let tags; - - beforeEach(() => (tags = endpoint({ instance, headers }))); - afterEach(() => (tags = null)); - - describe('list tags', () => { - it('should process w/ valid input', () => { - expect(tags.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/tags.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tags.list('invalid')).toThrowError(); - }); - }); - - describe('show tags', () => { - it('should process w/ valid input', () => { - expect(tags.show({ type: 'tickets', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123/tags.json`, - headers - }); - - expect(tags.show({ type: 'organizations', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/123/tags.json`, - headers - }); - - expect(tags.show({ type: 'users', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/tags.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tags.show()).toThrowError(); - expect(() => tags.show('invalid')).toThrowError(); - expect(() => tags.show({})).toThrowError(); - expect(() => tags.show({ invalid: '' })).toThrowError(); - expect(() => tags.show({ type: '' })).toThrowError(); - expect(() => tags.show({ type: 'tickets' })).toThrowError(); - expect(() => tags.show({ type: 'tickets', id: 0 })).toThrowError(); - expect(() => - tags.show({ type: 'tickets', id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('set tags', () => { - it('should process w/ valid input', () => { - expect(tags.set({ type: 'tickets', id: 123, data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/tickets/123/tags.json`, - headers, - data: {} - }); - - expect(tags.set({ type: 'organizations', id: 123, data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/organizations/123/tags.json`, - headers, - data: {} - }); - - expect(tags.set({ type: 'users', id: 123, data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/123/tags.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tags.set()).toThrowError(); - expect(() => tags.set('invalid')).toThrowError(); - expect(() => tags.set({})).toThrowError(); - expect(() => tags.set({ type: 'invalid' })).toThrowError(); - expect(() => tags.set({ type: 'tickets' })).toThrowError(); - expect(() => tags.set({ type: 'tickets', id: 0 })).toThrowError(); - expect(() => tags.set({ type: 'tickets', id: 123 })).toThrowError(); - expect(() => - tags.set({ type: 'tickets', id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('add tags', () => { - it('should process w/ valid input', () => { - expect(tags.add({ type: 'tickets', id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/tickets/123/tags.json`, - headers, - data: {} - }); - - expect(tags.add({ type: 'organizations', id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/organizations/123/tags.json`, - headers, - data: {} - }); - - expect(tags.add({ type: 'users', id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/tags.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tags.add()).toThrowError(); - expect(() => tags.add('invalid')).toThrowError(); - expect(() => tags.add({})).toThrowError(); - expect(() => tags.add({ type: 'invalid' })).toThrowError(); - expect(() => tags.add({ type: 'tickets', id: 'invalid' })).toThrowError(); - expect(() => tags.add({ type: 'tickets', id: 0 })).toThrowError(); - expect(() => tags.add({ type: 'tickets', id: 123 })).toThrowError(); - expect(() => - tags.add({ type: 'tickets', id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('remove tags', () => { - it('should process w/ valid input', () => { - expect(tags.remove({ type: 'tickets', id: 123, data: {} })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/tickets/123/tags.json`, - headers, - data: {} - }); - - expect(tags.remove({ type: 'organizations', id: 123, data: {} })).toEqual( - { - method: 'DELETE', - url: `${url}/api/v2/organizations/123/tags.json`, - headers, - data: {} - } - ); - - expect(tags.remove({ type: 'users', id: 123, data: {} })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/users/123/tags.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tags.remove()).toThrowError(); - expect(() => tags.remove('invalid')).toThrowError(); - expect(() => tags.remove({})).toThrowError(); - expect(() => tags.remove({ invalid: '' })).toThrowError(); - expect(() => tags.remove({ type: '' })).toThrowError(); - expect(() => tags.remove({ type: 'tickets' })).toThrowError(); - expect(() => tags.remove({ type: 'tickets', id: 0 })).toThrowError(); - expect(() => - tags.remove({ type: 'tickets', id: 'invalid' }) - ).toThrowError(); - expect(() => - tags.remove({ type: 'tickets', id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('autocomplete tags', () => { - it('should process w/ valid input', () => { - expect(tags.autocomplete({ name: 'name' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/autocomplete/tags.json?name=name`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tags.autocomplete()).toThrowError(); - expect(() => tags.autocomplete('invalid')).toThrowError(); - expect(() => tags.autocomplete({})).toThrowError(); - expect(() => tags.autocomplete({ name: 0 })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/ticket_activities.test.js b/tests/src/v2/support/ticket_activities.test.js deleted file mode 100644 index 567eec2..0000000 --- a/tests/src/v2/support/ticket_activities.test.js +++ /dev/null @@ -1,48 +0,0 @@ -const endpoint = require('../../../../src/v2/support/ticket_activities'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('end users', () => { - let ticket_activities; - - beforeEach(() => (ticket_activities = endpoint({ instance, headers }))); - afterEach(() => (ticket_activities = null)); - - describe('list activities', () => { - it('should process w/ valid input', () => { - expect(ticket_activities.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/activities.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticket_activities.list('invalid')).toThrowError(); - }); - }); - - describe('show activity', () => { - it('should process w/ valid input', () => { - expect(ticket_activities.show({ activity_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/activities/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticket_activities.show()).toThrowError(); - expect(() => ticket_activities.show('invalid')).toThrowError(); - expect(() => ticket_activities.show({})).toThrowError(); - expect(() => - ticket_activities.show({ activity_id: 'invalid' }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/ticket_comments.test.js b/tests/src/v2/support/ticket_comments.test.js deleted file mode 100644 index b56b0d7..0000000 --- a/tests/src/v2/support/ticket_comments.test.js +++ /dev/null @@ -1,100 +0,0 @@ -const endpoint = require('../../../../src/v2/support/ticket_comments'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('ticket comments', () => { - let ticketComments; - - beforeEach(() => (ticketComments = endpoint({ instance, headers }))); - afterEach(() => (ticketComments = null)); - - describe('list comments', () => { - it('should process w/ valid input', () => { - expect(ticketComments.list({ ticket_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123/comments.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketComments.list()).toThrowError(); - expect(() => ticketComments.list('invalid')).toThrowError(); - expect(() => - ticketComments.list({ ticket_id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('list email ccs for a comment', () => { - it('should process w/ valid input', () => { - expect(ticketComments.emailCCs({ ticket_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123/comments.json?include=users`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketComments.emailCCs()).toThrowError(); - expect(() => ticketComments.emailCCs('invalid')).toThrowError(); - expect(() => - ticketComments.emailCCs({ ticket_id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('redact string in comment', () => { - it('should process w/ valid input', () => { - expect( - ticketComments.redact({ ticket_id: 123, id: 456, data: {} }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/tickets/123/comments/456/redact.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketComments.redact()).toThrowError(); - expect(() => ticketComments.redact('invalid')).toThrowError(); - expect(() => - ticketComments.redact({ ticket_id: 'invalid' }) - ).toThrowError(); - expect(() => - ticketComments.redact({ ticket_id: 123, id: 'invalid' }) - ).toThrowError(); - expect(() => - ticketComments.redact({ ticket_id: 123, id: 456, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('make comment private', () => { - it('should process w/ valid input', () => { - expect(ticketComments.makePrivate({ ticket_id: 123, id: 456 })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/tickets/123/comments/456/make_private.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketComments.makePrivate()).toThrowError(); - expect(() => ticketComments.makePrivate('invalid')).toThrowError(); - expect(() => - ticketComments.makePrivate({ ticket_id: 'invalid' }) - ).toThrowError(); - expect(() => - ticketComments.makePrivate({ ticket_id: 123, id: 'invalid' }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/ticket_fields.test.js b/tests/src/v2/support/ticket_fields.test.js deleted file mode 100644 index 8a2669e..0000000 --- a/tests/src/v2/support/ticket_fields.test.js +++ /dev/null @@ -1,197 +0,0 @@ -const endpoint = require('../../../../src/v2/support/ticket_fields'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('ticket fields', () => { - let ticketFields; - - beforeEach(() => (ticketFields = endpoint({ instance, headers }))); - afterEach(() => (ticketFields = null)); - - describe('list ticket fields', () => { - it('should process w/ valid input', () => { - expect(ticketFields.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_fields.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.list('invalid')).toThrowError(); - }); - }); - - describe('show ticket field', () => { - it('should process w/ valid input', () => { - expect(ticketFields.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_fields/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.show()).toThrowError(); - expect(() => ticketFields.show('invalid')).toThrowError(); - expect(() => ticketFields.show({})).toThrowError(); - expect(() => ticketFields.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('create ticket field', () => { - it('should process w/ valid input', () => { - expect(ticketFields.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/ticket_fields.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.create()).toThrowError(); - expect(() => ticketFields.create('invalid')).toThrowError(); - expect(() => ticketFields.create({})).toThrowError(); - expect(() => ticketFields.create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('update ticket field', () => { - it('should process w/ valid input', () => { - expect(ticketFields.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/ticket_fields/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.update()).toThrowError(); - expect(() => ticketFields.update('invalid')).toThrowError(); - expect(() => ticketFields.update({})).toThrowError(); - expect(() => ticketFields.update({ id: 'invalid' })).toThrowError(); - expect(() => - ticketFields.update({ id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('delete ticket field', () => { - it('should process w/ valid input', () => { - expect(ticketFields.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/ticket_fields/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.delete()).toThrowError(); - expect(() => ticketFields.delete('invalid')).toThrowError(); - expect(() => ticketFields.delete({})).toThrowError(); - expect(() => ticketFields.delete({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('list ticket field options', () => { - it('should process w/ valid input', () => { - expect(ticketFields.listOptions({ field_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_fields/123/options.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.listOptions()).toThrowError(); - expect(() => ticketFields.listOptions('invalid')).toThrowError(); - expect(() => ticketFields.listOptions({})).toThrowError(); - expect(() => - ticketFields.listOptions({ field_id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('show a ticket field option', () => { - it('should process w/ valid input', () => { - expect(ticketFields.showOption({ field_id: 123, id: 456 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_fields/123/options/456.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.showOption()).toThrowError(); - expect(() => ticketFields.showOption('invalid')).toThrowError(); - expect(() => ticketFields.showOption({})).toThrowError(); - expect(() => - ticketFields.showOption({ field_id: 'invalid' }) - ).toThrowError(); - expect(() => - ticketFields.showOption({ field_id: 123, id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('create or update a ticket field option', () => { - it('should process w/ valid input', () => { - expect( - ticketFields.createOrUpdateOption({ field_id: 123, id: 456, data: {} }) - ).toEqual({ - method: 'POST', - url: `${url}/api/v2/ticket_fields/123/options/456.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.createOrUpdateOption()).toThrowError(); - expect(() => ticketFields.createOrUpdateOption('invalid')).toThrowError(); - expect(() => ticketFields.createOrUpdateOption({})).toThrowError(); - expect(() => - ticketFields.createOrUpdateOption({ field_id: 'invalid' }) - ).toThrowError(); - expect(() => - ticketFields.createOrUpdateOption({ field_id: 123, id: 'invalid' }) - ).toThrowError(); - expect(() => - ticketFields.createOrUpdateOption({ - field_id: 123, - id: 456, - data: 'invalid' - }) - ).toThrowError(); - }); - }); - - describe('delete ticket field option', () => { - it('should process w/ valid input', () => { - expect(ticketFields.deleteOption({ field_id: 123, id: 456 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/ticket_fields/123/options/456.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketFields.deleteOption()).toThrowError(); - expect(() => ticketFields.deleteOption('invalid')).toThrowError(); - expect(() => ticketFields.deleteOption({})).toThrowError(); - expect(() => - ticketFields.deleteOption({ field_id: 'invalid' }) - ).toThrowError(); - expect(() => - ticketFields.deleteOption({ field_id: 123, id: 'invalid' }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/ticket_forms.test.js b/tests/src/v2/support/ticket_forms.test.js deleted file mode 100644 index f898b93..0000000 --- a/tests/src/v2/support/ticket_forms.test.js +++ /dev/null @@ -1,155 +0,0 @@ -const endpoint = require('../../../../src/v2/support/ticket_forms'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('ticket forms', () => { - let ticketForms; - - beforeEach(() => (ticketForms = endpoint({ instance, headers }))); - afterEach(() => (ticketForms = null)); - - describe('list ticket forms', () => { - it('should process w/ valid input', () => { - expect(ticketForms.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_forms.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketForms.list('invalid')).toThrowError(); - }); - }); - - describe('create ticket forms', () => { - it('should process w/ valid input', () => { - expect(ticketForms.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/ticket_forms.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketForms.create()).toThrowError(); - expect(() => ticketForms.create({})).toThrowError(); - expect(() => ticketForms.create('invalid')).toThrowError(); - expect(() => ticketForms.create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('show ticket form', () => { - it('should process w/ valid input', () => { - expect(ticketForms.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_forms/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketForms.show()).toThrowError(); - expect(() => ticketForms.show({})).toThrowError(); - expect(() => ticketForms.show('invalid')).toThrowError(); - expect(() => ticketForms.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('show many ticket forms', () => { - it('should process w/ valid input', () => { - expect(ticketForms.show_many({ ids: '1,2,3' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_forms/show_many.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketForms.show_many()).toThrowError(); - expect(() => ticketForms.show_many({})).toThrowError(); - expect(() => ticketForms.show_many('invalid')).toThrowError(); - expect(() => ticketForms.show_many({ ids: 0 })).toThrowError(); - }); - }); - - describe('update ticket forms', () => { - it('should process w/ valid input', () => { - expect(ticketForms.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/ticket_forms/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketForms.update()).toThrowError(); - expect(() => ticketForms.update({})).toThrowError(); - expect(() => ticketForms.update('invalid')).toThrowError(); - expect(() => ticketForms.update({ id: 0 })).toThrowError(); - expect(() => ticketForms.update({ id: 'invalid' })).toThrowError(); - expect(() => - ticketForms.update({ id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('delete ticket form', () => { - it('should process w/ valid input', () => { - expect(ticketForms.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/ticket_forms/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketForms.delete()).toThrowError(); - expect(() => ticketForms.delete({})).toThrowError(); - expect(() => ticketForms.delete('invalid')).toThrowError(); - expect(() => ticketForms.delete({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('reorder ticket forms', () => { - it('should process w/ valid input', () => { - expect(ticketForms.reorder({ data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/ticket_forms/reorder.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketForms.reorder()).toThrowError(); - expect(() => ticketForms.reorder({})).toThrowError(); - expect(() => ticketForms.reorder('invalid')).toThrowError(); - expect(() => ticketForms.reorder({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('clone an already existing ticket form', () => { - it('should process w/ valid input', () => { - expect(ticketForms.clone({ id: 123 })).toEqual({ - method: 'POST', - url: `${url}/api/v2/ticket_forms/123/clone.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketForms.clone()).toThrowError(); - expect(() => ticketForms.clone({})).toThrowError(); - expect(() => ticketForms.clone('invalid')).toThrowError(); - expect(() => ticketForms.clone({ id: 'invalid' })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/ticket_import.test.js b/tests/src/v2/support/ticket_import.test.js deleted file mode 100644 index bfbe64b..0000000 --- a/tests/src/v2/support/ticket_import.test.js +++ /dev/null @@ -1,51 +0,0 @@ -const endpoint = require('../../../../src/v2/support/ticket_import'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('end users', () => { - let ticket_import; - - beforeEach(() => (ticket_import = endpoint({ instance, headers }))); - afterEach(() => (ticket_import = null)); - - describe('ticket import (single)', () => { - it('should process w/ valid input', () => { - expect(ticket_import.single({ data: { ticket: {} } })).toEqual({ - method: 'POST', - url: `${url}/api/v2/imports/tickets.json`, - headers, - data: { ticket: {} } - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticket_import.single()).toThrowError(); - expect(() => ticket_import.single('invalid')).toThrowError(); - expect(() => ticket_import.single({})).toThrowError(); - expect(() => ticket_import.single({ ticket: 'invalid' })).toThrowError(); - }); - }); - - describe('ticket bulk import', () => { - it('should process w/ valid input', () => { - expect(ticket_import.bulk({ data: { tickets: [{}, {}] } })).toEqual({ - method: 'POST', - url: `${url}/api/v2/imports/tickets/create_many.json`, - headers, - data: { tickets: [{}, {}] } - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticket_import.bulk()).toThrowError(); - expect(() => ticket_import.bulk('invalid')).toThrowError(); - expect(() => ticket_import.bulk({})).toThrowError(); - expect(() => ticket_import.bulk({ tickets: 'invalid' })).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/ticket_metrics.test.js b/tests/src/v2/support/ticket_metrics.test.js deleted file mode 100644 index d2bed25..0000000 --- a/tests/src/v2/support/ticket_metrics.test.js +++ /dev/null @@ -1,56 +0,0 @@ -const endpoint = require('../../../../src/v2/support/ticket_metrics'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('ticket metrics', () => { - let ticketMetrics; - - beforeAll(() => (ticketMetrics = endpoint({ instance, headers }))); - afterAll(() => (ticketMetrics = null)); - - describe('list ticket metrics', () => { - it('should process w/ valid input', () => { - expect(ticketMetrics.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_metrics.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketMetrics.list('invalid')).toThrowError(); - }); - }); - - describe('show ticket metrics', () => { - it('should process w/ valid input', () => { - expect(ticketMetrics.show({ ticket_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123/metrics.json`, - headers - }); - - expect(ticketMetrics.show({ ticket_metric_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_metrics/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => ticketMetrics.show()).toThrowError(); - expect(() => ticketMetrics.show({})).toThrowError(); - expect(() => ticketMetrics.show('invalid')).toThrowError(); - expect(() => ticketMetrics.show({ ticket_id: 0 })).toThrowError(); - expect(() => ticketMetrics.show({ ticket_metric_id: 0 })).toThrowError(); - expect(() => - ticketMetrics.show({ ticket_id: 0, ticket_metric_id: 0 }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/tickets.test.js b/tests/src/v2/support/tickets.test.js deleted file mode 100644 index 794a72e..0000000 --- a/tests/src/v2/support/tickets.test.js +++ /dev/null @@ -1,504 +0,0 @@ -const endpoint = require('../../../../src/v2/support/tickets'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('tickets', () => { - let tickets; - - beforeEach(() => (tickets = endpoint({ instance, headers }))); - afterEach(() => (tickets = null)); - - describe('list tickets', () => { - it('should process w/ valid input', () => { - expect(tickets.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets.json`, - headers - }); - - expect(tickets.list({ type: 'organizations', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/123/tickets.json`, - headers - }); - - expect(tickets.list({ type: 'users_requested', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/tickets/requested.json`, - headers - }); - - expect(tickets.list({ type: 'users_ccd', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/tickets/ccd.json`, - headers - }); - - expect(tickets.list({ type: 'users_assigned', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/tickets/assigned.json`, - headers - }); - - expect(tickets.list({ type: 'recent' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/recent.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.list('invalid')).toThrowError(); - expect(() => tickets.list({ type: 'invalid' })).toThrowError(); - expect(() => - tickets.list({ type: 'tickets', id: 'invalid' }) - ).toThrowError(); - expect(() => tickets.list({ type: 'tickets', id: 123 })).toThrowError(); - }); - }); - - describe('list by external id', () => { - it('should process w/ valid input', () => { - expect(tickets.list_by_external_id({ external_id: '123' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets.json?external_id=123`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.list_by_external_id()).toThrowError(); - expect(() => tickets.list_by_external_id({})).toThrowError(); - expect(() => - tickets.list_by_external_id({ external_id: 123 }) - ).toThrowError(); - }); - }); - - describe('show', () => { - it('should process w/ valid input', () => { - expect(tickets.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.show()).toThrowError(); - expect(() => tickets.show({})).toThrowError(); - expect(() => tickets.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('show many', () => { - it('should process w/ valid input', () => { - expect(tickets.show_many({ ids: '1,2,3' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/show_many.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.show_many()).toThrowError(); - expect(() => tickets.show_many({})).toThrowError(); - expect(() => tickets.show_many({ ids: 0 })).toThrowError(); - }); - }); - - describe('create', () => { - it('should process w/ valid input', () => { - expect(tickets.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/tickets.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.create()).toThrowError(); - expect(() => tickets.create('invalid')).toThrowError(); - expect(() => tickets.create({})).toThrowError(); - expect(() => tickets.create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('create many', () => { - it('should process w/ valid input', () => { - expect(tickets.create_many({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/tickets/create_many.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.create_many()).toThrowError(); - expect(() => tickets.create_many('invalid')).toThrowError(); - expect(() => tickets.create_many({})).toThrowError(); - expect(() => tickets.create_many({ data: 123 })).toThrowError(); - }); - }); - - describe('update', () => { - it('should process w/ valid input', () => { - expect(tickets.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/tickets/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.update()).toThrowError(); - expect(() => tickets.update({})).toThrowError(); - expect(() => tickets.update({ data: {} })).toThrowError(); - expect(() => tickets.update({ id: 'invalid', data: {} })).toThrowError(); - expect(() => tickets.update({ id: 123, data: 'invalid' })).toThrowError(); - }); - }); - - describe('update many', () => { - it('should process w/ valid input', () => { - expect(tickets.update_many({ data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/tickets/update_many.json`, - headers, - data: {} - }); - - expect(tickets.update_many({ ids: '1,2,3', data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/tickets/update_many.json?ids=1,2,3`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.update_many()).toThrowError(); - expect(() => tickets.update_many('invalid')).toThrowError(); - expect(() => tickets.update_many({})).toThrowError(); - expect(() => tickets.update_many({ data: 'invalid' })).toThrowError(); - expect(() => tickets.update_many({ ids: 0, data: {} })).toThrowError(); - }); - }); - - describe('mark as spam', () => { - it('should process w/ valid input', () => { - expect(tickets.mark_as_spam({ id: 123 })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/tickets/123/mark_as_spam.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.mark_as_spam()).toThrowError(); - expect(() => tickets.mark_as_spam('invalid')).toThrowError(); - expect(() => tickets.mark_as_spam({})).toThrowError(); - expect(() => tickets.mark_as_spam({ id: 0 })).toThrowError(); - expect(() => tickets.mark_as_spam({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('mark as spam bulk', () => { - it('should process w/ valid input', () => { - expect(tickets.mark_as_spam_bulk({ ids: '1,2,3' })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/tickets/mark_many_as_spam.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.mark_as_spam_bulk()).toThrowError(); - expect(() => tickets.mark_as_spam_bulk('invalid')).toThrowError(); - expect(() => tickets.mark_as_spam_bulk({})).toThrowError(); - expect(() => tickets.mark_as_spam_bulk({ id: 0 })).toThrowError(); - expect(() => tickets.mark_as_spam_bulk({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('merge', () => { - it('should process w/ valid input', () => { - expect(tickets.merge({ id: 123, data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/tickets/123/merge.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.merge()).toThrowError(); - expect(() => tickets.merge('invalid')).toThrowError(); - expect(() => tickets.merge({})).toThrowError(); - expect(() => tickets.merge({ id: 'invalid' })).toThrowError(); - expect(() => tickets.merge({ id: 0 })).toThrowError(); - expect(() => tickets.merge({ id: 123, data: 'invalid' })).toThrowError(); - }); - }); - - describe('related', () => { - it('should process w/ valid input', () => { - expect(tickets.related({ id: 123 })).toEqual({ - method: 'POST', - url: `${url}/api/v2/tickets/123/related.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.related()).toThrowError(); - expect(() => tickets.related('invalid')).toThrowError(); - expect(() => tickets.related({})).toThrowError(); - expect(() => tickets.related({ id: 'invalid' })).toThrowError(); - expect(() => tickets.related({ id: 0 })).toThrowError(); - expect(() => - tickets.related({ id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('delete', () => { - it('should process w/ valid input', () => { - expect(tickets.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/tickets/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.delete()).toThrowError(); - expect(() => tickets.delete('invalid')).toThrowError(); - expect(() => tickets.delete({})).toThrowError(); - expect(() => tickets.delete({ id: 'invalid' })).toThrowError(); - expect(() => tickets.delete({ id: 0 })).toThrowError(); - expect(() => tickets.delete({ id: 123, data: 'invalid' })).toThrowError(); - }); - }); - - describe('delete bulk', () => { - it('should process w/ valid input', () => { - expect(tickets.delete_bulk({ ids: '1,2,3' })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/tickets/destroy_many.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.delete_bulk()).toThrowError(); - expect(() => tickets.delete_bulk('invalid')).toThrowError(); - expect(() => tickets.delete_bulk({})).toThrowError(); - expect(() => tickets.delete_bulk({ ids: 0 })).toThrowError(); - }); - }); - - describe('deleted', () => { - it('should process w/ valid input', () => { - expect(tickets.deleted()).toEqual({ - method: 'GET', - url: `${url}/api/v2/deleted_tickets.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.deleted('invalid')).toThrowError(); - expect(() => tickets.deleted({})).toThrowError(); - }); - }); - - describe('restore', () => { - it('should process w/ valid input', () => { - expect(tickets.restore({ id: 123 })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/deleted_tickets/123/restore.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.restore()).toThrowError(); - expect(() => tickets.restore('invalid')).toThrowError(); - expect(() => tickets.restore({})).toThrowError(); - expect(() => tickets.restore({ id: 0 })).toThrowError(); - }); - }); - - describe('restore bulk', () => { - it('should process w/ valid input', () => { - expect(tickets.restore_bulk({ ids: '1,2,3' })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/deleted_tickets/restore_many?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.restore_bulk()).toThrowError(); - expect(() => tickets.restore_bulk('invalid')).toThrowError(); - expect(() => tickets.restore_bulk({})).toThrowError(); - expect(() => tickets.restore_bulk({ ids: 0 })).toThrowError(); - }); - }); - - describe('delete permanently', () => { - it('should process w/ valid input', () => { - expect(tickets.delete_permanently({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/deleted_tickets/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.delete_permanently()).toThrowError(); - expect(() => tickets.delete_permanently('invalid')).toThrowError(); - expect(() => tickets.delete_permanently({})).toThrowError(); - expect(() => tickets.delete_permanently({ id: 0 })).toThrowError(); - expect(() => - tickets.delete_permanently({ id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('delete permanently bulk', () => { - it('should process w/ valid input', () => { - expect(tickets.delete_permanently_bulk({ ids: '1,2,3' })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/deleted_tickets/destroy_many?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.delete_permanently_bulk()).toThrowError(); - expect(() => tickets.delete_permanently_bulk('invalid')).toThrowError(); - expect(() => tickets.delete_permanently_bulk({})).toThrowError(); - expect(() => tickets.delete_permanently_bulk({ ids: 0 })).toThrowError(); - expect(() => - tickets.delete_permanently_bulk({ id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('collaborators', () => { - it('should process w/ valid input', () => { - expect(tickets.collaborators({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123/collaborators.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.collaborators()).toThrowError(); - expect(() => tickets.collaborators('invalid')).toThrowError(); - expect(() => tickets.collaborators({})).toThrowError(); - expect(() => tickets.collaborators({ id: 0 })).toThrowError(); - expect(() => tickets.collaborators({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('followers', () => { - it('should process w/ valid input', () => { - expect(tickets.followers({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123/followers.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.followers()).toThrowError(); - expect(() => tickets.followers('invalid')).toThrowError(); - expect(() => tickets.followers({})).toThrowError(); - expect(() => tickets.followers({ id: 0 })).toThrowError(); - expect(() => tickets.followers({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('email ccs', () => { - it('should process w/ valid input', () => { - expect(tickets.email_ccs({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123/email_ccs.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.email_ccs()).toThrowError(); - expect(() => tickets.email_ccs('invalid')).toThrowError(); - expect(() => tickets.email_ccs({})).toThrowError(); - expect(() => tickets.email_ccs({ id: 0 })).toThrowError(); - expect(() => tickets.email_ccs({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('incidents', () => { - it('should process w/ valid input', () => { - expect(tickets.incidents({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/tickets/123/incidents.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.incidents()).toThrowError(); - expect(() => tickets.incidents('invalid')).toThrowError(); - expect(() => tickets.incidents({})).toThrowError(); - expect(() => tickets.incidents({ id: 0 })).toThrowError(); - expect(() => tickets.incidents({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('problems', () => { - it('should process w/ valid input', () => { - expect(tickets.problems()).toEqual({ - method: 'GET', - url: `${url}/api/v2/problems.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.problems('invalid')).toThrowError(); - expect(() => tickets.problems({})).toThrowError(); - }); - }); - - describe('autocomplete problems', () => { - it('should process w/ valid input', () => { - expect(tickets.autocomplete_problems({ name: 'name' })).toEqual({ - method: 'POST', - url: `${url}/api/v2/problems/autocomplete.json?text=name`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => tickets.autocomplete_problems()).toThrowError(); - expect(() => tickets.autocomplete_problems('invalid')).toThrowError(); - expect(() => tickets.autocomplete_problems({})).toThrowError(); - expect(() => tickets.autocomplete_problems({ id: 0 })).toThrowError(); - expect(() => - tickets.autocomplete_problems({ id: 'invalid' }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/user_fields.test.js b/tests/src/v2/support/user_fields.test.js deleted file mode 100644 index 7761d18..0000000 --- a/tests/src/v2/support/user_fields.test.js +++ /dev/null @@ -1,208 +0,0 @@ -const endpoint = require('../../../../src/v2/support/user_fields'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('ticket fields', () => { - let user_fields; - - beforeEach(() => (user_fields = endpoint({ instance, headers }))); - afterEach(() => (user_fields = null)); - - describe('list user fields', () => { - it('should process w/ valid input', () => { - expect(user_fields.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/user_fields.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.list('invalid')).toThrowError(); - }); - }); - - describe('show user field', () => { - it('should process w/ valid input', () => { - expect(user_fields.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/user_fields/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.show()).toThrowError(); - expect(() => user_fields.show('invalid')).toThrowError(); - expect(() => user_fields.show({})).toThrowError(); - expect(() => user_fields.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('create user fields', () => { - it('should process w/ valid input', () => { - expect(user_fields.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/user_fields.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.create()).toThrowError(); - expect(() => user_fields.create('invalid')).toThrowError(); - expect(() => user_fields.create({})).toThrowError(); - expect(() => user_fields.create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('update user fields', () => { - it('should process w/ valid input', () => { - expect(user_fields.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/user_fields/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.update()).toThrowError(); - expect(() => user_fields.update('invalid')).toThrowError(); - expect(() => user_fields.update({})).toThrowError(); - expect(() => user_fields.update({ id: 'invalid' })).toThrowError(); - expect(() => - user_fields.update({ id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('delete user field', () => { - it('should process w/ valid input', () => { - expect(user_fields.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/user_fields/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.delete()).toThrowError(); - expect(() => user_fields.delete('invalid')).toThrowError(); - expect(() => user_fields.delete({})).toThrowError(); - expect(() => user_fields.delete({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('reorder user field', () => { - it('should process w/ valid input', () => { - expect(user_fields.reorder({ data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/user_fields/reorder.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.reorder()).toThrowError(); - expect(() => user_fields.reorder('invalid')).toThrowError(); - expect(() => user_fields.reorder({})).toThrowError(); - expect(() => user_fields.reorder({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('list user field options', () => { - it('should process w/ valid input', () => { - expect(user_fields.listOptions({ field_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/user_fields/123/options.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.listOptions()).toThrowError(); - expect(() => user_fields.listOptions('invalid')).toThrowError(); - expect(() => user_fields.listOptions({})).toThrowError(); - expect(() => - user_fields.listOptions({ field_id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('show a user field option', () => { - it('should process w/ valid input', () => { - expect(user_fields.showOption({ field_id: 123, id: 456 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/ticket_fields/123/options/456.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.showOption()).toThrowError(); - expect(() => user_fields.showOption('invalid')).toThrowError(); - expect(() => user_fields.showOption({})).toThrowError(); - expect(() => - user_fields.showOption({ field_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_fields.showOption({ field_id: 123, id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('create or update a user field option', () => { - it('should process w/ valid input', () => { - expect( - user_fields.createOrUpdateOption({ field_id: 123, data: {} }) - ).toEqual({ - method: 'POST', - url: `${url}/api/v2/user_fields/123/options.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.createOrUpdateOption()).toThrowError(); - expect(() => user_fields.createOrUpdateOption('invalid')).toThrowError(); - expect(() => user_fields.createOrUpdateOption({})).toThrowError(); - expect(() => - user_fields.createOrUpdateOption({ field_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_fields.createOrUpdateOption({ field_id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('delete user field option', () => { - it('should process w/ valid input', () => { - expect(user_fields.deleteOption({ field_id: 123, id: 456 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/user_fields/123/options/456.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_fields.deleteOption()).toThrowError(); - expect(() => user_fields.deleteOption('invalid')).toThrowError(); - expect(() => user_fields.deleteOption({})).toThrowError(); - expect(() => - user_fields.deleteOption({ field_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_fields.deleteOption({ field_id: 123, id: 'invalid' }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/user_identities.test.js b/tests/src/v2/support/user_identities.test.js deleted file mode 100644 index 1ac27f8..0000000 --- a/tests/src/v2/support/user_identities.test.js +++ /dev/null @@ -1,299 +0,0 @@ -const endpoint = require('../../../../src/v2/support/user_identities'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('user identities', () => { - let user_identities; - - beforeEach(() => (user_identities = endpoint({ instance, headers }))); - afterEach(() => (user_identities = null)); - - describe('list identities', () => { - it('should process w/ valid input', () => { - expect(user_identities.list({ user_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/identities.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => user_identities.list()).toThrowError(); - expect(() => user_identities.list({})).toThrowError(); - expect(() => user_identities.list('invalid')).toThrowError(); - expect(() => user_identities.list({ user_id: 'invalid' })).toThrowError(); - }); - }); - - describe('show identity', () => { - test('should process w/ valid input', () => { - expect(user_identities.show({ user_id: 123, id: 456 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/identities/456.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => user_identities.show()).toThrowError(); - expect(() => user_identities.show({})).toThrowError(); - expect(() => user_identities.show({ user_id: 'invalid' })).toThrowError(); - expect(() => - user_identities.show({ user_id: 0, id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('create identity', () => { - test('should process w/ valid input', () => { - expect(user_identities.create({ user_id: 123, data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/123/identities.json`, - headers, - data: {} - }); - - expect( - user_identities.create({ user_id: 123, end_users: false, data: {} }) - ).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/123/identities.json`, - headers, - data: {} - }); - - expect( - user_identities.create({ user_id: 123, end_users: true, data: {} }) - ).toEqual({ - method: 'POST', - url: `${url}/api/v2/end_users/123/identities.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => user_identities.create()).toThrowError(); - expect(() => user_identities.create({})).toThrowError(); - expect(() => user_identities.create('invalid')).toThrowError(); - expect(() => - user_identities.create({ user_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.create({ user_id: 123, end_users: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.create({ user_id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('update identity', () => { - test('should process w/ valid input', () => { - expect( - user_identities.update({ user_id: 123, id: 456, data: {} }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/identities/456.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => user_identities.update()).toThrowError(); - expect(() => user_identities.update({})).toThrowError(); - expect(() => - user_identities.update({ user_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.update({ user_id: 123, id: 'invalid', data: {} }) - ).toThrowError(); - expect(() => - user_identities.update({ user_id: 123, id: 456 }) - ).toThrowError(); - expect(() => - user_identities.update({ user_id: 123, id: 456, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('make identity primary', () => { - test('should process w/ valid input', () => { - expect(user_identities.make_primary({ user_id: 123, id: 456 })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/identities/456/make_primary`, - headers, - data: {} - }); - - expect( - user_identities.make_primary({ user_id: 123, id: 456, data: {} }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/identities/456/make_primary`, - headers, - data: {} - }); - - expect( - user_identities.make_primary({ - user_id: 123, - id: 456, - end_users: false, - data: {} - }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/identities/456/make_primary`, - headers, - data: {} - }); - - expect( - user_identities.make_primary({ - user_id: 123, - id: 456, - end_users: true, - data: {} - }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/end_users/123/identities/456/make_primary`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => user_identities.make_primary()).toThrowError(); - expect(() => user_identities.make_primary({})).toThrowError(); - expect(() => user_identities.make_primary('invalid')).toThrowError(); - expect(() => - user_identities.make_primary({ user_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.make_primary({ user_id: 123, id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.make_primary({ - user_id: 123, - id: 456, - end_users: 'invalid' - }) - ).toThrowError(); - expect(() => - user_identities.make_primary({ user_id: 123, id: 456, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('verify identity', () => { - test('should process w/ valid input', () => { - expect(user_identities.verify({ user_id: 123, id: 456 })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/identities/456/verify`, - headers, - data: {} - }); - - expect( - user_identities.verify({ user_id: 123, id: 456, data: {} }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/identities/456/verify`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => user_identities.verify()).toThrowError(); - expect(() => user_identities.verify({})).toThrowError(); - expect(() => user_identities.verify('invalid')).toThrowError(); - expect(() => - user_identities.verify({ user_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.verify({ user_id: 123, id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.verify({ user_id: 123, id: 456, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('request user verification', () => { - test('should process w/ valid input', () => { - expect( - user_identities.request_verification({ user_id: 123, id: 456 }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/identities/456/request_verification.json`, - headers, - data: {} - }); - - expect( - user_identities.request_verification({ - user_id: 123, - id: 456, - data: {} - }) - ).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/identities/456/request_verification.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => user_identities.request_verification()).toThrowError(); - expect(() => user_identities.request_verification({})).toThrowError(); - expect(() => - user_identities.request_verification('invalid') - ).toThrowError(); - expect(() => - user_identities.request_verification({ user_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.request_verification({ user_id: 123, id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.request_verification({ - user_id: 123, - id: 456, - data: 'invalid' - }) - ).toThrowError(); - }); - }); - - describe('delete identity', () => { - test('should process w/ valid input', () => { - expect(user_identities.delete({ user_id: 123, id: 456 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/users/123/identities/456.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => user_identities.delete()).toThrowError(); - expect(() => user_identities.delete({})).toThrowError(); - expect(() => user_identities.delete('invalid')).toThrowError(); - expect(() => - user_identities.delete({ user_id: 'invalid' }) - ).toThrowError(); - expect(() => - user_identities.delete({ user_id: 123, id: 'invalid' }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/user_passwords.test.js b/tests/src/v2/support/user_passwords.test.js deleted file mode 100644 index 3f9af32..0000000 --- a/tests/src/v2/support/user_passwords.test.js +++ /dev/null @@ -1,75 +0,0 @@ -const endpoint = require('../../../../src/v2/support/user_passwords'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('user passwords', () => { - let userPasswords; - - beforeEach(() => (userPasswords = endpoint({ instance, headers }))); - afterEach(() => (userPasswords = null)); - - describe("set a user's password", () => { - it('should process w/ valid input', () => { - expect(userPasswords.set({ user_id: 123, data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/123/password.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => userPasswords.set()).toThrowError(); - expect(() => userPasswords.set('invalid')).toThrowError(); - expect(() => userPasswords.set({ user_id: 'invalid' })).toThrowError(); - expect(() => - userPasswords.set({ user_id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('change your password', () => { - it('should process w/ valid input', () => { - expect(userPasswords.change({ user_id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123/password.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => userPasswords.change()).toThrowError(); - expect(() => userPasswords.change({})).toThrowError(); - expect(() => userPasswords.change('invalid')).toThrowError(); - expect(() => userPasswords.change({ id: 'invalid' })).toThrowError(); - expect(() => - userPasswords.change({ id: 123, data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('get a list of password requirements', () => { - it('should process w/ valid input', () => { - expect(userPasswords.requirements({ user_id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/password/requirements.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => userPasswords.requirements()).toThrowError(); - expect(() => userPasswords.requirements({})).toThrowError(); - expect(() => userPasswords.requirements('invalid')).toThrowError(); - expect(() => - userPasswords.requirements({ user_id: 'invalid' }) - ).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/users.test.js b/tests/src/v2/support/users.test.js deleted file mode 100644 index bc0d9e4..0000000 --- a/tests/src/v2/support/users.test.js +++ /dev/null @@ -1,466 +0,0 @@ -const endpoint = require('../../../../src/v2/support/users'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('users', () => { - let users; - - beforeEach(() => (users = endpoint({ instance, headers }))); - afterEach(() => (users = null)); - - describe('list users', () => { - it('should process w/ valid input', () => { - expect(users.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/users.json`, - headers - }); - - expect(users.list({ type: 'groups', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/groups/123/users.json`, - headers - }); - - expect(users.list({ type: 'organizations', id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/organizations/123/users.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - // Invalid "type" - expect(() => users.list({ type: 'invalid' })).toThrowError(); - expect(() => users.list({ type: 'invalid', id: 0 })).toThrowError(); - expect(() => users.list({ type: 123 })).toThrowError(); - expect(() => users.list({ type: 123, id: 123 })).toThrowError(); - - // Invalid "id" - expect(() => users.list({ type: '', id: 123 })).toThrowError(); - expect(() => users.list({ type: 'groups' })).toThrowError(); - expect(() => users.list({ type: 'groups', id: 0 })).toThrowError(); - expect(() => users.list({ type: 'organizations' })).toThrowError(); - expect(() => users.list({ type: 'organizations', id: 0 })).toThrowError(); - - // Invalid "type" & "id" - expect(() => users.list({ id: 0 })).toThrowError(); - expect(() => users.list({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('show user', () => { - test('should process w/ valid input', () => { - expect(users.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.show()).toThrowError(); - expect(() => users.show({})).toThrowError(); - expect(() => users.show({ id: 'invalid' })).toThrowError(); - expect(() => users.show({ id: 0 })).toThrowError(); - }); - }); - - describe('show many users', () => { - test('should process w/ valid input', () => { - expect(users.show_many({ ids: '1,2,3' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/show_many.json?ids=1,2,3`, - headers - }); - - expect(users.show_many({ external_ids: '1,2,3' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/show_many.json?external_ids=1,2,3`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - // Missing options - expect(() => users.show_many()).toThrowError(); - expect(() => users.show_many({})).toThrowError(); - - // Invalid options - expect(() => users.show_many({ ids: 123 })).toThrowError(); - expect(() => users.show_many({ external_ids: 123 })).toThrowError(); - expect(() => - users.show_many({ ids: '1,2,3', external_ids: '1,2,3' }) - ).toThrowError(); - }); - }); - - describe('user related information', () => { - test('should process w/ valid input', () => { - expect(users.related({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/related.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.related()).toThrowError(); - expect(() => users.related({})).toThrowError(); - expect(() => users.related({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('create user', () => { - test('should process w/ valid input', () => { - expect(users.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.create()).toThrowError(); - expect(() => users.create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('create or update user', () => { - test('should process w/ valid input', () => { - expect(users.create_or_update({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/create_or_update.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.create_or_update()).toThrowError(); - expect(() => users.create_or_update({})).toThrowError(); - expect(() => users.create_or_update({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('create or update many users', () => { - test('should process w/ valid input', () => { - expect(users.create_or_update_many({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/create_or_update_many.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.create_or_update_many()).toThrowError(); - expect(() => users.create_or_update_many({})).toThrowError(); - expect(() => - users.create_or_update_many({ data: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('merge self with another user', () => { - test('should process w/ valid input', () => { - expect(users.merge_self({ data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/me/merge.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.merge_self()).toThrowError(); - expect(() => users.merge_self({})).toThrowError(); - expect(() => users.merge_self({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('merge end users', () => { - test('should process w/ valid input', () => { - expect(users.merge({ id: 123, data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/123/merge.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.merge()).toThrowError(); - expect(() => users.merge({})).toThrowError(); - expect(() => users.merge({ id: 'invalid', data: {} })).toThrowError(); - expect(() => users.merge({ id: 123, data: 'invalid' })).toThrowError(); - }); - }); - - describe('create many users', () => { - test('should process w/ valid input', () => { - expect(users.create_many({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/create_many.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.create_many()).toThrowError(); - expect(() => users.create_many({})).toThrowError(); - expect(() => users.create_many({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('update user', () => { - test('should process w/ valid input', () => { - expect(users.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users/123.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.update()).toThrowError(); - expect(() => users.update({})).toThrowError(); - expect(() => users.update({ data: {} })).toThrowError(); - expect(() => users.update({ id: 'invalid', data: {} })).toThrowError(); - expect(() => users.update({ id: 123 })).toThrowError(); - expect(() => users.update({ id: 123, data: 'invalid' })).toThrowError(); - }); - }); - - describe('update many users', () => { - test('should process w/ valid input', () => { - expect(users.update_many({ data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users.json`, - headers, - data: {} - }); - - expect(users.update_many({ ids: '1,2,3', data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users.json?ids=1,2,3`, - headers, - data: {} - }); - - expect(users.update_many({ external_ids: '1,2,3', data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/users.json?external_ids=1,2,3`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.update_many()).toThrowError(); - expect(() => users.update_many({})).toThrowError(); - expect(() => users.update_many({ data: 'invalid' })).toThrowError(); - expect(() => users.update_many({ ids: 123, data: {} })).toThrowError(); - expect(() => - users.update_many({ external_ids: 123, data: {} }) - ).toThrowError(); - expect(() => - users.update_many({ ids: '', external_ids: '', data: {} }) - ).toThrowError(); - expect(() => - users.update_many({ ids: '1,2,3', external_ids: '1,2,3', data: {} }) - ).toThrowError(); - }); - }); - - describe('delete many users', () => { - test('should process w/ valid input', () => { - expect(users.delete_many({ ids: '1,2,3' })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/users/destroy_many.json?ids=1,2,3`, - headers - }); - - expect(users.delete_many({ external_ids: '1,2,3' })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/users/destroy_many.json?external_ids=1,2,3`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.delete_many()).toThrowError(); - expect(() => users.delete_many({})).toThrowError(); - expect(() => users.delete_many({ ids: '' })).toThrowError(); - expect(() => users.delete_many({ ids: 123 })).toThrowError(); - expect(() => users.delete_many({ external_ids: '' })).toThrowError(); - expect(() => users.delete_many({ external_ids: 123 })).toThrowError(); - }); - }); - - describe('delete user', () => { - test('should process w/ valid input', () => { - expect(users.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/users/123.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.delete()).toThrowError(); - expect(() => users.delete(123)).toThrowError(); - expect(() => users.delete({})).toThrowError(); - expect(() => users.delete({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('search', () => { - test('should process w/ valid input', () => { - expect(users.search({ query: 'valid_query' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/search.json?query=valid_query`, - headers - }); - - expect(users.search({ external_id: 'external_id' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/search.json?external_id=external_id`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.search()).toThrowError(); - expect(() => users.search({})).toThrowError(); - expect(() => users.search({ query: '' })).toThrowError(); - expect(() => users.search({ external_id: '' })).toThrowError(); - expect(() => users.search({ query: '', external_id: '' })).toThrowError(); - expect(() => - users.search({ query: 'query', external_id: 'external_id' }) - ).toThrowError(); - }); - }); - - describe('autocomplete', () => { - test('should process w/ valid input', () => { - expect(users.autocomplete({ name: 'name' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/autocomplete.json?name=name`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.autocomplete()).toThrowError(); - expect(() => users.autocomplete({})).toThrowError(); - expect(() => users.autocomplete('name')).toThrowError(); - expect(() => users.autocomplete({ name: 123 })).toThrowError(); - expect(() => users.autocomplete({ name: '' })).toThrowError(); - }); - }); - - describe('request create user', () => { - test('should process w/ valid input', () => { - expect(users.request_create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/users/request_create.json`, - headers, - data: {} - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.request_create()).toThrowError(); - expect(() => users.request_create({})).toThrowError(); - expect(() => users.request_create({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('list deleted users', () => { - test('should process w/ valid input', () => { - expect(users.list_deleted()).toEqual({ - method: 'GET', - url: `${url}/api/v2/deleted_users.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.list_deleted('invalid')).toThrowError(); - }); - }); - - describe('show deleted user', () => { - test('should process w/ valid input', () => { - expect(users.show_deleted({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/deleted_users/123.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.show_deleted()).toThrowError(); - }); - }); - - describe('permanently delete user', () => { - test('should process w/ valid input', () => { - expect(users.permanently_delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/deleted_users/123.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.permanently_delete()).toThrowError(); - expect(() => users.permanently_delete({})).toThrowError(); - expect(() => users.permanently_delete({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('compliance deletion statuses', () => { - test('should process w/ valid input', () => { - expect(users.compliance_deletion_statuses({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/123/compliance_deletion_statuses.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.compliance_deletion_statuses()).toThrowError(); - expect(() => - users.compliance_deletion_statuses('invalid') - ).toThrowError(); - expect(() => users.compliance_deletion_statuses({})).toThrowError(); - expect(() => - users.compliance_deletion_statuses({ id: 'invalid' }) - ).toThrowError(); - }); - }); - - describe('current authenticated user', () => { - test('should process w/ valid input', () => { - expect(users.current()).toEqual({ - method: 'GET', - url: `${url}/api/v2/users/me.json`, - headers - }); - }); - - test('should throw error w/ invalid input', () => { - expect(() => users.current('invalid')).toThrowError(); - }); - }); -}); diff --git a/tests/src/v2/support/views.test.js b/tests/src/v2/support/views.test.js deleted file mode 100644 index a12a08e..0000000 --- a/tests/src/v2/support/views.test.js +++ /dev/null @@ -1,308 +0,0 @@ -const endpoint = require('../../../../src/v2/support/views'); - -const instance = 'instance'; -const url = `https://${instance}.zendesk.com`; -const headers = { - 'Content-Type': 'application/json', - Authorization: 'Basic <64bit_encoded_credentials>' -}; - -describe('views', () => { - let views; - - beforeEach(() => (views = endpoint({ instance, headers }))); - afterEach(() => (views = null)); - - describe('list views', () => { - it('should process w/ valid input', () => { - expect(views.list()).toEqual({ - method: 'GET', - url: `${url}/api/v2/views.json`, - headers - }); - - expect(views.list({ ids: '1,2,3' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/views.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.list('invalid')).toThrowError(); - }); - }); - - describe('update many views', () => { - it('should process w/ valid input', () => { - expect(views.update_many({ data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/views/update_many.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.update_many()).toThrowError(); - expect(() => views.update_many({})).toThrowError(); - expect(() => views.update_many('invalid')).toThrowError(); - expect(() => views.update_many({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('list active views', () => { - it('should process w/ valid input', () => { - expect(views.active()).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/active.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.active('invalid')).toThrowError(); - }); - }); - - describe('list views - compact', () => { - it('should process w/ valid input', () => { - expect(views.compact()).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/compact.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.compact('invalid')).toThrowError(); - }); - }); - - describe('show view', () => { - it('should process w/ valid input', () => { - expect(views.show({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.show()).toThrowError(); - expect(() => views.show({})).toThrowError(); - expect(() => views.show('invalid')).toThrowError(); - expect(() => views.show({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('create view', () => { - it('should process w/ valid input', () => { - expect(views.create({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/views.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.create()).toThrowError(); - expect(() => views.create({})).toThrowError(); - expect(() => views.create('invalid')).toThrowError(); - expect(() => views.create({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('update view', () => { - it('should process w/ valid input', () => { - expect(views.update({ id: 123, data: {} })).toEqual({ - method: 'PUT', - url: `${url}/api/v2/views/123.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.update()).toThrowError(); - expect(() => views.update({})).toThrowError(); - expect(() => views.update('invalid')).toThrowError(); - expect(() => views.update({ id: 'invalid' })).toThrowError(); - expect(() => views.update({ id: 123, data: 'invalid' })).toThrowError(); - }); - }); - - describe('delete view', () => { - it('should process w/ valid input', () => { - expect(views.delete({ id: 123 })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/views/123.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.delete()).toThrowError(); - expect(() => views.delete({})).toThrowError(); - expect(() => views.delete('invalid')).toThrowError(); - expect(() => views.delete({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('delete many views', () => { - it('should process w/ valid input', () => { - expect(views.delete_many({ data: {} })).toEqual({ - method: 'DELETE', - url: `${url}/api/v2/views/destroy_many.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.delete_many()).toThrowError(); - expect(() => views.delete_many({})).toThrowError(); - expect(() => views.delete_many('invalid')).toThrowError(); - expect(() => views.delete_many({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('execute view', () => { - it('should process w/ valid input', () => { - expect(views.execute({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/123/execute.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.execute()).toThrowError(); - expect(() => views.execute({})).toThrowError(); - expect(() => views.execute('invalid')).toThrowError(); - expect(() => views.execute({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('list tickets from a view', () => { - it('should process w/ valid input', () => { - expect(views.tickets({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/123/tickets.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.tickets()).toThrowError(); - expect(() => views.tickets({})).toThrowError(); - expect(() => views.tickets('invalid')).toThrowError(); - expect(() => views.tickets({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('get view counts', () => { - it('should process w/ valid input', () => { - expect(views.count_many({ ids: '1,2,3' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/count_many.json?ids=1,2,3`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.count_many()).toThrowError(); - expect(() => views.count_many({})).toThrowError(); - expect(() => views.count_many('invalid')).toThrowError(); - expect(() => views.count_many({ ids: 0 })).toThrowError(); - }); - }); - - describe('get view count', () => { - it('should process w/ valid input', () => { - expect(views.count({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/123/count.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.count()).toThrowError(); - expect(() => views.count({})).toThrowError(); - expect(() => views.count('invalid')).toThrowError(); - expect(() => views.count({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('export view', () => { - it('should process w/ valid input', () => { - expect(views.export({ id: 123 })).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/123/export.json`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.export()).toThrowError(); - expect(() => views.export({})).toThrowError(); - expect(() => views.export('invalid')).toThrowError(); - expect(() => views.export({ id: 'invalid' })).toThrowError(); - }); - }); - - describe('search views', () => { - it('should process w/ valid input', () => { - expect(views.search({ query: 'query' })).toEqual({ - method: 'GET', - url: `${url}/api/v2/views/search.json?query=query`, - headers - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.search()).toThrowError(); - expect(() => views.search({})).toThrowError(); - expect(() => views.search('invalid')).toThrowError(); - expect(() => views.search({ query: '' })).toThrowError(); - }); - }); - - describe('previewing views', () => { - it('should process w/ valid input', () => { - expect(views.preview({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/views/preview.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.preview()).toThrowError(); - expect(() => views.preview({})).toThrowError(); - expect(() => views.preview('invalid')).toThrowError(); - expect(() => views.preview({ data: 'invalid' })).toThrowError(); - }); - }); - - describe('preview count', () => { - it('should process w/ valid input', () => { - expect(views.preview_count({ data: {} })).toEqual({ - method: 'POST', - url: `${url}/api/v2/views/preview/count.json`, - headers, - data: {} - }); - }); - - it('should throw error w/ invalid input', () => { - expect(() => views.preview_count()).toThrowError(); - expect(() => views.preview_count({})).toThrowError(); - expect(() => views.preview_count('invalid')).toThrowError(); - expect(() => views.preview_count({ data: 'invalid' })).toThrowError(); - }); - }); -}); diff --git a/tests/utils/headers.test.js b/tests/utils/headers.test.js new file mode 100644 index 0000000..7cf3c0c --- /dev/null +++ b/tests/utils/headers.test.js @@ -0,0 +1,49 @@ +const base64 = require('js-base64').Base64; +const { generate } = require('../../src/utils/headers'); + +describe('headers', () => { + let options; + + beforeEach(() => { + options = { + email: 'user@email.com', + password: 'password', + token: 'token' + }; + }); + + afterEach(() => { + options = null; + }); + + describe('generate', () => { + it('should process using an email & password', () => { + const { email, password } = options; + const encoded = base64.encode(`${email}:${password}`); + + expect(generate({ email, password })).toEqual({ + 'Content-Type': 'application/json', + Authorization: `Basic ${encoded}` + }); + }); + + it('should process using an email & token', () => { + const { email, token } = options; + const encoded = base64.encode(`${email}/token:${token}`); + + expect(generate({ email, token })).toEqual({ + 'Content-Type': 'application/json', + Authorization: `Basic ${encoded}` + }); + }); + + it('should fail with invalid input', () => { + const { email, token } = options; + + expect(() => generate()).toThrowError(); + expect(() => generate({})).toThrowError(); + expect(() => generate({ email })).toThrowError(); + expect(() => generate({ token })).toThrowError(); + }); + }); +}); diff --git a/tests/utils/options.test.js b/tests/utils/options.test.js new file mode 100644 index 0000000..193d42e --- /dev/null +++ b/tests/utils/options.test.js @@ -0,0 +1,51 @@ +const { validate, prepare } = require('../../src/utils/options'); + +describe('util: options', () => { + let options; + + beforeEach(() => { + options = { + instance: 'instance', + email: 'user@email.com', + password: 'password', + token: 'token' + }; + }); + + afterEach(() => { + options = null; + }); + + describe('validate', () => { + it('should setup validate function', () => { + expect(validate).toBeTruthy(); + }); + + it('should process a valid options object', () => { + expect(validate(options)).toBeTruthy(); + }); + }); + + describe('prepare', () => { + it('should setup prepare function with password', () => { + const { instance, email, password } = options; + const { url, headers } = prepare({ instance, email, password }); + + expect(url).toBeTruthy(); + expect(headers).toBeTruthy(); + }); + + it('should setup prepare function with token', () => { + const { instance, email, token } = options; + const { url, headers } = prepare({ instance, email, token }); + + expect(url).toBeTruthy(); + expect(headers).toBeTruthy(); + }); + + it('should fail with invalid input', () => { + expect(() => prepare()).toThrowError(); + expect(() => prepare(options)).toThrowError(); + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index 43c3508..00eccee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2296,6 +2296,11 @@ jest@^24.9.0: import-local "^2.0.0" jest-cli "^24.9.0" +js-base64@^2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.1.tgz#1efa39ef2c5f7980bb1784ade4a8af2de3291121" + integrity sha512-M7kLczedRMYX4L8Mdh4MzyAMM9O5osx+4FcOQuTvr3A9F2D9S5JXheN0ewNbrvK2UatkTRhL5ejGmGSjNMiZuw== + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"