fix: send $groupidentify for new groups even without properties#3319
fix: send $groupidentify for new groups even without properties#3319dustinbyrne wants to merge 3 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/browser/src/__tests__/posthog-core-also.test.ts
Line: 1309-1319
Comment:
**Redundant test duplicates earlier assertion**
This test tests the exact same scenario as the one at line 1261 ("sends $groupidentify for a new group even without properties"). Both start with no existing group, call `posthog.group('organization', 'org::5')`, and assert the exact same `$groupidentify` payload shape.
Jest's `toHaveBeenCalledWith` uses deep equality (`toEqual`) under the hood, so passing `{ $group_type: 'organization', $group_key: 'org::5' }` as the expected argument already fails if `$group_set` (or any extra property) is present. The extra `expect(capturedArgs).not.toHaveProperty('$group_set')` assertion on line 1318 is therefore fully implied by the first test's assertion and adds no additional coverage.
Per the project's "OnceAndOnlyOnce" and "no superfluous parts" simplicity rules, this test should be removed.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: send $groupidentify for new groups ..." | Re-trigger Greptile |
| it('sends $groupidentify without $group_set when group key changes and no properties provided', () => { | ||
| posthog.group('organization', 'org::5') | ||
|
|
||
| expect(posthog.capture).toHaveBeenCalledWith('$groupidentify', { | ||
| $group_type: 'organization', | ||
| $group_key: 'org::5', | ||
| }) | ||
| // Verify $group_set is NOT in the properties | ||
| const capturedArgs = jest.mocked(posthog.capture).mock.calls[0][1] | ||
| expect(capturedArgs).not.toHaveProperty('$group_set') | ||
| }) |
There was a problem hiding this comment.
Redundant test duplicates earlier assertion
This test tests the exact same scenario as the one at line 1261 ("sends $groupidentify for a new group even without properties"). Both start with no existing group, call posthog.group('organization', 'org::5'), and assert the exact same $groupidentify payload shape.
Jest's toHaveBeenCalledWith uses deep equality (toEqual) under the hood, so passing { $group_type: 'organization', $group_key: 'org::5' } as the expected argument already fails if $group_set (or any extra property) is present. The extra expect(capturedArgs).not.toHaveProperty('$group_set') assertion on line 1318 is therefore fully implied by the first test's assertion and adds no additional coverage.
Per the project's "OnceAndOnlyOnce" and "no superfluous parts" simplicity rules, this test should be removed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browser/src/__tests__/posthog-core-also.test.ts
Line: 1309-1319
Comment:
**Redundant test duplicates earlier assertion**
This test tests the exact same scenario as the one at line 1261 ("sends $groupidentify for a new group even without properties"). Both start with no existing group, call `posthog.group('organization', 'org::5')`, and assert the exact same `$groupidentify` payload shape.
Jest's `toHaveBeenCalledWith` uses deep equality (`toEqual`) under the hood, so passing `{ $group_type: 'organization', $group_key: 'org::5' }` as the expected argument already fails if `$group_set` (or any extra property) is present. The extra `expect(capturedArgs).not.toHaveProperty('$group_set')` assertion on line 1318 is therefore fully implied by the first test's assertion and adds no additional coverage.
Per the project's "OnceAndOnlyOnce" and "no superfluous parts" simplicity rules, this test should be removed.
How can I resolve this? If you propose a fix, please make it concise.|
Size Change: -2.31 kB (-0.03%) Total Size: 6.65 MB
ℹ️ View Unchanged
|
Problem
Customers calling
posthog.group("company", "company_id")without properties expect the group type and group to be created server-side (via a$groupidentifyevent, documented here). However, the browser SDK only sent$groupidentifywhengroupPropertiesToSetwas provided, meaning a no-propertiesgroup()call silently did nothing beyond changing local state. The group was never created on the server.This is inconsistent with the iOS, Android, Unity, and Flutter SDKs, which all unconditionally send
$groupidentify.Changes
packages/browser/src/posthog-core.tsgroup()now sends$groupidentifywhen the group key is new or changed, even without properties.$group_setis only included in the event payload when properties are actually provided, matching the behavior of all other SDKs.packages/browser/src/__tests__/posthog-core-also.test.ts$groupidentify$groupidentify$groupidentifywith$group_set$group_setfrom payload$groupidentifyenqueuesRelease info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file