From 88bc12658464c60a70106f498945a6c3a9023369 Mon Sep 17 00:00:00 2001 From: Severin Gafner Date: Fri, 11 Feb 2022 10:16:58 +0100 Subject: [PATCH] extend the `downloadLogs` vendorConnector function to take the logs as a parameter --- src/main/baseConnector.js | 4 ++-- src/main/types.js | 2 +- src/test/baseConnector.test.js | 13 ++++++++++++- ts-declaration/logger.d.ts | 2 +- ts-declaration/types.d.ts | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/baseConnector.js b/src/main/baseConnector.js index 3124b7b..06295b2 100644 --- a/src/main/baseConnector.js +++ b/src/main/baseConnector.js @@ -12,7 +12,7 @@ import { Validator, GenericResult, InitResult, CallResult, HangupResult, HoldTog ParticipantResult, RecordingToggleResult, AgentConfigResult, ActiveCallsResult, SignedRecordingUrlResult, LogoutResult, VendorConnector, Contact, AudioStats, SuperviseCallResult, SupervisorHangupResult, AgentStatusInfo} from './types'; import { enableMos, getMOS, initAudioStats, updateAudioStats } from './mosUtil'; -import { log } from './logger'; +import { getLogs, log } from './logger'; let channelPort; let vendorConnector; @@ -478,7 +478,7 @@ async function channelMessageHandler(message) { } break; case constants.MESSAGE_TYPE.DOWNLOAD_VENDOR_LOGS: - vendorConnector.downloadLogs(); + vendorConnector.downloadLogs(getLogs()); break; case constants.MESSAGE_TYPE.LOG: { const { logLevel, logMessage, payload } = message.data; diff --git a/src/main/types.js b/src/main/types.js index 8e787c7..088b644 100644 --- a/src/main/types.js +++ b/src/main/types.js @@ -853,7 +853,7 @@ export class VendorConnector { /** * Triggers a browser download for Vendor Logs */ - downloadLogs() { + downloadLogs(logs) { downloadLogs(); } diff --git a/src/test/baseConnector.test.js b/src/test/baseConnector.test.js index 27904c5..6228f76 100644 --- a/src/test/baseConnector.test.js +++ b/src/test/baseConnector.test.js @@ -11,7 +11,7 @@ import { ActiveCallsResult, InitResult, CallResult, HoldToggleResult, GenericRes AgentConfigResult, Phone, HangupResult, SignedRecordingUrlResult, LogoutResult, AudioStats, StatsInfo, AudioStatsElement, SuperviseCallResult, SupervisorHangupResult } from '../main/index'; import baseConstants from '../main/constants'; -import { log } from '../main/logger'; +import { log, getLogs } from '../main/logger'; jest.mock('../main/logger'); const constants = { @@ -1505,6 +1505,17 @@ describe('SCVConnectorBase tests', () => { fireMessage(constants.MESSAGE_TYPE.DOWNLOAD_VENDOR_LOGS); expect(adapter.downloadLogs).toBeCalledTimes(1); }); + it('Should pass the saved logmessages to downloadLogs() when DOWNLOAD_VENDOR_LOGS is published', () => { + getLogs.mockImplementationOnce(() => [ + '"2022-02-10T20:10:30.503Z|INFO|SYSTEM|{"eventType":"SETUP_CONNECTOR","payload":{}' + ] + ); + fireMessage(constants.MESSAGE_TYPE.DOWNLOAD_VENDOR_LOGS); + expect(adapter.downloadLogs).toBeCalledTimes(1); + expect(adapter.downloadLogs).toBeCalledWith([ + '"2022-02-10T20:10:30.503Z|INFO|SYSTEM|{"eventType":"SETUP_CONNECTOR","payload":{}' + ]); + }); }); describe('logMessageToVendor()', () => { diff --git a/ts-declaration/logger.d.ts b/ts-declaration/logger.d.ts index 9f1e1d8..4e0dfdb 100644 --- a/ts-declaration/logger.d.ts +++ b/ts-declaration/logger.d.ts @@ -9,7 +9,7 @@ export function log(logMessage: object, logLevel: string, logSource?: string): v * * @returns a deep copy of the logs array */ -export function getLogs(): any; +export function getLogs(): string[]; /** * Download the logs as a file */ diff --git a/ts-declaration/types.d.ts b/ts-declaration/types.d.ts index 156f352..bdcbb38 100644 --- a/ts-declaration/types.d.ts +++ b/ts-declaration/types.d.ts @@ -707,7 +707,7 @@ export class VendorConnector { /** * Triggers a browser download for Vendor Logs */ - downloadLogs(): void; + downloadLogs(logs: string[]): void; /** * Sends the logs with a logLevel and payload to the vendor connector. * Does a no-op, if not implemented.