Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/six-cameras-turn.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 1 addition & 1 deletion apps/meteor/client/hooks/useIsEnterprise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) }) });
};
1 change: 1 addition & 0 deletions apps/meteor/tests/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export const createFakeLicenseInfo = (partial: Partial<Omit<LicenseInfo, 'licens
color: faker.internet.color(),
})),
trial: faker.datatype.boolean(),
hasValidLicense: faker.datatype.boolean(),
...partial,
});

Expand Down
1 change: 1 addition & 0 deletions ee/packages/license/src/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ export abstract class LicenseManager extends Emitter<LicenseEvents> {
limits: limits as Record<LicenseLimitKind, { max: number; value: number }>,
tags: license?.information.tags || [],
trial: Boolean(license?.information.trial),
hasValidLicense: this.hasValidLicense(),
};
}
}
1 change: 1 addition & 0 deletions packages/core-typings/src/license/LicenseInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export type LicenseInfo = {
limits: Record<LicenseLimitKind, { value?: number; max: number }>;
tags: ILicenseTag[];
trial: boolean;
hasValidLicense: boolean;
cloudSyncAnnouncement?: ICloudSyncAnnouncement;
};
Loading