Skip to content

Commit

Permalink
Add unit test to goff-api.spec.ts for support endpoint paths in data …
Browse files Browse the repository at this point in the history
…collector goff-api.ts goff-api.spec.ts

Signed-off-by: Chris Price <[email protected]>
  • Loading branch information
crprice authored Jan 22, 2025
1 parent 956b86d commit 4a3e573
Showing 1 changed file with 46 additions and 0 deletions.
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

0 comments on commit 4a3e573

Please sign in to comment.