mirror of
https://github.com/mileswolfallen2/miles-web.git
synced 2026-12-05 08:10:43 +00:00
Add comprehensive test suite for application functionality
- Implement tests for HTTP API endpoints, ensuring correct responses and security headers. - Create configuration tests to validate loading of defaults and environment overrides. - Add tests for FEDL service to verify data handling and snapshot functionality. - Introduce GitHub service tests to check API data normalization and caching behavior. - Develop monitor service tests for network checks and uptime calculations. - Implement persistence tests to ensure database migrations are idempotent and data persists across restarts. - Add vault service tests for session management and brute-force protection mechanisms. - Include helper functions for test context creation and JSON response handling.
This commit is contained in:
1 parent
84b7a7e302
commit
c250653961
55 files changed
+8174
-226
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
||||
const MIGRATIONS_DIR = path.join(HERE, 'migrations');
|
||||
|
||||
export function migrate(db, { migrationsDir = MIGRATIONS_DIR } = {}) {
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
version INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
applied_at TEXT NOT NULL
|
||||
);
|
||||
`);
|
||||
|
||||
const applied = new Set(
|
||||
db.prepare('SELECT version FROM schema_migrations').all().map((row) => row.version)
|
||||
);
|
||||
|
||||
const files = fs
|
||||
.readdirSync(migrationsDir)
|
||||
.filter((name) => /^\d+_.+\.sql$/.test(name))
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
|
||||
const insert = db.prepare(
|
||||
'INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)'
|
||||
);
|
||||
|
||||
let count = 0;
|
||||
for (const file of files) {
|
||||
const version = Number.parseInt(file.split('_')[0], 10);
|
||||
if (applied.has(version)) continue;
|
||||
const sql = fs.readFileSync(path.join(migrationsDir, file), 'utf8');
|
||||
const run = db.transaction(() => {
|
||||
db.exec(sql);
|
||||
insert.run(version, file, new Date().toISOString());
|
||||
});
|
||||
run();
|
||||
count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
Reference in new issue
Block a user