Skip to content

Commit

Permalink
Remove 'exclude' property check reliance on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
howard-e committed Dec 14, 2023
1 parent c7d57fa commit 5c4ec6a
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 63 deletions.
7 changes: 3 additions & 4 deletions client/components/Reports/getMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const StyledNone = styled.span`
const none = <StyledNone>None</StyledNone>;

const sum = arr => arr?.reduce((total, item) => total + item, 0) || 0;
const validAssertionResults = a => !a.exclude;

const countTests = ({
testPlanReport, // Choose one to provide
Expand All @@ -19,9 +18,9 @@ const countTests = ({
}) => {
const countScenarioResult = scenarioResult => {
return (
scenarioResult?.assertionResults
?.filter(validAssertionResults)
.every(assertionResult => assertionResult.passed) || 0
scenarioResult?.assertionResults?.every(
assertionResult => assertionResult.passed
) || 0
);
};

Expand Down
20 changes: 14 additions & 6 deletions client/components/TestRenderer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const TestRenderer = ({
}

for (let i = 0; i < scenarioResults.length; i++) {
const {
let {
output,
assertionResults,
unexpectedBehaviors,
Expand All @@ -258,15 +258,23 @@ const TestRenderer = ({
if (output) commands[i].atOutput.value = output;
commands[i].atOutput.highlightRequired = highlightRequired;

// Required because assertionResults can now be returned without an id if there is a 0-priority exception
// applied
assertionResults = assertionResults.filter(el => !!el.id);

for (let j = 0; j < assertionResults.length; j++) {
const assertionResult = assertionResults[j];
const { highlightRequired } = assertionResult;
const { passed, highlightRequired, assertion } =
assertionResults[j];

commands[i].assertions[j].result = assertionResult.passed
let assertionForCommandIndex = commands[i].assertions.findIndex(
({ description }) => description === assertion?.text
);
commands[i].assertions[assertionForCommandIndex].result = passed
? 'pass'
: 'fail';

commands[i].assertions[j].highlightRequired = highlightRequired;
commands[i].assertions[
assertionForCommandIndex
].highlightRequired = highlightRequired;
}

if (unexpectedBehaviors && unexpectedBehaviors.length) {
Expand Down
19 changes: 13 additions & 6 deletions client/components/TestRun/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,12 @@ const TestRun = () => {

// process assertion results
for (let j = 0; j < assertions.length; j++) {
const { result, highlightRequired } = assertions[j];
const { description, result, highlightRequired } =
assertions[j];
const assertionResult = {
...scenarioResult.assertionResults[j],
...scenarioResult.assertionResults.find(
({ assertion: { text } }) => text === description
),
passed: result === 'pass'
};
assertionResults.push(
Expand Down Expand Up @@ -638,10 +641,14 @@ const TestRun = () => {
id,
output: output,
unexpectedBehaviors: unexpectedBehaviors,
assertionResults: assertionResults.map(({ id, passed }) => ({
id,
passed
}))
assertionResults: assertionResults
// All assertions are always being passed from the TestRenderer results, but in the instance where
// there is a 0-priority exception, and id won't be provided and that cannot be saved
.filter(el => !!el.id)
.map(({ id, passed }) => ({
id,
passed
}))
})
);

Expand Down
6 changes: 2 additions & 4 deletions client/components/common/TestPlanResultsTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ const TestPlanResultsTable = ({
{optionalHeader}
{testResult.scenarioResults.map((scenarioResult, index) => {
const passedAssertions = scenarioResult.assertionResults.filter(
assertionResult =>
assertionResult.passed && !assertionResult.exclude
assertionResult => assertionResult.passed
);
const failedAssertions = scenarioResult.assertionResults.filter(
assertionResult =>
!assertionResult.passed && !assertionResult.exclude
assertionResult => !assertionResult.passed
);

// Rows are sorted by priority descending, then result (failures then passes), then
Expand Down
8 changes: 2 additions & 6 deletions client/components/common/TestPlanResultsTable/utils.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
export const calculateAssertionsCount = testResult => {
const passedAssertionsCount = testResult.scenarioResults.reduce(
(acc, scenarioResult) =>
acc +
scenarioResult.assertionResults.filter(e => e.passed && !e.exclude)
.length,
acc + scenarioResult.assertionResults.filter(e => e.passed).length,
0
);

const failedAssertionsCount = testResult.scenarioResults.reduce(
(acc, scenarioResult) =>
acc +
scenarioResult.assertionResults.filter(e => !e.passed && !e.exclude)
.length,
acc + scenarioResult.assertionResults.filter(e => !e.passed).length,
0
);

Expand Down
1 change: 0 additions & 1 deletion client/components/common/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export const ASSERTION_RESULT_FIELDS = gql`
text
}
passed
exclude
}
`;

Expand Down
5 changes: 0 additions & 5 deletions server/graphql-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,6 @@ const graphqlSchema = gql`
results require this field to be filled in.
"""
passed: Boolean
"""
Indicates if this assertion result needs to be ignored because it is included with
a 0-level priority
"""
exclude: Boolean
# TODO: propose removing this for the reason given above
"""
NOTE: This has been deprecated, legacy use = when passed is false, a failedReason must be given.
Expand Down
36 changes: 20 additions & 16 deletions server/resolvers/TestPlanRunOperations/createTestResultSkeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ const createTestResultSkeleton = ({
id: scenarioResultId,
scenarioId: scenario.id,
output: null,
assertionResults: test.assertions.map(assertion => ({
id: createAssertionResultId(
scenarioResultId,
assertion.id
),
assertionId: assertion.id,
passed: null,
exclude: assertion.assertionExceptions?.some(
e =>
scenario.commands.find(
c =>
c.id === e.commandId &&
c.settings === e.settings
) && e.priority === 'EXCLUDE'
)
})),
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.settings === e.settings
) && e.priority === 'EXCLUDE'
);
})
.map(assertion => ({
id: createAssertionResultId(
scenarioResultId,
assertion.id
),
assertionId: assertion.id,
passed: null
})),
unexpectedBehaviors: null
};
})
Expand Down
2 changes: 1 addition & 1 deletion server/resolvers/helpers/convertAssertionPriority.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const convertAssertionPriority = priority => {
if (priority === 'REQUIRED') return 'MUST';
if (priority === 'OPTIONAL') return 'SHOULD';
return priority; // MAY or EXCLUDE
return priority;
};

