mirror of https://github.com/buster-so/buster.git
electric helpers
This commit is contained in:
parent
5ca40d032b
commit
fdb46bba29
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue