From fdb46bba2966751fce8ad0c71f860171486b7b74 Mon Sep 17 00:00:00 2001 From: dal Date: Mon, 21 Jul 2025 01:37:41 -0600 Subject: [PATCH] electric helpers --- .../electric-shape/_helpers/helpers.test.ts | 20 ++++++++++++++----- .../api/v2/electric-shape/_helpers/helpers.ts | 14 +++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/apps/server/src/api/v2/electric-shape/_helpers/helpers.test.ts b/apps/server/src/api/v2/electric-shape/_helpers/helpers.test.ts index 2dadc1772..cc91e722d 100644 --- a/apps/server/src/api/v2/electric-shape/_helpers/helpers.test.ts +++ b/apps/server/src/api/v2/electric-shape/_helpers/helpers.test.ts @@ -2,21 +2,31 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { extractParamFromWhere, getElectricShapeUrl } from '.'; describe('getElectricShapeUrl', () => { - process.env.ELECTRIC_PROXY_URL = 'http://localhost:3000'; - const originalElectricUrl = process.env.ELECTRIC_PROXY_URL; + let originalElectricUrl: string | undefined; + let originalSourceId: string | undefined; beforeEach(() => { - // Clean up environment variable before each test + // Save original environment variables + originalElectricUrl = process.env.ELECTRIC_PROXY_URL; + originalSourceId = process.env.ELECTRIC_SOURCE_ID; + + // Set default test values process.env.ELECTRIC_PROXY_URL = 'http://localhost:3000'; process.env.ELECTRIC_SOURCE_ID = ''; }); afterEach(() => { - // Restore original environment variable after each test + // Restore original environment variables if (originalElectricUrl !== undefined) { process.env.ELECTRIC_PROXY_URL = originalElectricUrl; } else { - process.env.ELECTRIC_PROXY_URL = ''; + delete process.env.ELECTRIC_PROXY_URL; + } + + if (originalSourceId !== undefined) { + process.env.ELECTRIC_SOURCE_ID = originalSourceId; + } else { + delete process.env.ELECTRIC_SOURCE_ID; } }); diff --git a/apps/server/src/api/v2/electric-shape/_helpers/helpers.ts b/apps/server/src/api/v2/electric-shape/_helpers/helpers.ts index 243ad34ac..77034cc57 100644 --- a/apps/server/src/api/v2/electric-shape/_helpers/helpers.ts +++ b/apps/server/src/api/v2/electric-shape/_helpers/helpers.ts @@ -1,15 +1,11 @@ -if (!process.env.ELECTRIC_PROXY_URL) { - throw new Error('ELECTRIC_PROXY_URL is not set'); -} - -if (process.env.NODE_ENV === 'production' && !process.env.ELECTRIC_SOURCE_ID) { - console.warn('ELECTRIC_SOURCE_ID is not set'); -} - export const getElectricShapeUrl = (requestUrl: string) => { const url = new URL(requestUrl); - const baseUrl = process.env.ELECTRIC_PROXY_URL || ''; + const baseUrl = process.env.ELECTRIC_PROXY_URL; + + if (!baseUrl) { + throw new Error('ELECTRIC_PROXY_URL is not set'); + } // Parse the base URL and replace the path with /v1/shape const baseUrlObj = new URL(baseUrl);