Repository navigation
test: replace partial billing factories with a typed manual mock #17697
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bfef545
test: replace partial billing factories with a typed manual mock
ampagent c1d0b92
test: simplify billing context mock setup
ampagent 416be45
test: centralize billing context setup
ampagent 55ec268
test: isolate billing redirect fixture
ampagent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { vi } from 'vitest' | ||
| import { computed, ref } from 'vue' | ||
|
|
||
| import type { BillingContext } from '../types' | ||
| import type { useBillingContext as realUseBillingContext } from '../useBillingContext' | ||
|
|
||
| function createBillingContextMock(): BillingContext { | ||
| return { | ||
| type: computed(() => 'legacy'), | ||
| isInitialized: ref(false), | ||
| isLoading: ref(false), | ||
| error: ref(null), | ||
| subscription: computed(() => null), | ||
| balance: computed(() => null), | ||
| plans: computed(() => []), | ||
| currentPlanSlug: computed(() => null), | ||
| teamCreditStops: computed(() => null), | ||
| currentTeamCreditStop: computed(() => null), | ||
| maxSeats: computed(() => null), | ||
| occupiedSeats: computed(() => null), | ||
| canAccessSubscriptionFeatures: computed(() => false), | ||
| isFreeTier: computed(() => false), | ||
| billingStatus: computed(() => null), | ||
| subscriptionStatus: computed(() => null), | ||
| tier: computed(() => null), | ||
| renewalDate: computed(() => null), | ||
| isLegacyTeamPlan: computed(() => false), | ||
| isTeamPlan: computed(() => false), | ||
| canRunWorkflows: computed(() => false), | ||
| showsSubscribeToRunPrompt: computed(() => false), | ||
| getMaxSeats: vi.fn(() => 1), | ||
| initialize: vi.fn(async () => {}), | ||
| fetchStatus: vi.fn(async () => {}), | ||
| fetchBalance: vi.fn(async () => {}), | ||
| subscribe: vi.fn(async () => {}), | ||
| previewSubscribe: vi.fn(async () => null), | ||
| manageSubscription: vi.fn(async () => {}), | ||
| cancelSubscription: vi.fn(async () => {}), | ||
| resubscribe: vi.fn(async () => {}), | ||
| topup: vi.fn(async () => {}), | ||
| fetchPlans: vi.fn(async () => {}), | ||
| requireActiveSubscription: vi.fn(async () => {}), | ||
| showSubscriptionDialog: vi.fn(), | ||
| reconcileSubscriptionSuccess: vi.fn(async () => {}) | ||
| } | ||
| } | ||
|
|
||
| export const useBillingContext = vi.fn<typeof realUseBillingContext>( | ||
| createBillingContextMock | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Could we also update the billing mock guidance?
docs/testing/unit-testing.md:323still describesvi.mock(...)plusmockReturnValue(...)as an anti-pattern, but these migrated suites now use that pattern through this manual mock. Would it make sense to align the docs here, or track that as a follow-up?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.
#17714