feat(测试用例): 状态流转接入单条工作流
This commit is contained in:
79
apps/web/lib/test-case-workflow.test.ts
Normal file
79
apps/web/lib/test-case-workflow.test.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import type { TestCase } from './test-case';
|
||||
import { applyTestCaseTransition, normalizeTestCaseOnCreate } from './test-case-workflow';
|
||||
|
||||
function tc(patch: Partial<TestCase> = {}): TestCase {
|
||||
return {
|
||||
id: 'tc-1',
|
||||
caseNo: 'TC-001',
|
||||
versionId: 'version-1',
|
||||
title: '拖拽排序正常',
|
||||
description: '验证拖拽排序',
|
||||
categoryId: 'cat-test-functional',
|
||||
priority: 'P2',
|
||||
status: 'pending',
|
||||
createdBy: 'QA',
|
||||
createdAt: '2026-06-25T00:00:00.000Z',
|
||||
updatedAt: '2026-06-25T00:00:00.000Z',
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
test('normalizeTestCaseOnCreate forces pending and clears actual timestamps', () => {
|
||||
const result = normalizeTestCaseOnCreate(tc({
|
||||
status: 'running',
|
||||
startedAt: '2026-06-25T01:00:00.000Z',
|
||||
completedAt: '2026-06-25T02:00:00.000Z',
|
||||
}));
|
||||
|
||||
assert.equal(result.status, 'pending');
|
||||
assert.equal(result.startedAt, undefined);
|
||||
assert.equal(result.completedAt, undefined);
|
||||
});
|
||||
|
||||
test('pending to running writes startedAt', () => {
|
||||
const result = applyTestCaseTransition(tc(), 'running', {
|
||||
now: new Date('2026-06-25T01:00:00.000Z'),
|
||||
});
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.patch?.startedAt, '2026-06-25T01:00:00.000Z');
|
||||
});
|
||||
|
||||
test('running to passed writes completedAt', () => {
|
||||
const result = applyTestCaseTransition(tc({
|
||||
status: 'running',
|
||||
startedAt: '2026-06-25T01:00:00.000Z',
|
||||
}), 'passed', {
|
||||
now: new Date('2026-06-25T02:00:00.000Z'),
|
||||
});
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.patch?.completedAt, '2026-06-25T02:00:00.000Z');
|
||||
});
|
||||
|
||||
test('failed back to running clears failure and completion reason', () => {
|
||||
const result = applyTestCaseTransition(tc({
|
||||
status: 'failed',
|
||||
startedAt: '2026-06-25T01:00:00.000Z',
|
||||
completedAt: '2026-06-25T02:00:00.000Z',
|
||||
failReason: '排序未保存',
|
||||
}), 'running', {
|
||||
now: new Date('2026-06-25T03:00:00.000Z'),
|
||||
});
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.patch?.startedAt, undefined);
|
||||
assert.equal(result.patch?.completedAt, undefined);
|
||||
assert.equal(result.patch?.failReason, undefined);
|
||||
});
|
||||
|
||||
test('invalid transition is rejected', () => {
|
||||
const result = applyTestCaseTransition(tc(), 'passed', {
|
||||
now: new Date('2026-06-25T02:00:00.000Z'),
|
||||
});
|
||||
|
||||
assert.equal(result.ok, false);
|
||||
});
|
||||
Reference in New Issue
Block a user