Skip to content

Commit f7252ba

Browse files
committed
Tests
1 parent 1d4d1b4 commit f7252ba

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

packages/sdk/browser/__tests__/BrowserClient.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,4 +872,72 @@ describe('given a mock platform for a BrowserClient', () => {
872872
// Verify that no fetch calls were made
873873
expect(platform.requests.fetch.mock.calls.length).toBe(0);
874874
});
875+
876+
it('uses FDv1 endpoints when dataSystem is not set', async () => {
877+
const client = makeClient(
878+
'client-side-id',
879+
{ key: 'user-key', kind: 'user' },
880+
AutoEnvAttributes.Disabled,
881+
{ streaming: false, logger, diagnosticOptOut: true, sendEvents: false, fetchGoals: false },
882+
platform,
883+
);
884+
885+
await client.start();
886+
887+
const fetchUrl = platform.requests.fetch.mock.calls[0][0];
888+
expect(fetchUrl).toContain('/sdk/evalx/');
889+
expect(fetchUrl).not.toContain('/sdk/poll/eval');
890+
});
891+
892+
it('uses FDv2 endpoints when dataSystem is set', async () => {
893+
const client = makeClient(
894+
'client-side-id',
895+
{ key: 'user-key', kind: 'user' },
896+
AutoEnvAttributes.Disabled,
897+
{
898+
streaming: false,
899+
logger,
900+
diagnosticOptOut: true,
901+
sendEvents: false,
902+
fetchGoals: false,
903+
// @ts-ignore dataSystem is @internal
904+
dataSystem: {},
905+
},
906+
platform,
907+
);
908+
909+
await client.start();
910+
911+
const fetchUrl = platform.requests.fetch.mock.calls[0][0];
912+
expect(fetchUrl).toContain('/sdk/poll/eval/');
913+
});
914+
915+
it('validates dataSystem options and applies browser defaults', async () => {
916+
const client = makeClient(
917+
'client-side-id',
918+
{ key: 'user-key', kind: 'user' },
919+
AutoEnvAttributes.Disabled,
920+
{
921+
streaming: false,
922+
logger,
923+
diagnosticOptOut: true,
924+
sendEvents: false,
925+
fetchGoals: false,
926+
// @ts-ignore dataSystem is @internal
927+
dataSystem: { initialConnectionMode: 'invalid-mode' },
928+
},
929+
platform,
930+
);
931+
932+
// Invalid mode should produce a warning
933+
expect(logger.warn).toHaveBeenCalledWith(
934+
expect.stringContaining('dataSystem.initialConnectionMode'),
935+
);
936+
937+
await client.start();
938+
939+
// Should still use FDv2 — invalid sub-fields fall back to defaults, not disable FDv2
940+
const fetchUrl = platform.requests.fetch.mock.calls[0][0];
941+
expect(fetchUrl).toContain('/sdk/poll/eval/');
942+
});
875943
});

packages/sdk/browser/__tests__/options.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,19 @@ it('does not override common config flushInterval if it is set', () => {
9090
const result = filterToBaseOptionsWithDefaults(opts);
9191
expect(result.flushInterval).toEqual(15);
9292
});
93+
94+
it('passes dataSystem through to base options without stripping', () => {
95+
const opts = {
96+
dataSystem: { initialConnectionMode: 'polling' },
97+
} as any;
98+
const result = filterToBaseOptionsWithDefaults(opts);
99+
expect((result as any).dataSystem).toEqual({ initialConnectionMode: 'polling' });
100+
});
101+
102+
it('passes an empty dataSystem through to base options', () => {
103+
const opts = {
104+
dataSystem: {},
105+
} as any;
106+
const result = filterToBaseOptionsWithDefaults(opts);
107+
expect((result as any).dataSystem).toEqual({});
108+
});

0 commit comments

Comments
 (0)