Skip to content

Commit

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

// Validation
const _id = Joi.number().positive();

// 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 Reasons for Satisfaction Rating
*
* GET /api/v2/satisfaction_reasons.json
* https://developer.zendesk.com/rest_api/docs/support/satisfaction_reasons#list-reasons-for-satisfaction-rating
*/
list: () => {
// Ignore any options
return {
method: 'GET',
url: `${url}/api/v2/satisfaction_reasons.json`,
headers
};
},

/**
* Show Reason for Satisfaction Rating
*
* GET /api/v2/satisfaction_reasons/{id}.json
* https://developer.zendesk.com/rest_api/docs/support/satisfaction_reasons#show-reason-for-satisfaction-rating
*/
show: (options = {}) => {
const { error } = Joi.object({
id: _id.required()
}).validate(options);
if (error) throw new Error(error.details[0].message);

const { id } = options;
return {
method: 'GET',
url: `${url}/api/v2/satisfaction_reasons/${id}.json`,
headers
};
}
};
};
60 changes: 60 additions & 0 deletions tests/src/api/support/satisfaction_reasons.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const endpoint = require('../../../../src/api/support/satisfaction_reasons');
const { prepare } = require('../../../../src/utils/options');

describe('ticket skips', () => {
let endPoint, options, url, headers;

beforeEach(() => {
options = {
instance: 'instance',
email: 'user@email.com',
token: 'token'
};
endPoint = endpoint(options);
({ url, headers } = prepare(options));
});

afterEach(() => {
options = null;
endPoint = null;
url = null;
headers = null;
});

describe('init', () => {
it('should setup endpoint object', () => {
expect(endpoint(options)).toBeTruthy();
});

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

describe('list reasons for satisfaction rating', () => {
it('should process w/ valid input', () => {
expect(endPoint.list()).toEqual({
method: 'GET',
url: `${url}/api/v2/satisfaction_reasons.json`,
headers
});
});
});

describe('show reason for satisfaction rating', () => {
it('should process w/ valid input', () => {
expect(endPoint.show({ id: 123 })).toEqual({
method: 'GET',
url: `${url}/api/v2/satisfaction_reasons/123.json`,
headers
});
});

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

0 comments on commit bff07f0

Please sign in to comment.