mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 02:43:49 +08:00
fix: editor should not query billing subscriptions (#38157)
This commit is contained in:
parent
07b5dcbb19
commit
34f62e7df6
@ -232,7 +232,20 @@ describe('Billing Page + Plan Integration', () => {
|
|||||||
|
|
||||||
// Verify billing URL button visibility and behavior
|
// Verify billing URL button visibility and behavior
|
||||||
describe('Billing URL button', () => {
|
describe('Billing URL button', () => {
|
||||||
it('should show billing button when subscription management permission is granted', () => {
|
it('should show billing button when manager has subscription management permission', () => {
|
||||||
|
setupProviderContext({ type: Plan.sandbox })
|
||||||
|
setupAppContext({
|
||||||
|
isCurrentWorkspaceManager: true,
|
||||||
|
workspacePermissionKeys: ['billing.subscription.manage'],
|
||||||
|
})
|
||||||
|
|
||||||
|
render(<Billing />)
|
||||||
|
|
||||||
|
expect(screen.getByText(/viewBillingTitle/i)).toBeInTheDocument()
|
||||||
|
expect(screen.getByText(/viewBillingAction/i)).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should hide billing button when subscription management permission is granted without manager role', () => {
|
||||||
setupProviderContext({ type: Plan.sandbox })
|
setupProviderContext({ type: Plan.sandbox })
|
||||||
setupAppContext({
|
setupAppContext({
|
||||||
isCurrentWorkspaceManager: false,
|
isCurrentWorkspaceManager: false,
|
||||||
@ -241,8 +254,7 @@ describe('Billing Page + Plan Integration', () => {
|
|||||||
|
|
||||||
render(<Billing />)
|
render(<Billing />)
|
||||||
|
|
||||||
expect(screen.getByText(/viewBillingTitle/i)).toBeInTheDocument()
|
expect(screen.queryByText(/viewBillingTitle/i)).not.toBeInTheDocument()
|
||||||
expect(screen.getByText(/viewBillingAction/i)).toBeInTheDocument()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should hide billing button when subscription management permission is missing', () => {
|
it('should hide billing button when subscription management permission is missing', () => {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ let fetching = false
|
|||||||
let isManager = true
|
let isManager = true
|
||||||
let enableBilling = true
|
let enableBilling = true
|
||||||
let workspacePermissionKeys: string[] = ['billing.subscription.manage']
|
let workspacePermissionKeys: string[] = ['billing.subscription.manage']
|
||||||
|
let billingUrlEnabled = false
|
||||||
|
|
||||||
const refetchMock = vi.fn()
|
const refetchMock = vi.fn()
|
||||||
const openAsyncWindowMock = vi.fn()
|
const openAsyncWindowMock = vi.fn()
|
||||||
@ -19,11 +20,14 @@ type BillingWindowOptions = {
|
|||||||
type OpenAsyncWindowCall = [BillingUrlCallback, BillingWindowOptions]
|
type OpenAsyncWindowCall = [BillingUrlCallback, BillingWindowOptions]
|
||||||
|
|
||||||
vi.mock('@/service/use-billing', () => ({
|
vi.mock('@/service/use-billing', () => ({
|
||||||
useBillingUrl: () => ({
|
useBillingUrl: (enabled: boolean) => {
|
||||||
data: currentBillingUrl,
|
billingUrlEnabled = enabled
|
||||||
isFetching: fetching,
|
return {
|
||||||
refetch: refetchMock,
|
data: currentBillingUrl,
|
||||||
}),
|
isFetching: fetching,
|
||||||
|
refetch: refetchMock,
|
||||||
|
}
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('@/hooks/use-async-window-open', () => ({
|
vi.mock('@/hooks/use-async-window-open', () => ({
|
||||||
@ -54,28 +58,32 @@ describe('Billing', () => {
|
|||||||
fetching = false
|
fetching = false
|
||||||
isManager = true
|
isManager = true
|
||||||
enableBilling = true
|
enableBilling = true
|
||||||
|
billingUrlEnabled = false
|
||||||
workspacePermissionKeys = ['billing.subscription.manage']
|
workspacePermissionKeys = ['billing.subscription.manage']
|
||||||
refetchMock.mockResolvedValue({ data: 'https://billing' })
|
refetchMock.mockResolvedValue({ data: 'https://billing' })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows the billing action when subscription management permission is granted without manager role', () => {
|
it('hides the billing action when subscription management permission is granted without manager role', () => {
|
||||||
isManager = false
|
isManager = false
|
||||||
|
|
||||||
render(<Billing />)
|
render(<Billing />)
|
||||||
|
|
||||||
expect(screen.getByRole('button', { name: /billing\.viewBillingTitle/ })).toBeInTheDocument()
|
expect(screen.queryByRole('button', { name: /billing\.viewBillingTitle/ })).not.toBeInTheDocument()
|
||||||
|
expect(billingUrlEnabled).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('hides the billing action when subscription management permission is missing or billing is disabled', () => {
|
it('hides the billing action when subscription management permission is missing or billing is disabled', () => {
|
||||||
workspacePermissionKeys = []
|
workspacePermissionKeys = []
|
||||||
render(<Billing />)
|
render(<Billing />)
|
||||||
expect(screen.queryByRole('button', { name: /billing\.viewBillingTitle/ })).not.toBeInTheDocument()
|
expect(screen.queryByRole('button', { name: /billing\.viewBillingTitle/ })).not.toBeInTheDocument()
|
||||||
|
expect(billingUrlEnabled).toBe(false)
|
||||||
|
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
workspacePermissionKeys = ['billing.subscription.manage']
|
workspacePermissionKeys = ['billing.subscription.manage']
|
||||||
enableBilling = false
|
enableBilling = false
|
||||||
render(<Billing />)
|
render(<Billing />)
|
||||||
expect(screen.queryByRole('button', { name: /billing\.viewBillingTitle/ })).not.toBeInTheDocument()
|
expect(screen.queryByRole('button', { name: /billing\.viewBillingTitle/ })).not.toBeInTheDocument()
|
||||||
|
expect(billingUrlEnabled).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('opens the billing window with the immediate url when the button is clicked', async () => {
|
it('opens the billing window with the immediate url when the button is clicked', async () => {
|
||||||
|
|||||||
@ -11,9 +11,9 @@ import PlanComp from '../plan'
|
|||||||
|
|
||||||
const Billing: FC = () => {
|
const Billing: FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { workspacePermissionKeys } = useAppContext()
|
const { isCurrentWorkspaceManager, workspacePermissionKeys } = useAppContext()
|
||||||
const { enableBilling } = useProviderContext()
|
const { enableBilling } = useProviderContext()
|
||||||
const canManageBillingSubscription = hasPermission(workspacePermissionKeys, BillingPermission.SubscriptionManage)
|
const canManageBillingSubscription = isCurrentWorkspaceManager && hasPermission(workspacePermissionKeys, BillingPermission.SubscriptionManage)
|
||||||
const { data: billingUrl, isFetching, refetch } = useBillingUrl(enableBilling && canManageBillingSubscription)
|
const { data: billingUrl, isFetching, refetch } = useBillingUrl(enableBilling && canManageBillingSubscription)
|
||||||
const openAsyncWindow = useAsyncWindowOpen()
|
const openAsyncWindow = useAsyncWindowOpen()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user