From e8e27da4073dd89ae83ad14ba06aa0c3fbeb4b9b Mon Sep 17 00:00:00 2001 From: k-grant <38666098+k-grant@users.noreply.github.com> Date: Tue, 21 Jul 2020 18:19:18 -0700 Subject: [PATCH] Feature/en 6366 add message channels support (#80) * feat(messageChannels): EN-6366: Add MessageChannels call to customer to retrieve available channels to a customer. * simplify to a single call, to get message channels --- src/mocks/index.js | 1 + src/mocks/messageChannels.js | 23 ++++++++++++ src/resources/Customer.js | 9 +++++ src/resources/MessageChannels.js | 54 +++++++++++++++++++++++++++ src/resources/MessageChannels.test.js | 34 +++++++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 src/mocks/messageChannels.js create mode 100644 src/resources/MessageChannels.js create mode 100644 src/resources/MessageChannels.test.js diff --git a/src/mocks/index.js b/src/mocks/index.js index 0db16fe..5abecff 100644 --- a/src/mocks/index.js +++ b/src/mocks/index.js @@ -13,6 +13,7 @@ export { default as drivers } from './drivers'; export { default as externalApis } from './externalApis'; export { default as incidents } from './incidents'; export { default as messages } from './messages'; +export { default as messageChannels } from './messageChannels'; export { default as patterns } from './patterns'; export { default as reportingTickets } from './reportingTickets'; export { default as realTime } from './realTime'; diff --git a/src/mocks/messageChannels.js b/src/mocks/messageChannels.js new file mode 100644 index 0000000..d4a5af1 --- /dev/null +++ b/src/mocks/messageChannels.js @@ -0,0 +1,23 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import fetchMock from 'fetch-mock'; +import Client from '../Client'; + +const messageChannels = { + setUpSuccessfulMock: (client) => { + const listResponse = () => new Response( + Client.toBlob(messageChannels.list), { + headers: { + Link: '1/SYNC/messages_channels>', + }, + }); + fetchMock + .get(client.resolve('/1/SYNC/message_channels'), listResponse); + }, + getByName: name => messageChannels.list.find(v => v.name === name), + list: [{ + href: '/1/SYNC/message_channels/Signs', + name: 'Signs', + }], +}; + +export default messageChannels; diff --git a/src/resources/Customer.js b/src/resources/Customer.js index 17fe148..5cc23e7 100644 --- a/src/resources/Customer.js +++ b/src/resources/Customer.js @@ -20,6 +20,7 @@ import EnplugScreenshot from './EnplugScreenshot'; import EnplugConfiguration from './EnplugConfiguration'; import Message from './Message'; import MessagesContext from './MessagesContext'; +import MessageChannels from './MessageChannels'; import Pattern from './Pattern'; import PatternsContext from './PatternsContext'; import ReportingTicket from './ReportingTicket'; @@ -233,6 +234,14 @@ class Customer extends Resource { return this.resource(Incident, Incident.makeHref(this.code, id)); } + /** + * Gets a customers available message channels by its code. + * @returns {MessageChannels} for fetching this customer's message channels + */ + messageChannels() { + return this.resource(MessageChannels, MessageChannels.makeHref(this.code)); + } + /** * Gets a context for querying this customer's messages * @returns {MessagesContext} Context for querying this customer's messages diff --git a/src/resources/MessageChannels.js b/src/resources/MessageChannels.js new file mode 100644 index 0000000..a22a20c --- /dev/null +++ b/src/resources/MessageChannels.js @@ -0,0 +1,54 @@ +import Resource from './Resource'; + +/** + * MessageChannels resource + */ +class MessageChannels extends Resource { + /** + * Creates a new MessageChannels. + * + * Will populate itself with the values given to it after the client parameter + * @example