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

Add resolver for tracking first required AT Version #1051

Merged
merged 8 commits into from
Apr 24, 2024
23 changes: 23 additions & 0 deletions server/graphql-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,29 @@ const graphqlSchema = gql`
False value indicates to return the reports which have no markedFinalAt date.
"""
testPlanReports(isFinal: Boolean): [TestPlanReport]!
"""
For each report under this TestPlanVersion, if the report's combination
is indicated as required and the report is marked as final at the time
the TestPlanVersion is updated to RECOMMENDED then by checking the
testers' runs which have been marked as primary, the earliest found AT
version for the respective ATs should be considered as the
first required AT version or "earliestAtVersion".

The "earliest" is determined by comparing the recorded AtVersions'
releasedAt value.

Required Reports definition and combinations are defined at
https://github.com/w3c/aria-at-app/wiki/Business-Logic-and-Processes#required-reports.

Primary Test Plan Run is defined at
https://github.com/w3c/aria-at-app/wiki/Business-Logic-and-Processes#primary-test-plan-run.

After this TestPlanVersion is updated to RECOMMENDED, this should be
used to ensure subsequent reports created under the TestPlanVersion
should only being capturing results for AT Versions which are the same
as or were released after the "earliestAtVersion".
"""
earliestAtVersion(atId: ID!): AtVersion
}

"""
Expand Down
70 changes: 70 additions & 0 deletions server/resolvers/TestPlanVersion/earliestAtVersionResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const { getAts, getAtVersionById } = require('../../models/services/AtService');
const {
getTestPlanReports
} = require('../../models/services/TestPlanReportService');

const earliestAtVersionResolver = async (
testPlanVersion,
{ atId },
context
) => {
const { transaction } = context;

let reports = [];
if (testPlanVersion.testPlanReports) {
reports = [...testPlanVersion.testPlanReports];
} else {
reports = await getTestPlanReports({
where: { testPlanVersionId: testPlanVersion.id },
transaction
});
}

if (!reports.length || testPlanVersion.phase !== 'RECOMMENDED') {
return null;
}

// To track the required reports for RECOMMENDED phase
const ats = await getAts({ transaction });

let earliestAtVersion = null;
for (const testPlanReport of reports.filter(
testPlanReport => testPlanReport.atId == atId
)) {
const browserId = testPlanReport.browserId;

// Need to check if is required report for a primary test plan run
const isRequiredReport = ats
.find(at => at.id == atId)
.browsers.find(browser => browser.id == browserId)
.AtBrowsers.isRecommended;

if (isRequiredReport) {
const primaryRun =
testPlanReport.testPlanRuns.find(
({ isPrimary }) => isPrimary
) || testPlanReport.testPlanRuns[0];
const primaryRunAtVersionId = primaryRun.testResults[0].atVersionId;
const atVersion = await getAtVersionById({
id: primaryRunAtVersionId,
transaction
});

if (
!earliestAtVersion ||
new Date(atVersion.releasedAt) <
new Date(earliestAtVersion.releasedAt)
) {
earliestAtVersion = {
id: atVersion.id,
name: atVersion.name,
releasedAt: atVersion.releasedAt
};
}
}
}

return earliestAtVersion;
};

module.exports = earliestAtVersionResolver;
4 changes: 3 additions & 1 deletion server/resolvers/TestPlanVersion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ const gitMessage = require('./gitMessageResolver');
const tests = require('./testsResolver');
const testPlanReports = require('./testPlanReportsResolver');
const recommendedPhaseTargetDate = require('./recommendedPhaseTargetDateResolver');
const earliestAtVersion = require('./earliestAtVersionResolver');

const TestPlanVersion = {
testPlan,
gitMessage,
tests,
testPlanReports,
recommendedPhaseTargetDate
recommendedPhaseTargetDate,
earliestAtVersion
};

module.exports = TestPlanVersion;
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const deriveAttributesFromCustomField = (fieldName, customFields) => {
fields.includes('testPlan.directory')
)
derived.push('directory');
if (fields.includes('earliestAtVersion')) derived.push('phase');
break;
}
case 'testPlanReport': {
Expand Down
13 changes: 9 additions & 4 deletions server/tests/integration/graphql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ describe('graphql', () => {
['TestPlanReport', 'issues'],
['TestPlanReport', 'vendorReviewStatus'],
['TestPlanReportOperations', 'updateTestPlanReportTestPlanVersion'],
['TestPlanVersion', 'candidatePhaseReachedAt'],
['TestPlanVersion', 'recommendedPhaseReachedAt'],
['TestPlanVersion', 'recommendedPhaseTargetDate'],
['TestPlanVersion', 'deprecatedAt'],
['Test', 'viewers'],
['Command', 'atOperatingMode'], // TODO: Include when v2 test format CI tests are done
['CollectionJob', 'testPlanRun'],
Expand Down Expand Up @@ -369,6 +365,15 @@ describe('graphql', () => {
directory
}
}
recommendedTestPlanVersion: testPlanVersion(id: 69) {
__typename
id
earliestAtVersion(atId: 1) {
id
name
releasedAt
}
}
conflictTestPlanReport: testPlanReport(id: 2) {
__typename
id
Expand Down
Loading