From d158b48709d85746b779472233ad6c369aaf97f1 Mon Sep 17 00:00:00 2001 From: Andrew Powers Date: Wed, 20 Mar 2024 11:10:55 -0700 Subject: [PATCH] fix: live check -d --- @fiction/www/test/builtFiles.dist.test.ts | 2 +- @fiction/www/test/services.live.test.ts | 57 +++++++++++++++-------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/@fiction/www/test/builtFiles.dist.test.ts b/@fiction/www/test/builtFiles.dist.test.ts index 0bd197fc4..18499fea6 100644 --- a/@fiction/www/test/builtFiles.dist.test.ts +++ b/@fiction/www/test/builtFiles.dist.test.ts @@ -8,7 +8,7 @@ describe('pre check secrets', () => { it('has secrets', async () => { const { stdout } = execaCommandSync('flyctl secrets list -a fiction-sites') - const secrets = ['FLY_API_TOKEN', 'POSTGRES_URL', 'GH_TOKEN', 'TOKEN_SECRET'] + const secrets = ['FLY_API_TOKEN', 'POSTGRES_URL', 'GH_TOKEN', 'TOKEN_SECRET', 'AWS_ACCESS_KEY', 'AWS_ACCESS_KEY_SECRET', 'GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET'] for (const secret of secrets) expect(stdout).toContain(secret) }) diff --git a/@fiction/www/test/services.live.test.ts b/@fiction/www/test/services.live.test.ts index 40cf4f5fa..676f9aeb5 100644 --- a/@fiction/www/test/services.live.test.ts +++ b/@fiction/www/test/services.live.test.ts @@ -3,35 +3,38 @@ import { snap } from '@fiction/core/test-utils' describe('service health checks', () => { const services = [ - 'https://www.fiction.cx', - 'https://docs.fiction.cx', - 'https://theme-minimal.fiction.cx', - 'https://andrewpowers.fiction.cx', - 'https://www.andrewpowers.com', + { url: 'https://www.fiction.cx' }, + { url: 'https://docs.fiction.cx/', checkForText: 'fiction', noApi: true }, + { url: 'https://theme-minimal.fiction.cx' }, + { url: 'https://andrewpowers.fiction.cx' }, + { url: 'https://www.andrewpowers.com' }, ] it('services health endpoint works and logs response time', async () => { const outputs: Record[] = [] for (const service of services) { - const url = `${service}/api/health?test=1` + if (service.noApi) + continue + + const url = `${service.url}/api/health?test=1` const startTime = Date.now() - const response = await fetch(url) + const response = await fetch(url, { headers: { 'User-Agent': 'Fiction-Test' }, method: 'GET' }) const endTime = Date.now() const responseTime = endTime - startTime - expect(responseTime, `response time ${service}`).toBeLessThan(5000) + expect(responseTime, `response time ${service.url}`).toBeLessThan(5000) - console.warn(`Response time for ${service}: ${responseTime}ms`) + console.warn(`Response time for ${service.url}: ${responseTime}ms`) - expect(response.status, `response status ${service}`).toBe(200) + expect(response.status, `response status ${service.url}`).toBe(200) const json = (await response.json()) as Record outputs.push(json) - expect(json.status, `health status ${service}`).toBe('success') - expect(json.message, `health ${service}`).toBe('ok') + expect(json.status, `health status ${service.url}`).toBe('success') + expect(json.message, `health ${service.url}`).toBe('ok') } expect(snap(outputs)).toMatchInlineSnapshot(` @@ -42,7 +45,15 @@ describe('service health checks', () => { "message": "ok", "status": "success", "timestamp": "[dateTime:]", - "version": "6.0.9", + "version": "6.0.11", + }, + { + "commit": "notFound", + "duration": "[dateTime:]", + "message": "ok", + "status": "success", + "timestamp": "[dateTime:]", + "version": "6.0.11", }, { "commit": "notFound", @@ -50,22 +61,30 @@ describe('service health checks', () => { "message": "ok", "status": "success", "timestamp": "[dateTime:]", - "version": "6.0.9", + "version": "6.0.11", + }, + { + "commit": "notFound", + "duration": "[dateTime:]", + "message": "ok", + "status": "success", + "timestamp": "[dateTime:]", + "version": "6.0.11", }, ] `) }, 10000) it('websites are live and check content', async () => { - for (const site of services) { - const response = await fetch(`${site}?test=1`) + for (const service of services) { + const response = await fetch(`${service.url}?test=1`) - expect(response.status, `status ${site}`).toBe(200) + expect(response.status, `status ${service.url}`).toBe(200) const html = await response.text() - expect(html, `html: ${site}`).toContain('