Skip to content

Commit 928e437

Browse files
authored
fix(go-feature-flag): Support endpoint paths in data collector goff-api.ts (#1184)
Signed-off-by: Chris Price <[email protected]>
1 parent 62da1cb commit 928e437

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

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

+46
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 = {

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export class GoffApiController {
2222

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

2730
try {
2831
const headers: HeadersInit = {

0 commit comments

Comments
 (0)