Skip to content

Commit 8169d43

Browse files
Paul-Cluehoward-e
andauthored
Tests which have been re-ran to update results to avoid conflicts between testers still incorrectly display conflicting results (#685)
* Work on fixes * Fix re-ran tests conflicts * Fix re-ran tests conflicts * Change loop conditional * Revise updateTestPlanRun blocks * Fix destructure error * Add context object as param * Make suggested changes from code review * Add curly braces to if-block --------- Co-authored-by: Howard Edwards <[email protected]>
1 parent 382795e commit 8169d43

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
'use strict';
2+
const populateData = require('../services/PopulatedData/populateData');
3+
const { updateTestPlanRun } = require('../models/services/TestPlanRunService');
4+
const {
5+
updateTestPlanReport
6+
} = require('../models/services/TestPlanReportService');
7+
const conflictsResolver = require('../resolvers/TestPlanReport/conflictsResolver');
8+
const BrowserLoader = require('../models/loaders/BrowserLoader');
9+
const AtLoader = require('../models/loaders/AtLoader');
10+
11+
module.exports = {
12+
up: queryInterface => {
13+
return queryInterface.sequelize.transaction(async transaction => {
14+
const testPlanRunQuery = await queryInterface.sequelize.query(
15+
`SELECT id, "testResults" FROM "TestPlanRun"`,
16+
{
17+
transaction
18+
}
19+
);
20+
21+
const testPlanReportQuery = await queryInterface.sequelize.query(
22+
`SELECT id, status FROM "TestPlanReport"`,
23+
{
24+
transaction
25+
}
26+
);
27+
28+
const atLoader = AtLoader();
29+
const browserLoader = BrowserLoader();
30+
const testPlanRunData = testPlanRunQuery[0];
31+
const testPlanReportsData = testPlanReportQuery[0];
32+
if (!testPlanRunData) {
33+
// eslint-disable-next-line no-console
34+
console.info('The test Results are empty');
35+
return;
36+
}
37+
38+
for (let i = 0; i < testPlanRunData.length; i += 1) {
39+
const testPlanRun = testPlanRunData[i];
40+
const testPlanRunId = testPlanRun.id;
41+
let needsUpdate = false;
42+
43+
let updateParams = {
44+
testResults: testPlanRun.testResults
45+
};
46+
47+
if (!testPlanRunData[i].testResults) {
48+
continue;
49+
}
50+
if (
51+
Array.isArray(testPlanRunData[i].testResults) &&
52+
testPlanRunData[i].testResults.length < 1
53+
) {
54+
continue;
55+
}
56+
57+
for (
58+
let j = 0;
59+
j < testPlanRunData[i].testResults.length;
60+
j += 1
61+
) {
62+
if (!testPlanRunData[i].testResults[j].scenarioResults) {
63+
continue;
64+
}
65+
if (
66+
Array.isArray(
67+
testPlanRunData[i].testResults[j].scenarioResults
68+
) &&
69+
testPlanRunData[i].testResults[j].scenarioResults
70+
.length < 1
71+
) {
72+
continue;
73+
}
74+
for (
75+
let p = 0;
76+
p <
77+
testPlanRunData[i].testResults[j].scenarioResults
78+
.length;
79+
p += 1
80+
) {
81+
if (
82+
!testPlanRunData[i].testResults[j].scenarioResults[
83+
p
84+
].unexpectedBehaviors
85+
) {
86+
continue;
87+
}
88+
89+
if (
90+
Array.isArray(
91+
testPlanRunData[i].testResults[j]
92+
.scenarioResults[p].unexpectedBehaviors
93+
) &&
94+
testPlanRunData[i].testResults[j].scenarioResults[p]
95+
.unexpectedBehaviors.length < 1
96+
) {
97+
continue;
98+
}
99+
for (
100+
let s = 0;
101+
s <
102+
testPlanRunData[i].testResults[j].scenarioResults[p]
103+
.unexpectedBehaviors.length;
104+
s += 1
105+
) {
106+
const unexpectedBehavior =
107+
testPlanRunData[i].testResults[j]
108+
.scenarioResults[p].unexpectedBehaviors[s];
109+
if (
110+
unexpectedBehavior.id !== 'OTHER' &&
111+
unexpectedBehavior.otherUnexpectedBehaviorText ===
112+
null
113+
) {
114+
delete unexpectedBehavior.otherUnexpectedBehaviorText;
115+
116+
updateParams.testResults[j] =
117+
testPlanRunData[i].testResults[j];
118+
119+
needsUpdate = true;
120+
}
121+
}
122+
}
123+
}
124+
125+
if (needsUpdate) {
126+
// eslint-disable-next-line no-console
127+
console.info(
128+
`=== Fixing unexpectedBehavior results for TestPlanRun:${testPlanRunId} ===`
129+
);
130+
await updateTestPlanRun(testPlanRunId, updateParams);
131+
}
132+
}
133+
134+
for (let i = 0; i < testPlanReportsData.length; i++) {
135+
const testPlanReportId = testPlanReportsData[i].id;
136+
const status = testPlanReportsData[i].status;
137+
if (status === 'DRAFT') {
138+
let updateParams = {};
139+
const { testPlanReport } = await populateData(
140+
{
141+
testPlanReportId
142+
},
143+
{}
144+
);
145+
146+
const conflicts = await conflictsResolver(
147+
testPlanReport,
148+
null,
149+
{ atLoader, browserLoader }
150+
);
151+
152+
updateParams = {
153+
metrics: {
154+
conflictsCount: conflicts.length
155+
}
156+
};
157+
158+
await updateTestPlanReport(testPlanReport.id, updateParams);
159+
}
160+
}
161+
});
162+
}
163+
};

server/resolvers/TestResultOperations/saveTestResultCommon.js

+14
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ const saveTestResultCommon = async ({
4545
removeArrayItems: true
4646
});
4747

48+
// Some clients might send an otherUnexpectedBehaviorText for unexpectedBehaviors
49+
// that are not "OTHER". As long as the otherUnexpectedBehaviorText is null or undefined,
50+
// the best course of action is probably to allow it, but not save it to the database.
51+
newTestResult.scenarioResults.forEach(scenarioResult => {
52+
scenarioResult.unexpectedBehaviors.forEach(unexpectedBehavior => {
53+
if (
54+
unexpectedBehavior.id !== 'OTHER' &&
55+
unexpectedBehavior.otherUnexpectedBehaviorText == null
56+
) {
57+
delete unexpectedBehavior.otherUnexpectedBehaviorText;
58+
}
59+
});
60+
});
61+
4862
const isCorrupted = !deepPickEqual(
4963
[
5064
createTestResultSkeleton({ test, testPlanRun, testPlanReport }),

0 commit comments

Comments
 (0)