diff --git a/CHANGELOG.md b/CHANGELOG.md index 79905c9d..f8d9ec11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -# [Unreleased](https://github.com/purecloudlabs/genesys-cloud-streaming-client/compare/v19.7.1...HEAD) +# [Unreleased](https://github.com/purecloudlabs/genesys-cloud-streaming-client/compare/v19.8.0...HEAD) + +# [v19.8.0](https://github.com/purecloudlabs/genesys-cloud-streaming-client/compare/v19.7.1...v19.8.0) +### Added +* [STREAM-1661](https://inindca.atlassian.net/browse/STREAM-1661) - Expose current alerting leader status rather than exposing a snapshot of the value. The previous property is now deprecated. # [v19.7.1](https://github.com/purecloudlabs/genesys-cloud-streaming-client/compare/v19.7.0...v19.7.1) ### Changed diff --git a/package-lock.json b/package-lock.json index 52da78b7..73f3ad7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "genesys-cloud-streaming-client", - "version": "19.7.1", + "version": "19.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "genesys-cloud-streaming-client", - "version": "19.7.1", + "version": "19.8.0", "license": "MIT", "dependencies": { "@babel/runtime-corejs3": "^7.10.4", diff --git a/package.json b/package.json index 08d5098c..d9671ae4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "genesys-cloud-streaming-client", - "version": "19.7.1", + "version": "19.8.0", "description": "client for the Genesys Cloud Streaming APIs (websocket/xmpp interface)", "repository": "https:github.com/purecloudlabs/genesys-cloud-streaming-client", "license": "MIT", diff --git a/src/alerting-leader.ts b/src/alerting-leader.ts index 17adada5..1b587fa9 100644 --- a/src/alerting-leader.ts +++ b/src/alerting-leader.ts @@ -155,6 +155,7 @@ export class AlertingLeaderExtension extends EventEmitter implements StreamingCl on: this.on.bind(this), off: this.off.bind(this), claimAlertingLeader: this.claimAlertingLeader.bind(this), + getLeaderStatus: () => { return this.leaderStatus; }, leaderStatus: this.leaderStatus }; } @@ -164,5 +165,8 @@ export interface AlertingLeaderApi { on: (event: string, handler: (...args: any) => void) => void; off: (event: string, handler: (...args: any) => void) => void; claimAlertingLeader (): Promise; + getLeaderStatus (): ILeaderStatus; + + /* @deprecated Use {@link getLeaderStatus} */ leaderStatus: ILeaderStatus; } diff --git a/test/unit/alerting-leader.test.ts b/test/unit/alerting-leader.test.ts index c59c06c4..e1dbeb51 100644 --- a/test/unit/alerting-leader.test.ts +++ b/test/unit/alerting-leader.test.ts @@ -102,10 +102,11 @@ describe('AlertingLeader', () => { const clientOptions = { alertableInteractionTypes: [ AlertableInteractionTypes.voice ] }; const fakeClient = new FakeClient({ apiHost: 'example.com' }) as unknown as Client; const alertingLeader = new AlertingLeaderExtension(fakeClient, clientOptions as IClientOptions); + const alertingLeaderExposedApi = alertingLeader.expose; const expectedPayload = { voice: { alerting: true, configured: false } }; expect.assertions(4); - alertingLeader.expose.on('alertingLeaderChanged', (event) => { + alertingLeaderExposedApi.on('alertingLeaderChanged', (event) => { expect(event).toMatchObject(expectedPayload); }); @@ -124,7 +125,7 @@ describe('AlertingLeader', () => { alertingLeader['getAlertingLeader'] = jest.fn().mockRejectedValue({}); await alertingLeader['setupAlertingLeader'](); - expect(alertingLeader.expose.leaderStatus).toMatchObject(expectedPayload); + expect(alertingLeaderExposedApi.getLeaderStatus()).toMatchObject(expectedPayload); }); it('should not set up alerting leader if not configured', async () => { @@ -165,6 +166,7 @@ describe('AlertingLeader', () => { fakeClient.config.userId = userId; const alertingLeader = new AlertingLeaderExtension(fakeClient, {} as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; fakeClient._notifications._subscribeInternal = jest.fn().mockResolvedValue({}); const hawkPayload = { eventBody: { @@ -175,14 +177,14 @@ describe('AlertingLeader', () => { const expectedEventPayload = { voice: { alerting: true, configured: true } }; expect.assertions(2); - alertingLeader.expose.on('alertingLeaderChanged', (event) => { + alertingLeaderExposedApi.on('alertingLeaderChanged', (event) => { expect(event).toMatchObject(expectedEventPayload); }); await alertingLeader['subscribeToAlertingLeader'](); fakeClient.emit(`notify:v2.users.${userId}.alertingleader`, hawkPayload); - expect(alertingLeader.expose.leaderStatus).toStrictEqual(expectedEventPayload); + expect(alertingLeaderExposedApi.getLeaderStatus()).toStrictEqual(expectedEventPayload); }); it('should include the clientType if present', async () => { @@ -193,6 +195,7 @@ describe('AlertingLeader', () => { fakeClient.config.userId = userId; const alertingLeader = new AlertingLeaderExtension(fakeClient, {} as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; fakeClient._notifications._subscribeInternal = jest.fn().mockResolvedValue({}); const hawkPayload = { eventBody: { @@ -204,14 +207,14 @@ describe('AlertingLeader', () => { const expectedEventPayload = { voice: { alerting: true, configured: true, clientType } }; expect.assertions(2); - alertingLeader.expose.on('alertingLeaderChanged', (event) => { + alertingLeaderExposedApi.on('alertingLeaderChanged', (event) => { expect(event).toMatchObject(expectedEventPayload); }); await alertingLeader['subscribeToAlertingLeader'](); fakeClient.emit(`notify:v2.users.${userId}.alertingleader`, hawkPayload); - expect(alertingLeader.expose.leaderStatus).toStrictEqual(expectedEventPayload); + expect(alertingLeaderExposedApi.getLeaderStatus()).toStrictEqual(expectedEventPayload); }); it('should not emit its own event if there is no eventBody', async () => { @@ -221,12 +224,13 @@ describe('AlertingLeader', () => { fakeClient.config.userId = userId; const alertingLeader = new AlertingLeaderExtension(fakeClient, {} as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; fakeClient._notifications._subscribeInternal = jest.fn().mockResolvedValue({}); const hawkPayload = {}; expect.assertions(1); const eventSpy = jest.fn(); - alertingLeader.expose.on('alertingLeaderChanged', eventSpy); + alertingLeaderExposedApi.on('alertingLeaderChanged', eventSpy); await alertingLeader['subscribeToAlertingLeader'](); fakeClient.emit(`notify:v2.users.${userId}.alertingleader`, hawkPayload); @@ -241,6 +245,7 @@ describe('AlertingLeader', () => { fakeClient.config.userId = userId; const alertingLeader = new AlertingLeaderExtension(fakeClient, {} as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; fakeClient._notifications._subscribeInternal = jest.fn().mockResolvedValue({}); const hawkPayload = { eventBody: { @@ -254,7 +259,7 @@ describe('AlertingLeader', () => { const axiosMock = new AxiosMockAdapter(axios); axiosMock.onGet(alertingLeaderUrl).reply(200, { connectionId }); const eventSpy = jest.fn(); - alertingLeader.expose.on('alertingLeaderChanged', eventSpy); + alertingLeaderExposedApi.on('alertingLeaderChanged', eventSpy); await alertingLeader['subscribeToAlertingLeader'](); const getLeaderPromise = alertingLeader['getAlertingLeader'](); @@ -355,15 +360,16 @@ describe('AlertingLeader', () => { const clientOptions = { alertableInteractionTypes: [ AlertableInteractionTypes.voice ] }; const alertingLeader = new AlertingLeaderExtension(fakeClient, clientOptions as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; const expectedPayload = { voice: { alerting: true, configured: true, clientType } }; expect.assertions(2); - alertingLeader.expose.on('alertingLeaderChanged', (event) => { + alertingLeaderExposedApi.on('alertingLeaderChanged', (event) => { expect(event).toStrictEqual(expectedPayload); }); await alertingLeader['getAlertingLeader'](); - expect(alertingLeader.expose.leaderStatus).toMatchObject(expectedPayload); + expect(alertingLeaderExposedApi.getLeaderStatus()).toMatchObject(expectedPayload); axiosMock.restore(); }); @@ -376,15 +382,16 @@ describe('AlertingLeader', () => { const clientOptions = { alertableInteractionTypes: [ AlertableInteractionTypes.voice ] }; const alertingLeader = new AlertingLeaderExtension(fakeClient, clientOptions as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; const expectedPayload = { voice: { alerting: false, configured: true } }; expect.assertions(2); - alertingLeader.expose.on('alertingLeaderChanged', (event) => { + alertingLeaderExposedApi.on('alertingLeaderChanged', (event) => { expect(event).toStrictEqual(expectedPayload); }); await alertingLeader['getAlertingLeader'](); - expect(alertingLeader.expose.leaderStatus).toMatchObject(expectedPayload); + expect(alertingLeaderExposedApi.getLeaderStatus()).toMatchObject(expectedPayload); axiosMock.restore(); }); @@ -421,8 +428,9 @@ describe('AlertingLeader', () => { const clientOptions = { alertableInteractionTypes: [ AlertableInteractionTypes.voice ] }; const alertingLeader = new AlertingLeaderExtension(fakeClient, clientOptions as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; - alertingLeader.expose.claimAlertingLeader(); + alertingLeaderExposedApi.claimAlertingLeader(); expect(httpSpy.mock.calls[0][0]).toBe(alertingLeaderPath); expect(httpSpy.mock.calls[0][1]).toMatchObject({ data: { connectionId: connectionId } }); @@ -437,9 +445,10 @@ describe('AlertingLeader', () => { fakeClient.http.requestApi = httpSpy; const alertingLeader = new AlertingLeaderExtension(fakeClient, {} as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; try { - await alertingLeader.expose.claimAlertingLeader(); + await alertingLeaderExposedApi.claimAlertingLeader(); } catch (err) { expect(err).toBeInstanceOf(StreamingClientError); expect((err as any)['type']).toBe(StreamingClientErrorTypes.generic); @@ -459,9 +468,10 @@ describe('AlertingLeader', () => { const clientOptions = { alertableInteractionTypes: [ AlertableInteractionTypes.voice ] }; const alertingLeader = new AlertingLeaderExtension(fakeClient, clientOptions as IClientOptions); alertingLeader['connectionId'] = connectionId; + const alertingLeaderExposedApi = alertingLeader.expose; try { - await alertingLeader.expose.claimAlertingLeader(); + await alertingLeaderExposedApi.claimAlertingLeader(); } catch (err) { expect(err).toBeInstanceOf(StreamingClientError); expect((err as any)['type']).toBe(StreamingClientErrorTypes.generic);