Skip to content

Commit 0c188a2

Browse files
committed
Test for CROSS_SCENARIO match
1 parent 71a980b commit 0c188a2

File tree

3 files changed

+148
-18
lines changed

3 files changed

+148
-18
lines changed

server/scripts/populate-test-data/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ const populateTestDatabase = async transaction => {
212212
});
213213

214214
await populateFakeTestResults(26, ['completeAndPassing'], {
215-
transaction
215+
transaction,
216+
varyOutputsPerScenario: true
216217
});
217218

218219
await populateFakeTestResults(27, ['completeAndPassing'], {

server/scripts/populate-test-data/populateFakeTestResults.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const populateFakeTestResults = async (
3636
{
3737
transaction,
3838
atVersionId = null,
39-
numFakeTestResultConflicts = FAKE_RESULT_CONFLICTS_OPTIONS.SINGLE
39+
numFakeTestResultConflicts = FAKE_RESULT_CONFLICTS_OPTIONS.SINGLE,
40+
varyOutputsPerScenario = false
4041
}
4142
) => {
4243
const {
@@ -84,7 +85,8 @@ const populateFakeTestResults = async (
8485
fakeTestResultType: 'passing',
8586
submit: true,
8687
transaction,
87-
atVersionId
88+
atVersionId,
89+
varyOutputsPerScenario
8890
});
8991
break;
9092
case 'completeAndFailingDueToIncorrectAssertions':
@@ -154,7 +156,8 @@ const populateFakeTestResults = async (
154156
fakeTestResultType: 'passing',
155157
submit: false,
156158
transaction,
157-
atVersionId
159+
atVersionId,
160+
varyOutputsPerScenario
158161
});
159162
break;
160163
case 'incompleteAndFailingDueToIncorrectAssertions':
@@ -226,7 +229,8 @@ const populateFakeTestResults = async (
226229
index: i,
227230
fakeTestResultType: 'passing',
228231
submit: true,
229-
transaction
232+
transaction,
233+
varyOutputsPerScenario
230234
});
231235
}
232236
}
@@ -240,7 +244,8 @@ const getFake = async ({
240244
submit,
241245
numFakeTestResultConflicts,
242246
transaction,
243-
atVersionId = null
247+
atVersionId = null,
248+
varyOutputsPerScenario = false
244249
}) => {
245250
const testId = testPlanReport.runnableTests[index].id;
246251

@@ -298,18 +303,22 @@ const getFake = async ({
298303
...baseTestResult,
299304
atVersionId: atVersionId,
300305
browserVersionId: browserVersion.id,
301-
scenarioResults: baseTestResult.scenarioResults.map(scenarioResult => ({
302-
...scenarioResult,
303-
output: 'automatically seeded sample output',
304-
hasUnexpected: 'doesNotHaveUnexpected',
305-
assertionResults: scenarioResult.assertionResults.map(
306-
assertionResult => ({
307-
...assertionResult,
308-
passed: true
309-
})
310-
),
311-
unexpectedBehaviors: []
312-
}))
306+
scenarioResults: baseTestResult.scenarioResults.map(
307+
(scenarioResult, idx) => ({
308+
...scenarioResult,
309+
output: varyOutputsPerScenario
310+
? `seeded output ${idx + 1}`
311+
: 'automatically seeded sample output',
312+
hasUnexpected: 'doesNotHaveUnexpected',
313+
assertionResults: scenarioResult.assertionResults.map(
314+
assertionResult => ({
315+
...assertionResult,
316+
passed: true
317+
})
318+
),
319+
unexpectedBehaviors: []
320+
})
321+
)
313322
});
314323

315324
const testResult = getPassing();

server/tests/integration/verdict-service.test.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ const getReportWithRunsAndMatches = async (id, { transaction }) =>
3939
id
4040
testResults {
4141
id
42+
test { id rowNumber }
4243
scenarioResults {
4344
id
45+
scenario { id }
4446
output
4547
match {
4648
type
@@ -447,4 +449,122 @@ describe('Verdict service', () => {
447449
expect(sawMatch).toBe(true);
448450
});
449451
});
452+
453+
it('annotates CROSS_SCENARIO for a specific scenario when outputs are swapped between two scenarios', async () => {
454+
await apiServer.sessionAgentDbCleaner(async transaction => {
455+
// Use historical finalized report id 25; seeded via run 26 with distinct per-scenario outputs
456+
const { testPlanReport: historicalReport } = await getTestPlanReport(
457+
'25',
458+
{
459+
transaction
460+
}
461+
);
462+
463+
// Choose a historical test with at least 2 scenarios, different outputs, and identical assertion id sets
464+
const targetHistorical = (
465+
historicalReport.finalizedTestResults || []
466+
).find(tr => {
467+
if (!tr.scenarioResults || tr.scenarioResults.length < 2) return false;
468+
const [sr0, sr1] = tr.scenarioResults;
469+
if (sr0.output === sr1.output) return false;
470+
const setFrom = srs =>
471+
new Set(
472+
(srs.assertionResults || []).map(a => String(a.assertion.id))
473+
);
474+
const s0 = setFrom(sr0);
475+
const s1 = setFrom(sr1);
476+
if (s0.size !== s1.size) return false;
477+
for (const id of s0) if (!s1.has(id)) return false;
478+
return true;
479+
});
480+
481+
expect(targetHistorical).toBeDefined();
482+
const [hSr0, hSr1] = targetHistorical.scenarioResults;
483+
const sId0 = hSr0.scenario.id;
484+
const sId1 = hSr1.scenario.id;
485+
const out1 = hSr1.output;
486+
487+
const currentAtVersion = await getAtVersionByQuery({
488+
where: { atId: 3, name: '14.0' },
489+
transaction
490+
});
491+
492+
const createResponse =
493+
await createCollectionJobsFromPreviousVersionMutation(
494+
currentAtVersion.id,
495+
{ transaction }
496+
);
497+
const result = createResponse.createCollectionJobsFromPreviousAtVersion;
498+
const { collectionJob: newJob } = await getTestCollectionJob(
499+
result.collectionJobs[0].id,
500+
{ transaction }
501+
);
502+
503+
const secret = await getJobSecret(newJob.id, { transaction });
504+
let updateResponse = await sessionAgent
505+
.post(`/api/jobs/${newJob.id}`)
506+
.send({ status: 'RUNNING' })
507+
.set('x-automation-secret', secret)
508+
.set('x-transaction-id', transaction.id);
509+
expect(updateResponse.statusCode).toBe(200);
510+
511+
// Post responses; for the chosen test, swap the first two scenario outputs to induce CROSS_SCENARIO
512+
for (const historicalResult of historicalReport.finalizedTestResults) {
513+
const testRowNumber = historicalResult.test.rowNumber;
514+
const responses = historicalResult.scenarioResults.map(sr => sr.output);
515+
if (
516+
historicalResult.test.id === targetHistorical.test.id &&
517+
responses.length >= 2
518+
) {
519+
if (responses[0] !== responses[1]) {
520+
const tmp = responses[0];
521+
responses[0] = responses[1];
522+
responses[1] = tmp;
523+
}
524+
}
525+
const updateRes = await sessionAgent
526+
.post(`/api/jobs/${newJob.id}/test/${testRowNumber}`)
527+
.send({
528+
responses,
529+
capabilities: {
530+
atName: historicalReport.at.name,
531+
atVersion: newJob.testPlanRun.testPlanReport.exactAtVersion.name,
532+
browserName: historicalReport.browser.name,
533+
browserVersion: historicalResult.browserVersion.name
534+
}
535+
})
536+
.set('x-automation-secret', secret)
537+
.set('x-transaction-id', transaction.id);
538+
expect(updateRes.statusCode).toBe(200);
539+
}
540+
541+
const { testPlanReport: updated } = await getReportWithRunsAndMatches(
542+
newJob.testPlanRun.testPlanReport.id,
543+
{ transaction }
544+
);
545+
546+
expect(updated.isRerun).toBe(true);
547+
const updatedTestResult = (updated.draftTestPlanRuns || [])
548+
.flatMap(run => run.testResults || [])
549+
.find(tr => tr.test && tr.test.id === targetHistorical.test.id);
550+
expect(updatedTestResult).toBeDefined();
551+
552+
const updatedSr0 = (updatedTestResult.scenarioResults || []).find(
553+
sr => sr.scenario && sr.scenario.id === sId0
554+
);
555+
const updatedSr1 = (updatedTestResult.scenarioResults || []).find(
556+
sr => sr.scenario && sr.scenario.id === sId1
557+
);
558+
expect(updatedSr0).toBeDefined();
559+
expect(updatedSr1).toBeDefined();
560+
561+
// After swap: scenario sId0 now has output out1 and should be CROSS_SCENARIO sourcing scenario sId1
562+
expect(updatedSr0.output).toBe(out1);
563+
expect(updatedSr0.match).toBeDefined();
564+
expect(updatedSr0.match.type).toBe('CROSS_SCENARIO');
565+
expect(updatedSr0.match.source).toBeDefined();
566+
expect(updatedSr0.match.source.scenarioId).toBe(sId1);
567+
expect(updatedSr0.match.source.output).toBe(out1);
568+
});
569+
});
450570
});

0 commit comments

Comments
 (0)