Skip to content

Commit

Permalink
flag for ConfigAPI.getconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspk06 committed Jul 19, 2023
1 parent 40e2255 commit 3cb5b34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ class Radar {
Logger.info(`using options: ${JSON.stringify(options)}`);
}

ConfigAPI.getConfig();
// NOTE(jasonl): this allows us to run jest tests
// without having to mock the ConfigAPI.getConfig call
if (!(window as any)?.RADAR_TEST_ENV) {
ConfigAPI.getConfig();
}
}

public static clear() {
Expand Down
6 changes: 2 additions & 4 deletions test/api/trips.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('Trips', () => {

beforeEach(() => {
Radar.initialize('prj_test_pk_123');
Radar.setUserId(userId);
jest.spyOn(Http, 'request');
});

afterEach(() => {
Expand All @@ -19,10 +21,6 @@ describe('Trips', () => {
});

describe('startTrip', () => {
beforeEach(() => {
Radar.setUserId(userId);
jest.spyOn(Http, 'request');
});

describe('called without tripOptions', () => {
it('should include tripOptions each set to unknown', async () => {
Expand Down
14 changes: 14 additions & 0 deletions test/radar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ContextAPI from '../src/api/context';
import SearchAPI from '../src/api/search';
import TrackAPI from '../src/api/track';
import RoutingAPI from '../src/api/routing';
import ConfigAPI from '../src/api/config';

import { latitude, longitude } from './common';

Expand Down Expand Up @@ -51,6 +52,15 @@ describe('Radar', () => {
const units = 'imperial';

describe('initialize', () => {
beforeEach(() => {
(window as any).RADAR_TEST_ENV = false;
});

afterEach(() => {
(window as any).RADAR_TEST_ENV = true;
jest.restoreAllMocks();
});

describe('no key is provided', () => {
it('should throw RadarPublishableKeyError', () => {
try {
Expand All @@ -77,19 +87,23 @@ describe('Radar', () => {

describe('test publishableKey is provided', () => {
it('should initialize SDK in a test environment', () => {
jest.spyOn(ConfigAPI, 'getConfig');
Radar.initialize('_my_test_pk_123');
const options = Config.get();
expect(options.publishableKey).toEqual('_my_test_pk_123');
expect(options.live).toEqual(false);
expect(ConfigAPI.getConfig).toHaveBeenCalledTimes(1);
});
});

describe('live publishableKey is provided', () => {
it('should initialize SDK in a live environment', () => {
jest.spyOn(ConfigAPI, 'getConfig');
Radar.initialize('_my_live_pk_123');
const options = Config.get();
expect(options.publishableKey).toEqual('_my_live_pk_123');
expect(options.live).toEqual(true);
expect(ConfigAPI.getConfig).toHaveBeenCalledTimes(1);
});
});
});
Expand Down

0 comments on commit 3cb5b34

Please sign in to comment.