From 9ac06e0cecd0991e52c64152e22f09e8f4af2379 Mon Sep 17 00:00:00 2001 From: seldinpQ Date: Mon, 2 Dec 2024 19:38:36 +0100 Subject: [PATCH] chore(TMP-1657): Add test --- .../src/utils/__tests__/getDeckApiUrl.test.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts diff --git a/packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts b/packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts new file mode 100644 index 0000000000..2925036a6a --- /dev/null +++ b/packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts @@ -0,0 +1,44 @@ +// getDeckApiUrl.test.ts +import { getDeckApiUrl } from '../getDeckApiUrl'; + +describe('getDeckApiUrl', () => { + beforeEach(() => { + (global as any).window = {}; + }); + + afterEach(() => { + delete (global as any).window; + }); + + it('should return the production URL when environmentName is prod', () => { + (global as any).window.__TIMES_CONFIG__ = { + environmentName: 'prod' + }; + expect(getDeckApiUrl()).toBe( + 'https://editorial-tm.newsapis.co.uk/prod/deck-component-data-api' + ); + }); + + it('should return the staging URL when environmentName is not prod', () => { + (global as any).window.__TIMES_CONFIG__ = { + environmentName: 'staging' + }; + expect(getDeckApiUrl()).toBe( + 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api' + ); + }); + + it('should return the staging URL when window is undefined', () => { + delete (global as any).window; + expect(getDeckApiUrl()).toBe( + 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api' + ); + }); + + it('should return the staging URL when __TIMES_CONFIG__ is undefined', () => { + (global as any).window = {}; + expect(getDeckApiUrl()).toBe( + 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api' + ); + }); +});