Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarks newly copied test plan reports as final during results copy process #974

22 changes: 5 additions & 17 deletions server/resolvers/helpers/processCopiedReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ const getKeptTestResultsByTestId = (testResults, keptTestsByTestHash) => {

/**
* Updates metrics and markedFinalAt status for newly created TestPlanReports after copying process
* @param oldTestPlanReport
* @param newTestPlanReport
* @param testPlanRun
* @param testResults
Expand All @@ -153,7 +152,6 @@ const getKeptTestResultsByTestId = (testResults, keptTestsByTestHash) => {
* @returns {Promise<void>}
*/
const updateMetricsAndMarkedFinalAtForTestPlanReport = async ({
oldTestPlanReport,
newTestPlanReport,
testPlanRun,
testResults,
Expand All @@ -177,13 +175,12 @@ const updateMetricsAndMarkedFinalAtForTestPlanReport = async ({
null,
context
);
let updateParams = {};

// Mark the report as final if previously was for TestPlanVersion being deprecated; may still be
// nullified if finalized test results aren't equal to the amount known number of possible
// runnable tests, because no tests should be skipped. Would mean it CANNOT be final.
if (oldTestPlanReport.markedFinalAt)
updateParams = { markedFinalAt: new Date() };
// Even if oldTestPlanReport.markedFinalAt exists, it should be nullified
// when copied over because it should be on the test admin(s) to ensure
// the copied data isn't incorrect in certain instances or needs to be
// updated before finalizing again
let updateParams = { markedFinalAt: null };

// Calculate the metrics (happens if updating to DRAFT)
const conflicts = await conflictsResolver(
Expand All @@ -197,7 +194,6 @@ const updateMetricsAndMarkedFinalAtForTestPlanReport = async ({
// marked as final yet
updateParams = {
...updateParams,
markedFinalAt: null,
metrics: {
...populatedTestPlanReport.metrics,
conflictsCount: conflicts.length
Expand All @@ -213,7 +209,6 @@ const updateMetricsAndMarkedFinalAtForTestPlanReport = async ({
if (!finalizedTestResults || !finalizedTestResults.length) {
updateParams = {
...updateParams,
markedFinalAt: null,
metrics: {
...populatedTestPlanReport.metrics
}
Expand All @@ -229,12 +224,6 @@ const updateMetricsAndMarkedFinalAtForTestPlanReport = async ({

updateParams = {
...updateParams,
// means test results have now been 'skipped' during the update process so these
// cannot be finalized and must be updated in the test queue
markedFinalAt:
finalizedTestResults.length < runnableTests.length
? null
: updateParams.markedFinalAt,
metrics: {
...populatedTestPlanReport.metrics,
...metrics
Expand Down Expand Up @@ -439,7 +428,6 @@ const processCopiedReports = async ({

// Run updated metrics calculations for new TestPlanRun test results to be used in metrics calculations
await updateMetricsAndMarkedFinalAtForTestPlanReport({
oldTestPlanReport,
newTestPlanReport,
testPlanRun: newTestPlanRun,
testResults: newTestResults,
Expand Down
85 changes: 69 additions & 16 deletions server/tests/integration/dataManagement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,38 +674,64 @@ describe('data management', () => {
});
});

it('updates test plan version but removes marked as final for test plan report when new report has incomplete runs', async () => {
it('updates test plan version over another which had all test plan reports as final but removes final for all newly created test plan reports', async () => {
await dbCleaner(async transaction => {
function markedFinalAtReduce(acc, curr) {
return acc + (curr.markedFinalAt ? 1 : 0);
function markedFinalAtFilter({ markedFinalAt }) {
return !!markedFinalAt;
}

function completedResultsCount(testPlanReports, atId) {
return (
testPlanReports
.find(({ at }) => at.id == atId)
// 0 because only 1 tester for each already marked final
// report matters during this test
.draftTestPlanRuns[0].testResults.filter(
({ completedAt }) => !!completedAt
).length
);
}

const testPlanVersions = await testPlanVersionsQuery({
transaction
});

// Process counts for old test plan version
const [oldCommandButtonVersion] =
testPlanVersions.testPlanVersions.filter(
e =>
e.testPlan.directory === 'command-button' &&
e.phase === 'DRAFT' &&
e.metadata.testFormatVersion === 2
);

const oldCommandButtonVersionMarkedFinalReportsCount =
oldCommandButtonVersion.testPlanReports.reduce(
markedFinalAtReduce,
0
oldCommandButtonVersion.testPlanReports.filter(
markedFinalAtFilter
).length;
const oldCommandButtonJawsCompletedTestResultsCount =
completedResultsCount(
oldCommandButtonVersion.testPlanReports,
1
);
const oldCommandButtonNvdaCompletedTestResultsCount =
completedResultsCount(
oldCommandButtonVersion.testPlanReports,
2
);
const oldCommandButtonSafariCompletedTestResultsCount =
completedResultsCount(
oldCommandButtonVersion.testPlanReports,
3
);

// Process counts for new test plan version
const [newCommandButtonVersion] =
testPlanVersions.testPlanVersions.filter(
e =>
e.testPlan.directory === 'command-button' &&
e.phase === 'RD' &&
e.metadata.testFormatVersion === 2
);

const { testPlanVersion: newCommandButtonVersionInDraft } =
await updateVersionToPhaseQuery(
newCommandButtonVersion.id,
Expand All @@ -717,9 +743,26 @@ describe('data management', () => {
}
);
const newCommandButtonVersionInDraftMarkedFinalReportsCount =
newCommandButtonVersionInDraft.updatePhase.testPlanVersion.testPlanReports.reduce(
markedFinalAtReduce,
0
newCommandButtonVersionInDraft.updatePhase.testPlanVersion.testPlanReports.filter(
markedFinalAtFilter
).length;
const newCommandButtonJawsCompletedTestResultsCount =
completedResultsCount(
newCommandButtonVersionInDraft.updatePhase.testPlanVersion
.testPlanReports,
1
);
const newCommandButtonNvdaCompletedTestResultsCount =
completedResultsCount(
newCommandButtonVersionInDraft.updatePhase.testPlanVersion
.testPlanReports,
2
);
const newCommandButtonSafariCompletedTestResultsCount =
completedResultsCount(
newCommandButtonVersionInDraft.updatePhase.testPlanVersion
.testPlanReports,
3
);

// The difference between them is that there have been updated settings for VoiceOver tests;
Expand All @@ -729,14 +772,24 @@ describe('data management', () => {
// only 'navForwardsToButton' and 'navBackToButton' tests were affected. The individual tests for
// 'reqInfoAboutButton' should still match
//
// This means only 1 test plan report should be affected, for VoiceOver and now unmarked as final.
// The single JAWS and NVDA reports should be unaffected
// This means only 1 test plan report was affected results-wise, for VoiceOver, but they should all still be
// unmarked as final. The single JAWS and NVDA reports should have unaffected results but also unmarked as
// final.
expect(
newCommandButtonVersionInDraftMarkedFinalReportsCount
).toBeGreaterThan(1);
oldCommandButtonVersionMarkedFinalReportsCount
).toBeGreaterThan(0);
expect(
newCommandButtonVersionInDraftMarkedFinalReportsCount
).toEqual(oldCommandButtonVersionMarkedFinalReportsCount - 1);
).toEqual(0);
expect(newCommandButtonJawsCompletedTestResultsCount).toEqual(
oldCommandButtonJawsCompletedTestResultsCount
);
expect(newCommandButtonNvdaCompletedTestResultsCount).toEqual(
oldCommandButtonNvdaCompletedTestResultsCount
);
expect(newCommandButtonSafariCompletedTestResultsCount).toEqual(
oldCommandButtonSafariCompletedTestResultsCount - 2
);
});
});

Expand Down
Loading