test: add API integration test suite (40 tests)
- node:test based, zero extra dependencies, npm test script - api.test.js: auth, posts, pagination, replies, 404/401 handling - admin.test.js: admin API, role management, settings, links, logs - dm.test.js: private messaging, unread counts, read receipts, 403 - helpers.js: makeAdmin() to guarantee admin role in shared DB - test/README.md: setup and run instructions
This commit is contained in:
1 parent
02ac24ba88
commit
7d431a89a7
6 files changed
+463
-1
No files matched your search
@@ -0,0 +1,21 @@
|
||||
// 测试辅助工具
|
||||
import pg from 'pg';
|
||||
|
||||
// 从 DATABASE_URL 或默认连接串读取(与测试库保持一致)
|
||||
const pool = new pg.Pool({
|
||||
connectionString: process.env.DATABASE_URL || 'postgresql://forumlify:123456@localhost:5433/forumlify',
|
||||
});
|
||||
|
||||
// 把指定用户提升为管理员(绕过"第一个用户才 admin"的限制,保证每个测试文件可独立获得 admin)
|
||||
export async function makeAdmin(email) {
|
||||
await pool.query('UPDATE users SET role = $1 WHERE email = $2', ['admin', email]);
|
||||
await pool.end();
|
||||
}
|
||||
|
||||
// 清理测试数据(可选)
|
||||
export async function cleanup(emails) {
|
||||
for (const email of emails) {
|
||||
await pool.query('DELETE FROM users WHERE email = $1', [email]);
|
||||
}
|
||||
await pool.end();
|
||||
}
|
||||
Reference in new issue
Block a user