diff --git a/lib/edge/targeting.ts b/lib/edge/targeting.ts index a4cfdc47..91ebfcff 100644 --- a/lib/edge/targeting.ts +++ b/lib/edge/targeting.ts @@ -27,7 +27,7 @@ type UserIdentifiers = { type TargetingRequest = { ids: string[]; - hids: string[]; + hids?: string[]; }; type TargetingResponse = { @@ -49,7 +49,7 @@ const TARGETING_DONE_KEY = "OPTABLE_TARGETING_DONE"; async function Targeting(config: ResolvedConfig, req: TargetingRequest): Promise { const searchParams = new URLSearchParams(); req.ids.forEach((id) => searchParams.append("id", id)); - req.hids.forEach((id) => searchParams.append("hid", id)); + req.hids?.forEach((id) => searchParams.append("hid", id)); const abTest = determineABTest(config.abTests); if (abTest) { searchParams.append("ab_test_id", abTest.id); diff --git a/lib/sdk.test.ts b/lib/sdk.test.ts index 6e083595..acd977ea 100644 --- a/lib/sdk.test.ts +++ b/lib/sdk.test.ts @@ -903,6 +903,15 @@ describe("behavior testing of", () => { }) ); + await sdk.targeting({ ids: ["someId"], hids: ["someHint"] }); + + expect(fetchSpy).toHaveBeenLastCalledWith( + expect.objectContaining({ + method: "GET", + url: expect.stringContaining("v2/targeting?id=someId&hid=someHint"), + }) + ); + const latestResultFromCache = sdk.targetingFromCache(); expect(latestResultFromCache).toEqual({ ...targetingWithParam, refs: {} });