Skip to content

Commit

Permalink
Break out in-line filter into function sufficiently support readabili…
Browse files Browse the repository at this point in the history
…ty purposes
  • Loading branch information
howard-e committed Feb 6, 2024
1 parent 942223d commit bba8ad4
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions server/resolvers/TestPlanRunOperations/createTestResultSkeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ const {
createAssertionResultId
} = require('../../services/PopulatedData/locationOfDataId');

/**
* Determine whether a given assertion belongs to a given scenario and includes
* at least one exception with a given priority.
*
* @param {Assertion} assertion
* @param {Scenario} scenario
* @param {string} priority
*/
const hasExceptionWithPriority = (assertion, scenario, priority) => {
return assertion.assertionExceptions?.some(
exception =>
scenario.commands.find(
command =>
command.id === exception.commandId &&
command.atOperatingMode === exception.settings
) && exception.priority === priority
);
};

const createTestResultSkeleton = ({
test,
testPlanRun,
Expand Down Expand Up @@ -31,17 +50,16 @@ const createTestResultSkeleton = ({
scenarioId: scenario.id,
output: null,
assertionResults: test.assertions
// Filter out assertionResults which were marked with a 0-priority exception
.filter(assertion => {
return !assertion.assertionExceptions?.some(
e =>
scenario.commands.find(
c =>
c.id === e.commandId &&
c.atOperatingMode === e.settings
) && e.priority === 'EXCLUDE'
);
})
// Filter out assertionResults for the current scenario which were marked
// with a 0-priority exception
.filter(
assertion =>
!hasExceptionWithPriority(
assertion,
scenario,
'EXCLUDE'
)
)
.map(assertion => ({
id: createAssertionResultId(
scenarioResultId,
Expand Down

0 comments on commit bba8ad4

Please sign in to comment.