Files
upstream-rocketchat/apps/meteor/client/views/room/hooks/useE2EEResetRoomKey.spec.ts
upstream-mirror 30810eecd7
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
Code scanning - action / CodeQL-Build (push) Failing after 2s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

111 lines
3.6 KiB
TypeScript

import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook, waitFor } from '@testing-library/react';
import { useE2EEResetRoomKey } from './useE2EEResetRoomKey';
import { e2e } from '../../../lib/e2ee';
jest.mock('../../../lib/e2ee', () => ({
e2e: {
getInstanceByRoomId: jest.fn(),
},
}));
describe('useE2EEResetRoomKey', () => {
const e2eResetRoomKeyMock = jest.fn().mockResolvedValue({
e2eKeyId: 'E2E_KEY_ID',
e2eKey: 'E2E_KEY',
});
const resetRoomKeyMock = jest.fn();
const roomId = 'ROOM_ID';
afterEach(() => {
jest.clearAllMocks();
});
beforeEach(() => {
(e2e.getInstanceByRoomId as jest.Mock).mockImplementation(() => ({
resetRoomKey: e2eResetRoomKeyMock,
}));
});
it('should call resetRoomKey endpoint with correct params', async () => {
const { result } = renderHook(() => useE2EEResetRoomKey(), {
wrapper: mockAppRoot().withEndpoint('POST', '/v1/e2e.resetRoomKey', resetRoomKeyMock).build(),
});
await waitFor(() => result.current.mutate({ roomId }));
expect(e2e.getInstanceByRoomId).toHaveBeenCalledTimes(1);
expect(e2e.getInstanceByRoomId).toHaveBeenCalledWith('ROOM_ID');
expect(e2eResetRoomKeyMock).toHaveBeenCalledTimes(1);
expect(resetRoomKeyMock).toHaveBeenCalledWith({
rid: roomId,
e2eKeyId: 'E2E_KEY_ID',
e2eKey: 'E2E_KEY',
});
await waitFor(() => expect(result.current.status).toBe('success'));
});
it('should return an errror if e2e.getInstanceByRoomId() does not return correct params', async () => {
(e2e.getInstanceByRoomId as jest.Mock).mockReturnValue(null);
const { result } = renderHook(() => useE2EEResetRoomKey(), {
wrapper: mockAppRoot().withEndpoint('POST', '/v1/e2e.resetRoomKey', resetRoomKeyMock).build(),
});
await waitFor(() => result.current.mutate({ roomId }));
expect(e2e.getInstanceByRoomId).toHaveBeenCalledTimes(1);
expect(e2e.getInstanceByRoomId).toHaveBeenCalledWith('ROOM_ID');
expect(e2eResetRoomKeyMock).toHaveBeenCalledTimes(0);
await waitFor(() => expect(result.current.status).toBe('error'));
});
it('should return an errror if e2e.resetRoomKey() does not return correct params', async () => {
const e2eResetRoomKeyMock = jest.fn().mockResolvedValue(null);
const roomId = 'ROOM_ID';
(e2e.getInstanceByRoomId as jest.Mock).mockImplementation(() => ({
resetRoomKey: e2eResetRoomKeyMock,
}));
const { result } = renderHook(() => useE2EEResetRoomKey(), {
wrapper: mockAppRoot().withEndpoint('POST', '/v1/e2e.resetRoomKey', resetRoomKeyMock).build(),
});
await waitFor(() => result.current.mutate({ roomId }));
expect(e2e.getInstanceByRoomId).toHaveBeenCalledTimes(1);
expect(e2e.getInstanceByRoomId).toHaveBeenCalledWith('ROOM_ID');
expect(e2eResetRoomKeyMock).toHaveBeenCalledTimes(1);
expect(resetRoomKeyMock).toHaveBeenCalledTimes(0);
await waitFor(() => expect(result.current.status).toBe('error'));
});
it('should return an error if resetRoomKey does not resolve', async () => {
resetRoomKeyMock.mockRejectedValue(new Error('error-e2e-key-reset-in-progress'));
const { result } = renderHook(() => useE2EEResetRoomKey(), {
wrapper: mockAppRoot().withEndpoint('POST', '/v1/e2e.resetRoomKey', resetRoomKeyMock).build(),
});
await waitFor(() => result.current.mutate({ roomId }));
expect(e2e.getInstanceByRoomId).toHaveBeenCalledTimes(1);
expect(e2e.getInstanceByRoomId).toHaveBeenCalledWith('ROOM_ID');
expect(e2eResetRoomKeyMock).toHaveBeenCalledTimes(1);
expect(resetRoomKeyMock).toHaveBeenCalledWith({
rid: roomId,
e2eKeyId: 'E2E_KEY_ID',
e2eKey: 'E2E_KEY',
});
await waitFor(() => expect(result.current.status).toBe('error'));
});
});