feat: Track individual subscription start and cancel events#2079
Merged
charlesvien merged 2 commits intoMay 7, 2026
Merged
Conversation
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced May 7, 2026
07b789b to
ed295c4
Compare
4b95895 to
20283f4
Compare
4e338fc to
8b8adff
Compare
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/features/billing/stores/seatStore.ts:227-229
The third fallback to `PLAN_PRO` is a hardcoded guess that will silently emit an incorrect `plan_key` whenever `cancelSeat` is called without a seat loaded in the store (e.g., stale state) and the post-cancel API also returns `null`. Analytics data reporting the wrong cancelled plan is worse than a missing event. If neither the pre-cancel store state nor the post-cancel API response provides a plan key, the track call should be skipped rather than inventing a value.
```suggestion
const cancelledPlanKey = previousPlanKey ?? seat?.plan_key;
if (cancelledPlanKey) {
track(ANALYTICS_EVENTS.SUBSCRIPTION_CANCELLED, {
plan_key: cancelledPlanKey,
});
}
```
### Issue 2 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:233-255
**Missing test for the `cancelSeat` fallback path**
The sole `cancelSeat` test always pre-seeds the store with a `proSeat`, so `previousPlanKey` is always defined. The fallback branches (`seat?.plan_key` and the hardcoded `PLAN_PRO` default) are never exercised. A test starting with `seat: null` in the store would cover the path where the pre-cancel plan key has to come from the post-cancel API response — and would expose the incorrect-default behaviour described in the inline comment on the implementation.
Reviews (1): Last reviewed commit: "Track individual subscription start and ..." | Re-trigger Greptile |
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:282-285
Weak no-call assertion — only checks args, not presence. `not.toHaveBeenCalledWith(...)` passes even if `track` was called with different arguments (e.g., a future event added on the same code path). Use `not.toHaveBeenCalled()` to fully assert that no tracking fires in this branch.
```suggestion
expect(mockTrack).not.toHaveBeenCalled();
```
### Issue 2 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:233-287
Prefer parameterised tests here. The three `cancelSeat` tests share the same skeleton — call `cancelSeat()`, assert `cancelSeat` was invoked, then assert on `mockTrack` — varying only `initialSeat`, `getMySeatResponse`, and the expected `track` arguments. An `it.each` table would remove the repetition and make it trivial to add new cases. The same pattern applies to the `upgradeToPro` block above.
Reviews (2): Last reviewed commit: "skip cancel tracking when plan key is un..." | Re-trigger Greptile |
adboio
approved these changes
May 7, 2026
341073d to
4cdb1d2
Compare
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:282-285
The assertion uses `not.toHaveBeenCalledWith(event, anything)`, which only checks that `track` was not called with _this specific event and any args_. It would still pass if `track` was called with a different event entirely. Since tracking should be completely skipped on this path, `not.toHaveBeenCalled()` is both cleaner and a stricter guarantee.
```suggestion
expect(mockTrack).not.toHaveBeenCalled();
```
### Issue 2 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:233-288
**Prefer parameterised tests for `cancelSeat`**
The three `cancelSeat` tests share the same shape — seed store state, mock `getMySeat`, call `cancelSeat`, assert on `mockTrack` — and differ only in inputs and expected outcome. Collapsing them into a single `it.each` table (with `initialSeat`, `apiSeat`, and `expectedPlanKey` columns) would follow the team's rule of always preferring parameterised tests, make the coverage matrix instantly readable, and ensure future cases get added to one place.
Reviews (3): Last reviewed commit: "skip cancel tracking when plan key is un..." | Re-trigger Greptile |
4cdb1d2 to
a2eaeaf
Compare
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:282-285
The assertion `not.toHaveBeenCalledWith(SUBSCRIPTION_CANCELLED, expect.anything())` only guards against that specific call signature — it would silently pass if `mockTrack` were called with a different event (e.g. `SUBSCRIPTION_STARTED`). Since this test's intent is "no tracking at all on cancel", `not.toHaveBeenCalled()` is the correct, stricter form.
```suggestion
expect(mockTrack).not.toHaveBeenCalled();
```
### Issue 2 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:165-214
**Prefer parameterised tests for the two upgrade-path scenarios**
The "upgrades existing free seat to pro" and "upgrades alpha pro seat to paid pro" tests are structurally identical — they differ only in the pre-existing plan key and the expected `previous_plan_key` assertion. Per the project's convention, these should be collapsed into a single `it.each` table, e.g. `it.each([[PLAN_FREE, PLAN_FREE], [PLAN_PRO_ALPHA, PLAN_PRO_ALPHA]])("upgrades %s seat to pro", ...)`. This avoids repeating the same setup/assertion block twice and makes it trivial to add new plan variants.
Reviews (4): Last reviewed commit: "skip cancel tracking when plan key is un..." | Re-trigger Greptile |
Member
Author
Merge activity
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
Existing billing reports only track at the org level, leaving individual user subscription activity invisible.
Changes
Subscription startedandSubscription cancelledevent types withplan_keypropertiesseatStore.upgradeToProon both upgrade and fresh-create pathsseatStore.cancelSeatcapturing the pre-cancelplan_keyseatStore.test.tsHow did you test this?
Manually
Publish to changelog?