-
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.
Allow collecting signals even if edge function is not defined. (#1112)
- Loading branch information
Showing
3 changed files
with
67 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-signals': patch | ||
--- | ||
|
||
Allow collecting signals from sources without an edge function written yet |
54 changes: 54 additions & 0 deletions
54
packages/signals/signals/src/core/processor/__tests__/sandbox-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,54 @@ | ||
import { SandboxSettings, SandboxSettingsConfig } from '../sandbox' | ||
|
||
describe(SandboxSettings, () => { | ||
const edgeFnResponseBody = `function processSignal() { console.log('hello world') }` | ||
const baseSettings: SandboxSettingsConfig = { | ||
functionHost: undefined, | ||
processSignal: undefined, | ||
edgeFnDownloadURL: 'http://example.com/download', | ||
edgeFnFetchClient: jest.fn().mockReturnValue( | ||
Promise.resolve({ | ||
text: () => edgeFnResponseBody, | ||
}) | ||
), | ||
} | ||
test('initializes with provided settings', async () => { | ||
const sandboxSettings = new SandboxSettings({ ...baseSettings }) | ||
expect(baseSettings.edgeFnFetchClient).toHaveBeenCalledWith( | ||
baseSettings.edgeFnDownloadURL | ||
) | ||
expect(await sandboxSettings.processSignal).toEqual(edgeFnResponseBody) | ||
}) | ||
|
||
test('normalizes edgeFnDownloadURL when functionHost is provided', async () => { | ||
const settings: SandboxSettingsConfig = { | ||
...baseSettings, | ||
processSignal: undefined, | ||
functionHost: 'newHost.com', | ||
edgeFnDownloadURL: 'https://original.com/download', | ||
} | ||
new SandboxSettings(settings) | ||
expect(baseSettings.edgeFnFetchClient).toHaveBeenCalledWith( | ||
'https://newHost.com/download' | ||
) | ||
}) | ||
|
||
test('creates default processSignal when parameters are missing', async () => { | ||
const consoleWarnSpy = jest | ||
.spyOn(console, 'warn') | ||
.mockImplementation(() => {}) | ||
const settings: SandboxSettingsConfig = { | ||
...baseSettings, | ||
processSignal: undefined, | ||
edgeFnDownloadURL: undefined, | ||
} | ||
const sandboxSettings = new SandboxSettings(settings) | ||
expect(await sandboxSettings.processSignal).toEqual( | ||
'globalThis.processSignal = function processSignal() {}' | ||
) | ||
expect(baseSettings.edgeFnFetchClient).not.toHaveBeenCalled() | ||
expect(consoleWarnSpy).toHaveBeenCalledWith( | ||
expect.stringContaining('processSignal') | ||
) | ||
}) | ||
}) |
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