Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,52 @@ describe('Collect Data API', () => {
);
});

it('should call the API to collect data with endpoint path', async () => {
fetchMock.post('https://gofeatureflag.org/examplepath/v1/data/collector', 200);
const options: GoFeatureFlagWebProviderOptions = {
endpoint: 'https://gofeatureflag.org/examplepath',
apiTimeout: 1000,
};
const goff = new GoffApiController(options);
await goff.collectData(
[
{
key: 'flagKey',
contextKind: 'user',
creationDate: 1733138237486,
default: false,
kind: 'feature',
userKey: 'toto',
value: true,
variation: 'varA',
},
],
{ provider: 'open-feature-js-sdk' },
);
expect(fetchMock.lastUrl()).toBe('https://gofeatureflag.org/examplepath/v1/data/collector');
expect(fetchMock.lastOptions()?.headers).toEqual({
'Content-Type': 'application/json',
Accept: 'application/json',
});
expect(fetchMock.lastOptions()?.body).toEqual(
JSON.stringify({
events: [
{
key: 'flagKey',
contextKind: 'user',
creationDate: 1733138237486,
default: false,
kind: 'feature',
userKey: 'toto',
value: true,
variation: 'varA',
},
],
meta: { provider: 'open-feature-js-sdk' },
}),
);
});

it('should not call the API to collect data if no event provided', async () => {
fetchMock.post('https://gofeatureflag.org/v1/data/collector', 200);
const options: GoFeatureFlagWebProviderOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export class GoffApiController {

const request: DataCollectorRequest<boolean> = { events: events, meta: dataCollectorMetadata };
const endpointURL = new URL(this.endpoint);
endpointURL.pathname = 'v1/data/collector';
const dataCollectorPath = 'v1/data/collector';
endpointURL.pathname = endpointURL.pathname.endsWith('/')
? endpointURL.pathname + dataCollectorPath
: endpointURL.pathname + '/' + dataCollectorPath;

try {
const headers: HeadersInit = {
Expand Down
Loading