Skip to content

Commit

Permalink
chore(TMP-1657): Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
seldinpQ committed Dec 2, 2024
1 parent 38b0dc5 commit 9ac06e0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts
Original file line number Diff line number Diff line change
@@ -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'
);
});
});

0 comments on commit 9ac06e0

Please sign in to comment.