Files
upstream-rocketchat/apps/meteor/tests/end-to-end/api/livechat/20-messages.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
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (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

125 lines
4.4 KiB
TypeScript

import { faker } from '@faker-js/faker';
import type { ILivechatAgent, ILivechatVisitor, IOmnichannelRoom, IRoom } from '@rocket.chat/core-typings';
import { expect } from 'chai';
import { before, describe, it, after } from 'mocha';
import { api, getCredentials, request } from '../../../data/api-data';
import { sendSimpleMessage } from '../../../data/chat.helper';
import {
sendMessage,
startANewLivechatRoomAndTakeIt,
sendAgentMessage,
createAgent,
makeAgentAvailable,
uploadFile,
closeOmnichannelRoom,
} from '../../../data/livechat/rooms';
import { removeAgent } from '../../../data/livechat/users';
import { updateEESetting, updateSetting } from '../../../data/permissions.helper';
import { createRoom, deleteRoom } from '../../../data/rooms.helper';
describe('LIVECHAT - messages', () => {
let agent: ILivechatAgent;
before((done) => getCredentials(done));
before(async () => {
agent = await createAgent();
await makeAgentAvailable();
await updateSetting('Livechat_Routing_Method', 'Manual_Selection');
await updateEESetting('Livechat_Require_Contact_Verification', 'never');
});
after(() => Promise.all([updateSetting('Livechat_Routing_Method', 'Auto_Selection'), removeAgent(agent._id)]));
describe('Quote message feature for visitors', () => {
it('it should verify if visitor can quote message', async () => {
const {
room: { _id: roomId },
visitor: { token },
} = await startANewLivechatRoomAndTakeIt();
await sendMessage(roomId, 'Hello from visitor', token);
const agentMsgSentence = faker.lorem.sentence();
const agentMsg = await sendAgentMessage(roomId, agentMsgSentence);
const siteUrl = process.env.SITE_URL || process.env.TEST_API_URL || 'http://localhost:3000';
const msgLink = `${siteUrl}/live/${roomId}?msg=${agentMsg._id}`;
const quotedMsgSentence = faker.lorem.sentence();
const wholeQuotedMsg = `[${quotedMsgSentence}](${msgLink})`;
const quotedMessage = await sendMessage(roomId, wholeQuotedMsg, token);
expect(quotedMessage).to.have.property('_id');
expect(quotedMessage).to.have.property('msg').that.is.equal(wholeQuotedMsg);
expect(quotedMessage).to.have.property('attachments');
expect(quotedMessage.attachments).to.be.an('array').that.has.lengthOf(1);
const quotedMessageAttachments = quotedMessage.attachments?.[0];
if (quotedMessageAttachments) {
expect(quotedMessageAttachments).to.have.property('message_link').that.is.equal(msgLink);
expect(quotedMessageAttachments).to.have.property('text').that.is.equal(agentMsgSentence);
}
});
it('should verify if visitor is receiving a message with a image attachment', async () => {
const {
room: { _id: roomId },
visitor: { token },
} = await startANewLivechatRoomAndTakeIt();
const imgMessage = await uploadFile(roomId, token);
expect(imgMessage).to.have.property('files').that.is.an('array');
expect(imgMessage.files?.[0]).to.have.keys('_id', 'name', 'type');
expect(imgMessage).to.have.property('file').that.deep.equal(imgMessage?.files?.[0]);
});
});
describe('Livechat Messages', async () => {
let room: IOmnichannelRoom;
let privateRoom: IRoom;
let visitor: ILivechatVisitor;
before(async () => {
await updateSetting('Livechat_Routing_Method', 'Auto_Selection');
const data = await startANewLivechatRoomAndTakeIt();
visitor = data.visitor;
room = data.room;
const response = await createRoom({ type: 'p', name: `private-room-${Math.random()}` } as any);
privateRoom = response.body.group;
});
after(() => Promise.all([closeOmnichannelRoom(room._id), deleteRoom({ roomId: privateRoom._id, type: 'p' })]));
it('should not allow fetching arbitrary messages from another channel', async () => {
const response = await sendSimpleMessage({ roomId: privateRoom._id } as any);
const { message } = response.body;
await request
.get(api(`livechat/message/${message._id}`))
.query({ token: visitor.token, rid: room._id })
.send()
.expect(400)
.expect((res) => {
expect(res.body.error).to.be.equal('invalid-message');
});
});
it('should allow fetching messages using their _id and roomId', async () => {
const message = await sendMessage(room._id, 'Hello from visitor', visitor.token);
await request
.get(api(`livechat/message/${message._id}`))
.query({ token: visitor.token, rid: room._id })
.send()
.expect(200)
.expect((res) => {
expect(res.body.message._id).to.be.equal(message._id);
});
});
});
});