-
Notifications
You must be signed in to change notification settings - Fork 0
fix: change override condition of tier #1547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -486,7 +486,7 @@ describe('TierClient', () => { | |
| }); | ||
| }); | ||
|
|
||
| it('should upgrade PLG entitlement to FREE_TRIAL (PLG is not PAID, so tier updates)', async () => { | ||
| it('should NOT change tier when upgrading PLG to FREE_TRIAL (only PAID upgrades are applied)', async () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: the The entire invariant this PR enforces ("protect PAID from being overwritten") is unverified. Please add, each asserting
Also Important: consider replacing these two renamed tests with a parameterised Minor: the stale JSDoc at |
||
| const mockPlgEntitlement = { | ||
| ...mockEntitlement, | ||
| getTier: () => 'PLG', | ||
|
|
@@ -500,8 +500,8 @@ describe('TierClient', () => { | |
|
|
||
| const result = await tierClient.createEntitlement('FREE_TRIAL'); | ||
|
|
||
| expect(mockPlgEntitlement.setTier).to.have.been.calledWith('FREE_TRIAL'); | ||
| expect(mockPlgEntitlement.save).to.have.been.called; | ||
| expect(mockPlgEntitlement.setTier).to.not.have.been.called; | ||
| expect(mockPlgEntitlement.save).to.not.have.been.called; | ||
| expect(result).to.deep.equal({ | ||
| entitlement: mockPlgEntitlement, | ||
| siteEnrollment: mockSiteEnrollment, | ||
|
|
@@ -550,7 +550,7 @@ describe('TierClient', () => { | |
| }); | ||
| }); | ||
|
|
||
| it('should upgrade PRE_ONBOARD entitlement to PLG (PRE_ONBOARD is not PAID, so tier updates)', async () => { | ||
| it('should NOT change tier when upgrading PRE_ONBOARD to PLG (only PAID upgrades are applied)', async () => { | ||
| const mockPreOnboardEntitlement = { | ||
| ...mockEntitlement, | ||
| getTier: () => 'PRE_ONBOARD', | ||
|
|
@@ -564,8 +564,8 @@ describe('TierClient', () => { | |
|
|
||
| const result = await tierClient.createEntitlement('PLG'); | ||
|
|
||
| expect(mockPreOnboardEntitlement.setTier).to.have.been.calledWith('PLG'); | ||
| expect(mockPreOnboardEntitlement.save).to.have.been.called; | ||
| expect(mockPreOnboardEntitlement.setTier).to.not.have.been.called; | ||
| expect(mockPreOnboardEntitlement.save).to.not.have.been.called; | ||
| expect(result).to.deep.equal({ | ||
| entitlement: mockPreOnboardEntitlement, | ||
| siteEnrollment: mockSiteEnrollment, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: silent no-op with misleading return.
When this guard is false, the method still returns
existing.entitlementfrom below, whosegetTier()does NOT match thetierargument the caller passed. Callers inspacecat-api-service(PLG/LLMO onboarding) andspacecat-fulfillment-workerhave no way to detect their requested tier was ignored: no log, no error, no flag on the return object.Fix (pick one):
this.log.warn({ orgId, currentTier, requestedTier: tier }, 'Tier change skipped; createEntitlement only upgrades to PAID')in anelsebranch, OR{ entitlement, siteEnrollment, tierChanged: boolean }so callers can branch on it.Important (separate finding, same line): the hard-coded
=== ENTITLEMENT_TIERS.PAIDcouples the library to today's 4-tier ladder. When ENTERPRISE or any variant is added, this predicate is wrong at every call site. Prefer a tier-ordinal comparison or an explicit transition-policy map.