module.exports = convertAssertionPriority;
4 changes: 1 addition & 3 deletions server/tests/integration/graphql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ describe('graphql', () => {
['TestPlanVersion', 'recommendedPhaseTargetDate'],
['TestPlanVersion', 'deprecatedAt'],
['Test', 'viewers'],
['Command', 'settings'], // TODO: Uncomment when v2 test format CI tests are done
['AssertionResult', 'exclude'] // TODO: Uncomment when v2 test format CI tests are done
['Command', 'settings'] // TODO: Uncomment when v2 test format CI tests are done
];
({
typeAwareQuery,
Expand Down Expand Up @@ -414,7 +413,6 @@ describe('graphql', () => {
id
}
passed
exclude
}
unexpectedBehaviors {
__typename
Expand Down
19 changes: 8 additions & 11 deletions server/util/getMetrics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const convertAssertionPriority = require('../resolvers/helpers/convertAssertionPriority');

const sum = arr => arr.reduce((total, item) => total + item, 0);
const validAssertionResults = a => !a.exclude;

const countTests = ({
testPlanReport, // Choose one to provide
Expand All @@ -10,9 +9,9 @@ const countTests = ({
passedOnly
}) => {
const countScenarioResult = scenarioResult => {
return scenarioResult.assertionResults
.filter(validAssertionResults)
.every(assertionResult => assertionResult.passed);
return scenarioResult.assertionResults.every(
assertionResult => assertionResult.passed
);
};

const countTestResult = testResult => {
Expand All @@ -39,13 +38,11 @@ const countAssertions = ({
passedOnly
}) => {
const countScenarioResult = scenarioResult => {
const all = scenarioResult.assertionResults
.filter(validAssertionResults)
.filter(
a =>
convertAssertionPriority(a.assertion.priority) ===
convertAssertionPriority(priority)
);
const all = scenarioResult.assertionResults.filter(
a =>
convertAssertionPriority(a.assertion.priority) ===
convertAssertionPriority(priority)
);
if (passedOnly) return all.filter(each => each.passed).length;
return all.length;
};
Expand Down

0 comments on commit 5c4ec6a

Please sign in to comment.