Skip to content

Commit 4a3e573

Browse files
authored
Add unit test to goff-api.spec.ts for support endpoint paths in data collector goff-api.ts goff-api.spec.ts
Signed-off-by: Chris Price <[email protected]>
1 parent 956b86d commit 4a3e573

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

libs/providers/go-feature-flag-web/src/lib/controller/goff-api.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,52 @@ describe('Collect Data API', () => {
103103
);
104104
});
105105

106+
it('should call the API to collect data with endpoint path', async () => {
107+
fetchMock.post('https://gofeatureflag.org/examplepath/v1/data/collector', 200);
108+
const options: GoFeatureFlagWebProviderOptions = {
109+
endpoint: 'https://gofeatureflag.org/examplepath',
110+
apiTimeout: 1000,
111+
};
112+
const goff = new GoffApiController(options);
113+
await goff.collectData(
114+
[
115+
{
116+
key: 'flagKey',
117+
contextKind: 'user',
118+
creationDate: 1733138237486,
119+
default: false,
120+
kind: 'feature',
121+
userKey: 'toto',
122+
value: true,
123+
variation: 'varA',
124+
},
125+
],
126+
{ provider: 'open-feature-js-sdk' },
127+
);
128+
expect(fetchMock.lastUrl()).toBe('https://gofeatureflag.org/examplepath/v1/data/collector');
129+
expect(fetchMock.lastOptions()?.headers).toEqual({
130+
'Content-Type': 'application/json',
131+
Accept: 'application/json',
132+
});
133+
expect(fetchMock.lastOptions()?.body).toEqual(
134+
JSON.stringify({
135+
events: [
136+
{
137+
key: 'flagKey',
138+
contextKind: 'user',
139+
creationDate: 1733138237486,
140+
default: false,
141+
kind: 'feature',
142+
userKey: 'toto',
143+
value: true,
144+
variation: 'varA',
145+
},
146+
],
147+
meta: { provider: 'open-feature-js-sdk' },
148+
}),
149+
);
150+
});
151+
106152
it('should not call the API to collect data if no event provided', async () => {
107153
fetchMock.post('https://gofeatureflag.org/v1/data/collector', 200);
108154
const options: GoFeatureFlagWebProviderOptions = {

0 commit comments

Comments
 (0)