Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions js/test-management-scenarios/populate-test-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
var utils = require('./utils');

exports.rule = entities.Issue.onChange({
title: 'Populate-test-run',
Expand All @@ -23,24 +24,15 @@ exports.rule = entities.Issue.onChange({
workflow.check((TestCase.Type.name == ctx.Type.TestCase.name) || (TestCase.Type.name == ctx.Type.TestSuite.name), workflow.i18n('\'Test Run\' can be linked to \'Test Case\' and \'Test Suite\' only, but {0} has \'{1}\' type!', message, TestCase.Type.name));
TestCase.links[ctx.Execution.inward].delete(issue);

// New issue creation
var TestCaseRun = TestCase.copy();
TestCaseRun.Type = ctx.Type.TestExecution.name;
TestCaseRun.Status = ctx.Status.NoRun.name;

// Remove all links from Test Case Execution
Object.keys(TestCaseRun.links).forEach(function(linkType) {
if (!TestCaseRun.links[linkType])
return;
TestCaseRun.links[linkType].clear();
});
TestCaseRun.summary = "[TEST_CASE_EXECUTION" + "] [" + TestCaseRun.summary + "]";
if (TestCase.Type.name == ctx.Type.TestSuite.name) {
var linkedTestCases = TestCase.links[ctx.Subtask.outward]
linkedTestCases.forEach(function(testCase) {
utils.createTestCaseRun(testCase, issue, ctx);
});
} else {
utils.createTestCaseRun(TestCase, issue, ctx);
}

// Links population
TestCaseRun.links[ctx.Subtask.inward].add(issue);
issue.links[ctx.Subtask.outward].add(TestCaseRun);
TestCaseRun.links[ctx.Execution.outward].add(TestCase);
});
issue.fields['Total number of test cases'] = totalTestRuns;
},
requirements: {
Expand Down Expand Up @@ -99,4 +91,4 @@ exports.rule = entities.Issue.onChange({
},
},
}
});
});
22 changes: 21 additions & 1 deletion js/test-management-scenarios/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,24 @@ exports.resetStatuses = function(testRun, testRunCopy) {
testRunCopy.fields['Number of passed test cases'] = 0;
testRunCopy.fields['Number of failed test cases'] = 0;
return true;
};
};
exports.createTestCaseRun = function(testCase, testRun, ctx) {
// New issue creation
var testCaseRun = testCase.copy();

testCaseRun.Type = ctx.Type.TestExecution.name;
testCaseRun.Status = ctx.Status.NoRun.name;

// Remove all links from Test Case Execution
Object.keys(testCaseRun.links).forEach(function(linkType) {
if (!testCaseRun.links[linkType])
return;
testCaseRun.links[linkType].clear();
});
testCaseRun.summary = "[TEST_CASE_EXECUTION" + "] [" + testCaseRun.summary + "]";

// Links population
testCaseRun.links[ctx.Subtask.inward].add(testRun);
testRun.links[ctx.Subtask.outward].add(testCaseRun);
testCaseRun.links[ctx.Execution.outward].add(testCase);
};