-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(flags): Enqueue follow up requests without dropping (#797)
- Loading branch information
1 parent
233e604
commit e3a296e
Showing
8 changed files
with
71 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,10 +107,7 @@ test('person properties set in identify() with the same distinct_id are sent to | |
}) | ||
}) | ||
|
||
test('identify() doesnt trigger new request automatically if first request takes too long', async () => { | ||
// TODO: Make this experience nicer, and queue requests, rather than leave | ||
// it upto the user to call reloadFeatureFlags() manually. | ||
|
||
test('identify() triggers new request in queue after first request', async () => { | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token, { advanced_disable_decide: false }) | ||
|
||
|
@@ -130,12 +127,60 @@ test('identify() doesnt trigger new request automatically if first request takes | |
resetRequests(token) | ||
|
||
// don't wait for decide callback | ||
|
||
posthog.identify('test-id', { | ||
email: 'test@email.com', | ||
email: 'test2@email.com', | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(getRequests(token)['/decide/']).toEqual([]) | ||
}) | ||
|
||
// wait for decide callback | ||
// eslint-disable-next-line compat/compat | ||
await new Promise((res) => setTimeout(res, 500)) | ||
|
||
// now second call should've fired | ||
await waitFor(() => { | ||
expect(getRequests(token)['/decide/']).toEqual([ | ||
{ | ||
$anon_distinct_id: anonymousId, | ||
distinct_id: 'test-id', | ||
groups: {}, | ||
person_properties: { email: '[email protected]' }, | ||
token, | ||
}, | ||
]) | ||
}) | ||
}) | ||
|
||
test('identify() does not trigger new request in queue after first request for loaded callback', async () => { | ||
const token = v4() | ||
await createPosthogInstance(token, { | ||
advanced_disable_decide: false, | ||
bootstrap: { distinctID: 'anon-id' }, | ||
loaded: (ph) => { | ||
ph.identify('test-id', { email: '[email protected]' }) | ||
ph.group('playlist', 'id:77', { length: 8 }) | ||
}, | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(getRequests(token)['/decide/']).toEqual([ | ||
// This is the initial call to the decide endpoint on PostHog init, with all info added from `loaded`. | ||
{ | ||
// $anon_distinct_id: 'anon-id', // no anonymous ID is sent because this was overridden on load | ||
distinct_id: 'test-id', | ||
groups: { playlist: 'id:77' }, | ||
person_properties: { | ||
email: '[email protected]', | ||
}, | ||
group_properties: { | ||
playlist: { | ||
length: 8, | ||
}, | ||
}, | ||
token, | ||
}, | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters