snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export * from './useOutboundMessageAccess';
|
||||
@@ -0,0 +1,112 @@
|
||||
import { usePermission } from '@rocket.chat/ui-contexts';
|
||||
import type { UseQueryResult } from '@tanstack/react-query';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
import { useOutboundMessageAccess } from './useOutboundMessageAccess';
|
||||
import { useHasLicenseModule } from '../../../../../hooks/useHasLicenseModule';
|
||||
import { useOmnichannelEnabled } from '../../../hooks/useOmnichannelEnabled';
|
||||
|
||||
jest.mock('@rocket.chat/ui-contexts', () => ({
|
||||
usePermission: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('../../../hooks/useOmnichannelEnabled', () => ({
|
||||
useOmnichannelEnabled: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('../../../../../hooks/useHasLicenseModule', () => ({
|
||||
useHasLicenseModule: jest.fn(),
|
||||
}));
|
||||
|
||||
const usePermissionMock = jest.mocked(usePermission);
|
||||
const useOmnichannelEnabledMock = jest.mocked(useOmnichannelEnabled);
|
||||
const useHasLicenseModuleMock = jest.mocked(useHasLicenseModule);
|
||||
|
||||
// TODO: do not mock the hook itself, mock only its dependencies
|
||||
const createSuccessfulQueryResult = (data: boolean): UseQueryResult<boolean, Error> => ({
|
||||
data,
|
||||
error: null,
|
||||
isPending: false,
|
||||
isError: false,
|
||||
isLoading: false,
|
||||
isLoadingError: false,
|
||||
isRefetchError: false,
|
||||
isSuccess: true,
|
||||
isPlaceholderData: false,
|
||||
isFetched: true,
|
||||
isFetchedAfterMount: true,
|
||||
isFetching: false,
|
||||
isInitialLoading: false,
|
||||
isPaused: false,
|
||||
isRefetching: false,
|
||||
isStale: false,
|
||||
status: 'success',
|
||||
dataUpdatedAt: Date.now(),
|
||||
errorUpdatedAt: Date.now(),
|
||||
failureCount: 0,
|
||||
failureReason: null,
|
||||
errorUpdateCount: 0,
|
||||
refetch: () => Promise.resolve(createSuccessfulQueryResult(data)),
|
||||
fetchStatus: 'idle',
|
||||
promise: Promise.resolve(data),
|
||||
});
|
||||
|
||||
describe('useOutboundMessageAccess', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return false if omnichannel is not enabled', () => {
|
||||
useOmnichannelEnabledMock.mockReturnValue(false);
|
||||
useHasLicenseModuleMock.mockReturnValue(createSuccessfulQueryResult(true));
|
||||
usePermissionMock.mockReturnValue(true);
|
||||
|
||||
const { result } = renderHook(() => useOutboundMessageAccess());
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true if omnichannel module is missing (upsell)', () => {
|
||||
useOmnichannelEnabledMock.mockReturnValue(true);
|
||||
useHasLicenseModuleMock.mockImplementation((module) => createSuccessfulQueryResult(module !== 'livechat-enterprise'));
|
||||
usePermissionMock.mockReturnValue(true);
|
||||
|
||||
const { result } = renderHook(() => useOutboundMessageAccess());
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if outbound module is missing (upsell)', () => {
|
||||
useOmnichannelEnabledMock.mockReturnValue(true);
|
||||
useHasLicenseModuleMock.mockImplementation((module) => createSuccessfulQueryResult(module !== 'outbound-messaging'));
|
||||
usePermissionMock.mockReturnValue(true);
|
||||
|
||||
const { result } = renderHook(() => useOutboundMessageAccess());
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if both modules are missing (upsell)', () => {
|
||||
useOmnichannelEnabledMock.mockReturnValue(true);
|
||||
useHasLicenseModuleMock.mockReturnValue(createSuccessfulQueryResult(false));
|
||||
usePermissionMock.mockReturnValue(true);
|
||||
|
||||
const { result } = renderHook(() => useOutboundMessageAccess());
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if all conditions are met and user has permission', () => {
|
||||
useOmnichannelEnabledMock.mockReturnValue(true);
|
||||
useHasLicenseModuleMock.mockReturnValue(createSuccessfulQueryResult(true));
|
||||
usePermissionMock.mockReturnValue(true);
|
||||
|
||||
const { result } = renderHook(() => useOutboundMessageAccess());
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if all conditions are met but user does not have permission', () => {
|
||||
useOmnichannelEnabledMock.mockReturnValue(true);
|
||||
useHasLicenseModuleMock.mockReturnValue(createSuccessfulQueryResult(true));
|
||||
usePermissionMock.mockReturnValue(false);
|
||||
|
||||
const { result } = renderHook(() => useOutboundMessageAccess());
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { usePermission } from '@rocket.chat/ui-contexts';
|
||||
|
||||
import { useHasLicenseModule } from '../../../../../hooks/useHasLicenseModule';
|
||||
import { useOmnichannelEnabled } from '../../../hooks/useOmnichannelEnabled';
|
||||
|
||||
export const useOutboundMessageAccess = (): boolean => {
|
||||
const isOmnichannelEnabled = useOmnichannelEnabled();
|
||||
const { data: hasOmnichannelModule = false } = useHasLicenseModule('livechat-enterprise');
|
||||
const { data: hasOutboundModule = false } = useHasLicenseModule('outbound-messaging');
|
||||
const hasPermission = usePermission('outbound.send-messages');
|
||||
|
||||
if (!isOmnichannelEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hasOmnichannelModule || !hasOutboundModule) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return hasPermission;
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { IOutboundProvider, Serialized } from '@rocket.chat/core-typings';
|
||||
import type { OperationResult } from '@rocket.chat/rest-typings';
|
||||
import { useEndpoint, usePermission } from '@rocket.chat/ui-contexts';
|
||||
import type { UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useHasLicenseModule } from '../../../../../hooks/useHasLicenseModule';
|
||||
import { omnichannelQueryKeys } from '../../../../../lib/queryKeys';
|
||||
import { useOmnichannelEnterpriseEnabled } from '../../../hooks/useOmnichannelEnterpriseEnabled';
|
||||
|
||||
type OutboundProvidersResponse = Serialized<OperationResult<'GET', '/v1/omnichannel/outbound/providers'>>;
|
||||
|
||||
type UseOutboundProvidersListProps<TData> = Omit<UseQueryOptions<OutboundProvidersResponse, Error, TData>, 'queryKey' | 'queryFn'> & {
|
||||
type?: IOutboundProvider['providerType'];
|
||||
};
|
||||
|
||||
const useOutboundProvidersList = <TData = OutboundProvidersResponse>(options?: UseOutboundProvidersListProps<TData>) => {
|
||||
const { type = 'phone', enabled = true, staleTime = 5 * 60 * 1000, ...queryOptions } = options || {};
|
||||
const getProviders = useEndpoint('GET', '/v1/omnichannel/outbound/providers');
|
||||
|
||||
const isOmnichannelEnabled = useOmnichannelEnterpriseEnabled();
|
||||
const { data: hasOutboundModule = false } = useHasLicenseModule('outbound-messaging');
|
||||
const canSendOutboundMessages = usePermission('outbound.send-messages');
|
||||
|
||||
return useQuery<OutboundProvidersResponse, Error, TData>({
|
||||
queryKey: omnichannelQueryKeys.outboundProviders({ type }),
|
||||
queryFn: () => getProviders({ type }),
|
||||
retry: 3,
|
||||
enabled: isOmnichannelEnabled && hasOutboundModule && canSendOutboundMessages && enabled,
|
||||
staleTime,
|
||||
...queryOptions,
|
||||
});
|
||||
};
|
||||
|
||||
export default useOutboundProvidersList;
|
||||
Reference in New Issue
Block a user