-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from Eswar2103/FIRECERT-2243
Implementation of Interaction log service feature
- Loading branch information
Showing
8 changed files
with
167 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2021 Comcast Cable Communications Management, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// InteractionLogs | ||
|
||
import { logger } from './logger.mjs'; | ||
|
||
/** | ||
* @function: createAndSendInteractionLog | ||
* @Description: Create interaction log and send it to the client | ||
* @param {String} response - Response of the method call | ||
* @param {String} method - Name of the method | ||
* @param {String} params - Params of the method call | ||
* @param {Object} ws - WS object to send the interaction log | ||
* @param {String} ws - UserId value | ||
*/ | ||
function createAndSendInteractionLog(response, method, params, ws, userId) { | ||
try { | ||
const interactionLog = { | ||
app_id: "mock-firebolt", | ||
method: "", | ||
params: "", | ||
success: true, | ||
response: "", | ||
}; | ||
|
||
interactionLog.params = params; | ||
interactionLog.method = method; | ||
interactionLog.response = response; | ||
if (ws) { | ||
ws.send(JSON.stringify({ FireboltInteraction: interactionLog })); | ||
logger.debug( | ||
`Sent interaction log for user ${userId}: ${JSON.stringify({ | ||
FireboltInteraction: interactionLog, | ||
})}` | ||
); | ||
} else { | ||
logger.error( | ||
`Error in createAndSendInteractionLog: ws object is not provided` | ||
); | ||
} | ||
} catch (error) { | ||
logger.error(`Error in createAndSendInteractionLog: ${error}`); | ||
} | ||
} | ||
|
||
// ----exports---- | ||
|
||
export { createAndSendInteractionLog }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,6 @@ function getUsers(req, res) { | |
}); | ||
} | ||
|
||
|
||
// --- Exports --- | ||
|
||
export { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2021 Comcast Cable Communications Management, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// InteractionLogs: Tests | ||
|
||
import {jest} from '@jest/globals'; | ||
import { createAndSendInteractionLog } from "../../src/interactionLog.mjs"; | ||
import { logger } from "../../src/logger.mjs"; | ||
|
||
test(`interactionLogs.createAndSendInteractionLog works properly`, () => { | ||
const debugSpy = jest.spyOn(logger, "debug"); | ||
createAndSendInteractionLog('{name: "id"}', "account.id", {}, {send: () => {}}, '12345' ); | ||
expect(debugSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
test(`interactionLogs.createAndSendInteractionLog works properly without ws object`, () => { | ||
const errorSpy = jest.spyOn(logger, "error"); | ||
createAndSendInteractionLog('{name: "id"}', "account.id", {}, undefined ); | ||
expect(errorSpy).toHaveBeenCalled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters