import assert from 'node:assert/strict'; import { createServer } from 'node:http'; import { after, before, beforeEach, describe, it } from 'node:test'; /** * Public status page (M19). * * The guild id is set before the modules that read it are loaded — hence the * dynamic imports, the same arrangement the Gitea import test uses. */ process.env.DISCORD_GUILD_ID = '900000000000000000'; const GUILD = process.env.DISCORD_GUILD_ID; const { closeDatabase, getDatabase, initDatabase } = await import('../src/database/index.js'); const { createDeployment, finishDeployment } = await import('../src/database/repositories/deploy-repository.js'); const { renderStatus } = await import('../src/web/services/status-render.js'); const { resetStatusCache, statusSnapshot } = await import('../src/web/services/status-service.js'); const { createHandler } = await import('../src/web/server.js'); const snapshot = (overrides = {}) => ({ bot: { online: true, state: 'ok', uptimeMs: 3_600_000, startedAt: new Date().toISOString(), version: '1.2.3', pingMs: 42, }, environments: [], releases: [], links: {}, generatedAt: new Date().toISOString(), ...overrides, }); const deploy = ({ environment, repository, status, releaseTag = null }) => { const created = createDeployment({ guildId: GUILD, targetName: environment, repository, environment, releaseTag, }); finishDeployment(created.id, { status }); return created; }; describe('status page rendering', () => { it('says everything works when the bot answers', () => { const html = renderStatus(snapshot()); assert.match(html, /Tous les services fonctionnent/); assert.match(html, /status-banner-ok/); }); it('leads with the outage when the bot is down', () => { const html = renderStatus(snapshot({ bot: { ...snapshot().bot, online: false, state: 'down' } })); assert.match(html, /Le bot est hors ligne/); assert.match(html, /status-banner-down/); }); /** A green headline above a failed deployment is how a status page loses its point. */ it('refuses to look healthy while a deployment has failed', () => { const html = renderStatus( snapshot({ environments: [ { environment: 'production', repository: 'FWS/x', status: 'failed', tone: 'down', releaseTag: null, finishedAt: null, }, ], }), ); assert.match(html, /déploiement en échec/); assert.match(html, /status-banner-busy/); }); it('carries no script at all', () => { assert.doesNotMatch(renderStatus(snapshot()), /