Skip to content

Commit

Permalink
feat: export metabase client with delayed instantiation for test
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-hh-aa committed Nov 28, 2024
1 parent b3947be commit 301f7d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api.planx.uk/modules/analytics/metabase/shared/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
validateConfig,
createMetabaseClient,
MetabaseError,
initializeMetabaseClient,
} from "./client.js";
import nock from "nock";

Expand All @@ -12,6 +13,9 @@ describe("Metabase client", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.resetModules();
process.env.METABASE_URL_EXT = "https://test-metabase-url.com";
process.env.METABASE_API_KEY = "test-api-key";
initializeMetabaseClient();
});

afterEach(() => {
Expand Down
9 changes: 6 additions & 3 deletions api.planx.uk/modules/analytics/metabase/shared/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ export const createMetabaseClient = (): AxiosInstance => {
return client;
};

// Export singleton instance
export const metabaseClient = createMetabaseClient();
// Export both client and instance with delayed instantiation for test purposes
export let metabaseClient: AxiosInstance;

export default metabaseClient;
export const initializeMetabaseClient = () => {
metabaseClient = createMetabaseClient();
return metabaseClient;
};

0 comments on commit 301f7d5

Please sign in to comment.