Skip to content

Commit

Permalink
feat: Player interaction logs validation (#216)
Browse files Browse the repository at this point in the history
Co-authored-by: Nandana-NNR <[email protected]>
  • Loading branch information
Eswar2103 and Nandana-NNR authored Oct 14, 2024
1 parent 48a6684 commit 3366e97
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 33 deletions.
11 changes: 8 additions & 3 deletions Docs/Interaction_Logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ Interactions logs will be stored in `fbInteractionLogs` env variable as an array

### Custom validation support
To do validation for interaction logs, custom function function should be added in config module.
User can add `validateFireboltInteractionLogs` function inside `configModule/cypress/fixtures/customValidations/` to do validation of the interaction logs.

User can add `validateInteractionLogs` function inside `configModule/cypress/fixtures/customValidations/` to do validation of the interaction logs.

Refer to [this](/cypress/support/step_definitions/validations.md#custom) to add the custom validation object.

### Execution - How to execute
* Pass `interactionsMetrics= true` from the cli command to start the service
```
Expand All @@ -44,4 +46,7 @@ npx cypress open --browser electron -- env interactionsMetrics=true
},
}
}
```
```

### Note:
Interaction Logs will be cleared after the each scenario execution is done, so any kind of validations should be added in that scenario only.
2 changes: 2 additions & 0 deletions cypress/support/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ module.exports = {
'`Unable to find the ${envAppIdKey} value in the env, please add the value in configModule/constants/config.json`',
SET_EVENT_REQUEST: 'Request sent to set event values in platform: ',
SET_EVENT_SUCCESS: 'Event value set successfully in platform',
SCENARIO_NAME: 'scenarioName',
FIREBOLT_INTERACTION: 'FireboltInteraction',
};
function getSanityReportPath() {
// Check if Cypress is defined, for cypress test context
Expand Down
17 changes: 1 addition & 16 deletions cypress/support/cypress-commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ Cypress.Commands.add('getBeforeOperationObject', () => {
if (scenarioName.includes('(example')) {
scenarioName = scenarioName.split('(example')[0].trim();
}
Cypress.env(CONSTANTS.SCENARIO_NAME, scenarioName);
// Fetching current feature name
const moduleReqIdJson = Cypress.env(CONSTANTS.MODULEREQIDJSON);
const scenarioList = moduleReqIdJson.scenarioNames[featureFileName];
Expand Down Expand Up @@ -1506,19 +1507,3 @@ Cypress.Commands.add('startOrStopInteractionsService', (action) => {
}
});
});

/**
* @module commands
* @function validateFireboltInteractionLogs
* @description Command to validate the firebolt interaction logs in configModule
* @example
* cy.validateFireboltInteractionLogs()
* cy.validateFireboltInteractionLogs()
*/
Cypress.Commands.add('validateFireboltInteractionLogs', () => {
const validationObject = {
assertionDef: 'validateFireboltInteractionLogs',
};
const interactionLogs = UTILS.getEnvVariable(CONSTANTS.FB_INTERACTIONLOGS).getLogs();
cy.customValidation(validationObject, interactionLogs);
});
1 change: 1 addition & 0 deletions cypress/support/cypress-support/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export default function (module) {

// beforeEach
beforeEach(() => {
UTILS.getEnvVariable(CONSTANTS.FB_INTERACTIONLOGS).clearLogs();
cy.getBeforeOperationObject();
UTILS.destroyGlobalObjects([CONSTANTS.LIFECYCLE_APP_OBJECT_LIST]);
});
Expand Down
17 changes: 13 additions & 4 deletions cypress/support/cypress-support/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1127,18 +1127,27 @@ function fetchAppIdentifierFromEnv(appId) {
*/
class InteractionsLogs {
constructor() {
this.logs = [];
this.logs = new Map();
}

addLog(message) {
this.logs.push(message);
const scenarioName = Cypress.env(CONSTANTS.SCENARIO_NAME);
if (this.logs.size > 0 && this.logs.has(scenarioName)) {
this.logs.get(scenarioName).push(message);
} else {
this.logs.set(scenarioName, [message]);
}
}

getLogs() {
getLogs(scenarioName) {
if (scenarioName) {
return this.logs.get(scenarioName);
}
return this.logs;
}

clearLogs() {
this.logs = [];
this.logs.clear();
}
}
const interactionLogs = new InteractionsLogs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export default class Websocket extends AsyncTransportClient {
const mapKey = Array.from(Cypress.env('eventResponseMap').keys()).find((key) =>
key.includes(message.id)
);
const interactionKey = message.hasOwnProperty('FireboltInteraction');

if (interactionKey) {
Cypress.env('fbInteractionLogs').addLog(message.FireboltInteraction);
}

// Updating event response in the map when event is triggered by the platform
if (
Expand Down
36 changes: 29 additions & 7 deletions cypress/support/step_definitions/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Given(/Interactions collection process is (initiated|stopped)/, (action) => {
action == CONSTANTS.INITIATED
? CONSTANTS.FAILED_TO_INITIATE_INTERACTIONS_SERVICE
: CONSTANTS.FAILED_TO_STOP_INTERACTIONS_SERVICE;
fireLog.assert(false, message);
UTILS.fireLog.assert(false, message);
}
});
} else {
Expand All @@ -354,12 +354,34 @@ Given(/Interactions collection process is (initiated|stopped)/, (action) => {

/**
* @module validations
* @function Given Validate Firebolt Interactions logs
* @description Validating the firebolt interaction logs in configModule
* @function verify Firebolt Interactions for '(.+)'
* @description Validating the firebolt interaction logs
* @param {String} key - Validation object key name
* @example
* Given Validate Firebolt Interactions logs
* verify Firebolt Interactions for 'account id method'
*/
Given(/Validate Firebolt Interactions logs/, () => {
cy.then(() => cy.validateFireboltInteractionLogs());
Given(/verify Firebolt Interactions for '(.+)'/, (key) => {
if (
(!UTILS.getEnvVariable(CONSTANTS.IS_INTERACTIONS_SERVICE_ENABLED, false) ||
UTILS.getEnvVariable(CONSTANTS.IS_INTERACTIONS_SERVICE_ENABLED, false) === false) &&
(!UTILS.getEnvVariable(CONSTANTS.FB_INTERACTIONLOGS).size ||
UTILS.getEnvVariable(CONSTANTS.FB_INTERACTIONLOGS).size === 0)
) {
cy.log(`Interactions log service is not enabled`);
} else {
key = key.replaceAll(' ', '_').toUpperCase();
cy.getFireboltData(key).then((fireboltData) => {
const logs = UTILS.getEnvVariable(CONSTANTS.FB_INTERACTIONLOGS).getLogs(
Cypress.env(CONSTANTS.SCENARIO_NAME)
);
if (!logs) {
UTILS.fireLog.assert(
false,
`No interaction logs found for the scenario - ${Cypress.env(CONSTANTS.SCENARIO_NAME)}`
);
}
const contentObject = { logs: logs, content: fireboltData.content.data[0].validations };
cy.customValidation(fireboltData.content.data[0], contentObject);
});
}
});
11 changes: 8 additions & 3 deletions cypress/support/step_definitions/validations.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ For the validation part, for the states when the app is not reachable for us to
* `Given Interactions collection process is 'initiated'`
* `Given Interactions collection process is 'stopped'`

## Validate Firebolt Interactions logs
### Purpose: Validating the firebolt interaction logs in configModule
## verify Firebolt Interactions for '(.+)'
### Purpose: Validating the firebolt interaction logs

### Params:
| Param | Definition |
| --- | --- |
| key | validation object key name |

### Examples:
* `Given Validate Firebolt Interactions logs`
* `verify Firebolt Interactions for 'account id method'`

0 comments on commit 3366e97

Please sign in to comment.