feat: журнал тестирования, бэклог идей; V.2 hasAnyAttemptForTest + unit tests; ссылки в спринтах

Made-with: Cursor
This commit is contained in:
Константин Лебединский
2026-04-24 19:26:02 +05:00
parent 4eeb3fbc62
commit e87168d3a0
9 changed files with 247 additions and 4 deletions
+31
View File
@@ -0,0 +1,31 @@
{
"name": "clinic-tests-backend",
"version": "1.0.0",
"description": "Backend for Clinic Tests application",
"main": "src/index.js",
"type": "module",
"scripts": {
"start": "node src/index.js",
"dev": "node --watch src/index.js",
"test": "node --test src/services/testChainService.test.js",
"lint": "eslint src/",
"lint:fix": "eslint src/ --fix",
"format": "prettier --write src/"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.1.1",
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.0",
"jsonwebtoken": "^9.0.2",
"pg": "^8.12.0"
},
"devDependencies": {
"eslint": "^8.57.0",
"prettier": "^3.3.3"
}
}
+18
View File
@@ -0,0 +1,18 @@
/**
* Логика «цепочки» теста: попытки и версии (см. docs/revision_task/card1.md V.2).
* @param {import('pg').Pool | { query: Function }} pool пул или объект с методом query(sql, params)
* @param {string} testId UUID теста (tests.id)
* @returns {Promise<boolean>} true, если по любой версии этой цепочки есть хотя бы одна попытка
*/
export async function hasAnyAttemptForTest(pool, testId) {
const { rows } = await pool.query(
`SELECT EXISTS (
SELECT 1
FROM test_attempts ta
INNER JOIN test_versions tv ON ta.test_version_id = tv.id
WHERE tv.test_id = $1
) AS has_any`,
[testId]
);
return rows[0].has_any === true;
}
@@ -0,0 +1,23 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { hasAnyAttemptForTest } from './testChainService.js';
test('hasAnyAttemptForTest: false, если в базе пусто', async () => {
const pool = {
async query() {
return { rows: [{ has_any: false }] };
},
};
const result = await hasAnyAttemptForTest(pool, '00000000-0000-0000-0000-000000000001');
assert.equal(result, false);
});
test('hasAnyAttemptForTest: true, если есть попытка', async () => {
const pool = {
async query() {
return { rows: [{ has_any: true }] };
},
};
const result = await hasAnyAttemptForTest(pool, '00000000-0000-0000-0000-000000000001');
assert.equal(result, true);
});