-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add updateCDNSettings() option (#870)
- Loading branch information
Showing
4 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@segment/analytics-next': minor | ||
--- | ||
|
||
Add updateCDNSettings option |
70 changes: 70 additions & 0 deletions
70
packages/browser/src/browser/__tests__/update-cdn-settings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { AnalyticsBrowser } from '../..' | ||
import { setGlobalCDNUrl } from '../../lib/parse-cdn' | ||
import { remoteLoader } from '../../plugins/remote-loader' | ||
import unfetch from 'unfetch' | ||
import { createSuccess } from '../../test-helpers/factories' | ||
jest.mock('unfetch') | ||
|
||
const INTG_TO_DELETE = 'deleteMe' | ||
|
||
const cdnSettings = { | ||
integrations: { | ||
[INTG_TO_DELETE]: { bar: true }, | ||
otherIntegration: { foo: true }, | ||
}, | ||
} | ||
const mockFetchSettingsSuccessResponse = (cdnSettings: any) => { | ||
return jest | ||
.mocked(unfetch) | ||
.mockImplementation(() => createSuccess(cdnSettings)) | ||
} | ||
|
||
jest.mock('../../plugins/remote-loader') | ||
const remoteLoaderSpy = jest.fn().mockResolvedValue([]) | ||
jest.mocked(remoteLoader).mockImplementation(remoteLoaderSpy) | ||
|
||
describe('updateCDNSettings configuration option', () => { | ||
beforeEach(() => { | ||
setGlobalCDNUrl(undefined as any) | ||
;(window as any).analytics = undefined | ||
}) | ||
it('should update the configuration options if they are passed directly', async () => { | ||
await AnalyticsBrowser.load( | ||
{ | ||
writeKey: 'foo', | ||
cdnSettings, | ||
}, | ||
{ | ||
updateCDNSettings: (settings) => { | ||
delete settings.integrations.deleteMe | ||
return settings | ||
}, | ||
} | ||
) | ||
const [arg1] = remoteLoaderSpy.mock.lastCall | ||
expect(arg1.integrations.otherIntegration).toEqual( | ||
cdnSettings.integrations.otherIntegration | ||
) | ||
expect(arg1.integrations[INTG_TO_DELETE]).toBeUndefined() | ||
}) | ||
|
||
it('should update the configuration options if they are fetched', async () => { | ||
mockFetchSettingsSuccessResponse(cdnSettings) | ||
await AnalyticsBrowser.load( | ||
{ | ||
writeKey: 'foo', | ||
}, | ||
{ | ||
updateCDNSettings: (settings) => { | ||
delete settings.integrations.deleteMe | ||
return settings | ||
}, | ||
} | ||
) | ||
const [arg1] = remoteLoaderSpy.mock.lastCall | ||
expect(arg1.integrations.otherIntegration).toEqual( | ||
cdnSettings.integrations.otherIntegration | ||
) | ||
expect(arg1.integrations[INTG_TO_DELETE]).toBeUndefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters