feat: display tags in test run page (#378)

This commit is contained in:
kimatata
2026-01-10 18:17:07 +09:00
committed by GitHub
parent 0f34fb1683
commit 475fa1ced7
4 changed files with 79 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import defineRun from '../../models/runs.js';
import defineRunCase from '../../models/runCases.js';
import defineCase from '../../models/cases.js';
import defineFolder from '../../models/folders.js';
import defineTag from '../../models/tags.js';
import authMiddleware from '../../middleware/auth.js';
import visibilityMiddleware from '../../middleware/verifyVisible.js';
import { testRunCaseStatus, testRunStatus, priorities, testTypes, automationStatus } from '../../config/enums.js';
@@ -19,8 +20,11 @@ export default function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes);
const Case = defineCase(sequelize, DataTypes);
const Folder = defineFolder(sequelize, DataTypes);
const Tags = defineTag(sequelize, DataTypes);
RunCase.belongsTo(Case, { foreignKey: 'caseId' });
Case.belongsToMany(Tags, { through: 'caseTags', foreignKey: 'caseId', otherKey: 'tagId' });
Tags.belongsToMany(Case, { through: 'caseTags', foreignKey: 'tagId', otherKey: 'caseId' });
router.get('/download/:runId', verifySignedIn, verifyProjectVisibleFromRunId, async (req, res) => {
const { runId } = req.params;
@@ -38,7 +42,18 @@ export default function (sequelize) {
const runCases = await RunCase.findAll({
where: { runId },
include: [{ model: Case }],
include: [
{
model: Case,
include: [
{
model: Tags,
attributes: ['id', 'name'],
through: { attributes: [] },
},
],
},
],
});
if (type === 'xml') {
@@ -104,6 +119,7 @@ export default function (sequelize) {
priority: priorities[rc.Case.priority] || rc.Case.priority,
type: testTypes[rc.Case.type] || rc.Case.type,
automationStatus: automationStatus[rc.Case.automationStatus] || rc.Case.automationStatus,
tags: rc.Case.Tags && rc.Case.Tags.length > 0 ? rc.Case.Tags.map((tag) => tag.name).join(', ') : '',
status: testRunCaseStatus[rc.status] || rc.status,
}));

View File

@@ -59,6 +59,7 @@ vi.mock('../../models/runCases.js', () => ({
// mock defineCase
const mockCase = {
belongsTo: vi.fn(),
belongsToMany: vi.fn(),
};
vi.mock('../../models/cases.js', () => ({
default: () => mockCase,
@@ -72,6 +73,14 @@ vi.mock('../../models/folders.js', () => ({
default: () => mockFolder,
}));
// mock defineTag
const mockTags = {
belongsToMany: vi.fn(),
};
vi.mock('../../models/tags.js', () => ({
default: () => mockTags,
}));
describe('GET /download/:runId with type=csv', () => {
let app;
const sequelize = new Sequelize({
@@ -105,6 +114,10 @@ describe('GET /download/:runId with type=csv', () => {
priority: 0, // critical
type: 4, // functional
automationStatus: 0, // automated
Tags: [
{ id: 1, name: 'tag1' },
{ id: 2, name: 'tag2' },
],
},
},
{
@@ -119,6 +132,7 @@ describe('GET /download/:runId with type=csv', () => {
priority: 1, // high
type: 1, // security
automationStatus: 1, // automation-not-required
Tags: [],
},
},
{
@@ -133,6 +147,7 @@ describe('GET /download/:runId with type=csv', () => {
priority: 2, // medium
type: 2, // performance
automationStatus: 2, // cannot-be-automated
Tags: [{ id: 3, name: 'tag3' }],
},
},
]);
@@ -162,6 +177,11 @@ describe('GET /download/:runId with type=csv', () => {
expect(csvContent).toContain('inProgress');
expect(csvContent).toContain('underReview');
// Check that tags are included in the CSV
expect(csvContent).toContain('tags');
expect(csvContent).toContain('tag1, tag2');
expect(csvContent).toContain('tag3');
// Ensure numeric values are not present (except for id which should be numeric)
const lines = csvContent.split('\n');
const dataLines = lines.slice(1).filter((line) => line.trim()); // Skip header