mirror of
https://github.com/mileswolfallen2/miles-web.git
synced 2026-12-05 00:00:41 +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,38 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { openDatabase } from '../server/db/index.js';
|
||||
import { migrate } from '../server/db/migrate.js';
|
||||
import { seedConfig } from '../server/db/seed.js';
|
||||
import { createAnalyticsService } from '../server/services/analytics.js';
|
||||
import { createVaultService } from '../server/services/vault.js';
|
||||
import { makeConfig, silentLogger } from './helpers.js';
|
||||
|
||||
test('migrations are idempotent and data persists across a restart', async (t) => {
|
||||
const config = makeConfig();
|
||||
t.after(() => fs.rmSync(config.tempDir, { recursive: true, force: true }));
|
||||
|
||||
const first = openDatabase(config.dbPath);
|
||||
assert.equal(migrate(first), 1);
|
||||
assert.equal(migrate(first), 0);
|
||||
seedConfig(first, config);
|
||||
const analytics = createAnalyticsService({ db: first, config });
|
||||
analytics.recordHit({
|
||||
path: '/persisted',
|
||||
ip: '198.51.100.9',
|
||||
userAgent: 'Mozilla/5.0 Chrome/130 Safari/537.36',
|
||||
at: new Date('2026-11-07T12:00:00.000Z')
|
||||
});
|
||||
const vault = await createVaultService({ db: first, config, logger: silentLogger() });
|
||||
assert.equal(vault.enabled, false);
|
||||
first.close();
|
||||
|
||||
const second = openDatabase(config.dbPath);
|
||||
assert.equal(migrate(second), 0);
|
||||
seedConfig(second, config);
|
||||
const rows = second.prepare('SELECT path FROM pageviews').all();
|
||||
assert.deepEqual(rows, [{ path: '/persisted' }]);
|
||||
assert.equal(second.prepare('SELECT COUNT(*) AS c FROM projects WHERE visible = 1').get().c, 1);
|
||||
assert.equal(second.prepare('SELECT COUNT(*) AS c FROM servers').get().c, 1);
|
||||
second.close();
|
||||
});
|
||||
Reference in new issue
Block a user