From cada76070f3c0c3f1d950710a90d3dc1bd345093 Mon Sep 17 00:00:00 2001 From: Giancarlo Buomprisco Date: Wed, 18 Jun 2025 22:25:51 +0700 Subject: [PATCH] Fix healthcheck endpoint (#288) * fix healthcheck db query --- apps/e2e/tests/healthcheck.spec.ts | 18 ++++++++++++++++++ apps/web/app/healthcheck/route.ts | 9 +++++---- 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 apps/e2e/tests/healthcheck.spec.ts diff --git a/apps/e2e/tests/healthcheck.spec.ts b/apps/e2e/tests/healthcheck.spec.ts new file mode 100644 index 000000000..66163fca2 --- /dev/null +++ b/apps/e2e/tests/healthcheck.spec.ts @@ -0,0 +1,18 @@ +import { expect, test } from '@playwright/test'; + +// Simple healthcheck test to verify the API is up and the database responds + +test.describe('Healthcheck endpoint', () => { + test('returns healthy status', async ({ request }) => { + const response = await request.get('/healthcheck'); + + expect(response.status()).toBe(200); + + const body = await response.json(); + expect(body).toEqual( + expect.objectContaining({ + services: expect.objectContaining({ database: true }), + }), + ); + }); +}); diff --git a/apps/web/app/healthcheck/route.ts b/apps/web/app/healthcheck/route.ts index ebb71b975..551961c66 100644 --- a/apps/web/app/healthcheck/route.ts +++ b/apps/web/app/healthcheck/route.ts @@ -26,11 +26,12 @@ async function getSupabaseHealthCheck() { try { const client = getSupabaseServerAdminClient(); - const { error } = await client.rpc('is_set', { - field_name: 'billing_provider', - }); + const { data, error } = await client + .from('config') + .select('billing_provider') + .single(); - return !error; + return !error && Boolean(data?.billing_provider); } catch { return false; }