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:
113
apps/meteor/client/startup/slashCommands/topic.spec.ts
Normal file
113
apps/meteor/client/startup/slashCommands/topic.spec.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
import { clientCallbacks } from '@rocket.chat/ui-client';
|
||||
|
||||
import { createFakeRoom } from '../../../tests/mocks/data';
|
||||
import { sdk } from '../../lib/SDKClient';
|
||||
import { hasPermission } from '../../lib/authorization';
|
||||
import { slashCommands } from '../../lib/slashCommand';
|
||||
import { dispatchToastMessage } from '../../lib/toast';
|
||||
import { Rooms } from '../../stores';
|
||||
|
||||
import './topic';
|
||||
|
||||
jest.mock('@rocket.chat/ui-client', () => ({
|
||||
clientCallbacks: {
|
||||
run: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../lib/SDKClient', () => ({
|
||||
sdk: {
|
||||
rest: {
|
||||
post: jest.fn(),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../lib/authorization', () => ({
|
||||
hasPermission: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('../../lib/toast', () => ({
|
||||
dispatchToastMessage: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('../../stores', () => ({
|
||||
Rooms: {
|
||||
state: {
|
||||
get: jest.fn(),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
const post = jest.mocked(sdk.rest.post);
|
||||
const checkPermission = jest.mocked(hasPermission);
|
||||
const runClientCallback = jest.mocked(clientCallbacks.run);
|
||||
const showToast = jest.mocked(dispatchToastMessage);
|
||||
const getRoom = jest.mocked(Rooms.state.get);
|
||||
|
||||
const room = createFakeRoom({ _id: 'room-id', t: 'c', name: 'general' });
|
||||
|
||||
const getCallback = () => {
|
||||
const { callback } = slashCommands.commands.topic;
|
||||
expect(callback).toBeDefined();
|
||||
return callback as NonNullable<typeof callback>;
|
||||
};
|
||||
|
||||
const runCommand = (params = 'New topic') =>
|
||||
getCallback()({
|
||||
command: 'topic',
|
||||
params,
|
||||
message: { _id: 'message-id', rid: 'room-id' },
|
||||
userId: 'user-id',
|
||||
});
|
||||
|
||||
describe('/topic slash command', () => {
|
||||
beforeEach(() => {
|
||||
checkPermission.mockReturnValue(true);
|
||||
post.mockResolvedValue({} as never);
|
||||
runClientCallback.mockResolvedValue(undefined);
|
||||
getRoom.mockReturnValue(room);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('updates the topic when the user has permission', async () => {
|
||||
await runCommand('Updated topic');
|
||||
|
||||
expect(checkPermission).toHaveBeenCalledWith('edit-room', 'room-id');
|
||||
expect(post).toHaveBeenCalledWith('/v1/rooms.saveRoomSettings', {
|
||||
rid: 'room-id',
|
||||
roomTopic: 'Updated topic',
|
||||
});
|
||||
});
|
||||
|
||||
it('does not call the API when permission is missing', async () => {
|
||||
checkPermission.mockReturnValue(false);
|
||||
|
||||
await runCommand();
|
||||
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
expect(runClientCallback).not.toHaveBeenCalled();
|
||||
expect(getRoom).not.toHaveBeenCalled();
|
||||
expect(showToast).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('runs the roomTopicChanged callback after a successful update', async () => {
|
||||
await runCommand();
|
||||
|
||||
expect(runClientCallback).toHaveBeenCalledWith('roomTopicChanged', room);
|
||||
expect(post.mock.invocationCallOrder[0]).toBeLessThan(runClientCallback.mock.invocationCallOrder[0]);
|
||||
});
|
||||
|
||||
it('displays an error toast and propagates the REST API error when the update fails', async () => {
|
||||
const error = new Error('Failed to update topic');
|
||||
post.mockRejectedValue(error);
|
||||
|
||||
await expect(runCommand()).rejects.toBe(error);
|
||||
expect(showToast).toHaveBeenCalledWith({ type: 'error', message: error });
|
||||
expect(runClientCallback).not.toHaveBeenCalled();
|
||||
expect(getRoom).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user