diff --git a/.changeset/six-cameras-turn.md b/.changeset/six-cameras-turn.md new file mode 100644 index 0000000000000..37529a6bb0ba3 --- /dev/null +++ b/.changeset/six-cameras-turn.md @@ -0,0 +1,7 @@ +--- +'@rocket.chat/core-typings': patch +'@rocket.chat/license': patch +'@rocket.chat/meteor': patch +--- + +Fixes premium capability popup showing despite active enterprise license. diff --git a/apps/meteor/client/components/GenericUpsellModal/hooks/useUpsellActions.spec.ts b/apps/meteor/client/components/GenericUpsellModal/hooks/useUpsellActions.spec.ts new file mode 100644 index 0000000000000..50aff1697fae3 --- /dev/null +++ b/apps/meteor/client/components/GenericUpsellModal/hooks/useUpsellActions.spec.ts @@ -0,0 +1,67 @@ +import { mockAppRoot } from '@rocket.chat/mock-providers'; +import type { UseQueryResult } from '@tanstack/react-query'; +import { renderHook, waitFor } from '@testing-library/react'; + +import { useUpsellActions } from './useUpsellActions'; +import { createFakeLicenseInfo } from '../../../../tests/mocks/data'; +import { useIsEnterprise } from '../../../hooks/useIsEnterprise'; + +jest.mock('../../../hooks/useIsEnterprise', () => ({ + useIsEnterprise: jest.fn(), +})); + +const appRoot = mockAppRoot() + .withJohnDoe() + .withEndpoint('GET', '/v1/licenses.info', async () => ({ license: createFakeLicenseInfo({ hasValidLicense: true }) })) + .build(); + +describe('useUpsellActions hook', () => { + beforeEach(() => { + (useIsEnterprise as jest.Mock).mockImplementation(jest.requireActual('../../../hooks/useIsEnterprise').useIsEnterprise); + }); + + afterAll(() => { + jest.clearAllMocks(); + }); + + it('should show upsell modal if not enterprise', () => { + const { result } = renderHook(() => useUpsellActions(), { + wrapper: mockAppRoot().build(), + }); + + expect(result.current.shouldShowUpsell).toBe(true); + expect(result.current.cloudWorkspaceHadTrial).toBe(false); + }); + + it('should show upsell modal if enterprise but has no license module', async () => { + const { result } = renderHook(() => useUpsellActions(false), { + wrapper: appRoot, + }); + + await waitFor(() => { + expect(result.current.shouldShowUpsell).toBe(true); + }); + }); + + it('should NOT show upsell if enterprise and has license module', async () => { + const { result } = renderHook(() => useUpsellActions(true), { + wrapper: appRoot, + }); + + await waitFor(() => { + expect(result.current.shouldShowUpsell).toBe(false); + }); + }); + + it('should show upsell if useIsEnterprise is undefined', async () => { + (useIsEnterprise as jest.Mock).mockReturnValue({ + data: undefined, + } as UseQueryResult); + + const { result } = renderHook(() => useUpsellActions(true), { + wrapper: mockAppRoot().build(), + }); + + expect(result.current.shouldShowUpsell).toBe(true); + }); +}); diff --git a/apps/meteor/client/hooks/useIsEnterprise.ts b/apps/meteor/client/hooks/useIsEnterprise.ts index 884d138211444..e5fa08e0c8ef9 100644 --- a/apps/meteor/client/hooks/useIsEnterprise.ts +++ b/apps/meteor/client/hooks/useIsEnterprise.ts @@ -2,5 +2,5 @@ import { useLicenseBase } from '@rocket.chat/ui-client'; import type { UseQueryResult } from '@tanstack/react-query'; export const useIsEnterprise = (): UseQueryResult<{ isEnterprise: boolean }> => { - return useLicenseBase({ select: (data) => ({ isEnterprise: Boolean(data?.license.license) }) }); + return useLicenseBase({ select: (data) => ({ isEnterprise: Boolean(data?.license.hasValidLicense) }) }); }; diff --git a/apps/meteor/tests/mocks/data.ts b/apps/meteor/tests/mocks/data.ts index ecdca6b206a23..eb4cc6342e3f1 100644 --- a/apps/meteor/tests/mocks/data.ts +++ b/apps/meteor/tests/mocks/data.ts @@ -257,6 +257,7 @@ export const createFakeLicenseInfo = (partial: Partial { limits: limits as Record, tags: license?.information.tags || [], trial: Boolean(license?.information.trial), + hasValidLicense: this.hasValidLicense(), }; } } diff --git a/packages/core-typings/src/license/LicenseInfo.ts b/packages/core-typings/src/license/LicenseInfo.ts index 855602283cd36..6b0f959d0df8d 100644 --- a/packages/core-typings/src/license/LicenseInfo.ts +++ b/packages/core-typings/src/license/LicenseInfo.ts @@ -11,5 +11,6 @@ export type LicenseInfo = { limits: Record; tags: ILicenseTag[]; trial: boolean; + hasValidLicense: boolean; cloudSyncAnnouncement?: ICloudSyncAnnouncement; };