支持自部署需求管理、交付流程与飞书集成
This commit is contained in:
1 parent
4556a5b483
commit
e22b66d9dd
148 files changed
+8300
-6393
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, test } from 'node:test';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { emptyFields, type Demand } from '../lib/demand.ts';
|
||||
import { closeDatabases, getDatabase, type AccountRow } from '../lib/server/database.ts';
|
||||
import { withDefaultDeveloper } from '../lib/server/default-developer.ts';
|
||||
import { applyReviewAction } from '../lib/server/demand-review.ts';
|
||||
import type { AuthUser } from '../lib/server/auth.ts';
|
||||
|
||||
const directory = mkdtempSync(join(tmpdir(), 'demand-default-developer-'));
|
||||
const environment = { ...process.env };
|
||||
let admin: AuthUser;
|
||||
before(() => {
|
||||
Object.assign(process.env, { DATA_DIR: directory, APP_URL: 'https://test.example', INITIAL_ADMIN_USERNAME: 'default_admin', INITIAL_ADMIN_PASSWORD: 'Local test password 9274', INITIAL_ADMIN_DISPLAY_NAME: '系统管理员' });
|
||||
const row = getDatabase().prepare('SELECT * FROM accounts').first<AccountRow>()!;
|
||||
admin = { userId: row.id, username: row.username, displayName: row.display_name, role: 'admin', mustChangePassword: false };
|
||||
});
|
||||
after(() => { closeDatabases(); rmSync(directory, { recursive: true, force: true }); process.env = environment; });
|
||||
const demand = (status = '待评审'): Demand => ({ id: 'default', fields: { ...emptyFields }, revision: 7, status, reviewReady: true, createdAt: '', updatedAt: '', history: [], changes: [] });
|
||||
|
||||
test('unassigned formal demands resolve to an enabled system administrator without changing revision or history', () => {
|
||||
const original = demand();
|
||||
const assigned = withDefaultDeveloper(original);
|
||||
assert.equal(assigned.review?.developer.userId, admin.userId);
|
||||
assert.equal(assigned.review?.developer.displayName, '系统管理员');
|
||||
assert.equal(assigned.revision, 7);
|
||||
assert.deepEqual(assigned.history, []);
|
||||
assert.equal(original.review, undefined);
|
||||
assert.deepEqual(withDefaultDeveloper(original), assigned);
|
||||
});
|
||||
|
||||
test('existing assignments, private drafts and closed historical demands remain unchanged', () => {
|
||||
const assigned = { ...demand(), review: { developer: { userId: 'legacy', username: 'legacy', displayName: '原开发' }, proposals: [] } };
|
||||
for (const record of [assigned, demand('草稿'), demand('已取消'), demand('已完成')]) assert.equal(withDefaultDeveloper(record), record);
|
||||
});
|
||||
|
||||
test('default administrator can submit and confirm a demand they registered', () => {
|
||||
const record = withDefaultDeveloper(demand());
|
||||
applyReviewAction(record, admin.userId, admin, { action: 'propose-solution', scope: 'F-01 查询订单', outOfScope: '无' }, '2026-09-23T00:00:00Z');
|
||||
assert.equal(record.review?.proposals[0].developer.userId, admin.userId);
|
||||
applyReviewAction(record, admin.userId, admin, { action: 'confirm-solution', proposalVersion: 1, confirm: true }, '2026-09-23T00:01:00Z');
|
||||
assert.equal(record.review?.proposals[0].decision?.result, 'confirmed');
|
||||
});
|
||||
|
||||
test('disabled administrators are skipped and ordinary accounts are never used as defaults', () => {
|
||||
const database = getDatabase();
|
||||
database.prepare('UPDATE accounts SET disabled = 1 WHERE id = ?').bind(admin.userId).run();
|
||||
assert.throws(() => withDefaultDeveloper(demand()), /暂无启用的系统管理员/);
|
||||
database.prepare('UPDATE accounts SET disabled = 0, role = ? WHERE id = ?').bind('user', admin.userId).run();
|
||||
assert.throws(() => withDefaultDeveloper(demand()), /暂无启用的系统管理员/);
|
||||
database.prepare('UPDATE accounts SET role = ? WHERE id = ?').bind('admin', admin.userId).run();
|
||||
});
|
||||
Reference in new issue
Block a user