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
209 lines
6.7 KiB
TypeScript
209 lines
6.7 KiB
TypeScript
import { faker } from '@faker-js/faker';
|
|
import { request as baseRequest } from '@playwright/test';
|
|
import type { IRoom, IMessage } from '@rocket.chat/core-typings';
|
|
import type { ChannelsCreateProps, GroupsCreateProps } from '@rocket.chat/rest-typings';
|
|
|
|
import type { BaseTest } from './test';
|
|
import { BASE_API_URL } from '../config/constants';
|
|
|
|
/**
|
|
* createTargetChannel:
|
|
* - Usefull to create a target channel for message related tests
|
|
*/
|
|
export async function createTargetChannel(api: BaseTest['api'], options?: Omit<ChannelsCreateProps, 'name'>): Promise<string> {
|
|
const name = faker.string.uuid();
|
|
await api.post('/channels.create', { name, ...options });
|
|
|
|
return name;
|
|
}
|
|
|
|
export async function createTargetChannelAndReturnFullRoom(
|
|
api: BaseTest['api'],
|
|
options?: Omit<ChannelsCreateProps, 'name'>,
|
|
): Promise<{ channel: IRoom }> {
|
|
const name = faker.string.uuid();
|
|
return (await api.post('/channels.create', { name, ...options })).json();
|
|
}
|
|
|
|
export async function sendTargetChannelMessage(api: BaseTest['api'], roomName: string, options?: Partial<IMessage>) {
|
|
const response = await api.get(`/channels.info?roomName=${roomName}`);
|
|
|
|
const {
|
|
channel: { _id: rid },
|
|
}: { channel: IRoom } = await response.json();
|
|
|
|
await api.post('/chat.sendMessage', {
|
|
message: {
|
|
rid,
|
|
msg: options?.msg || 'simple message',
|
|
...options,
|
|
},
|
|
});
|
|
|
|
return options?.msg || 'simple message';
|
|
}
|
|
|
|
export async function deleteChannel(api: BaseTest['api'], roomName: string): Promise<void> {
|
|
await api.post('/channels.delete', { roomName });
|
|
}
|
|
|
|
export async function isChannelMember(api: BaseTest['api'], roomName: string, username: string): Promise<boolean> {
|
|
const response = await api.get(`/channels.members?roomName=${roomName}`);
|
|
const { members }: { members: { username: string }[] } = await response.json();
|
|
return members.some((member) => member.username === username);
|
|
}
|
|
|
|
export async function deleteRoom(api: BaseTest['api'], roomId: string): Promise<void> {
|
|
await api.post('/rooms.delete', { roomId });
|
|
}
|
|
|
|
export async function deletePrivateRoomsByName(credentials: { username: string; password: string }, roomNames: string[]): Promise<void> {
|
|
const userApi = await baseRequest.newContext();
|
|
|
|
try {
|
|
const loginResponse = await userApi.post(`${BASE_API_URL}/login`, { data: credentials });
|
|
|
|
if (!loginResponse.ok()) {
|
|
return;
|
|
}
|
|
|
|
const { data } = await loginResponse.json();
|
|
await Promise.allSettled(
|
|
roomNames.map((roomName) =>
|
|
userApi.post(`${BASE_API_URL}/groups.delete`, {
|
|
data: { roomName },
|
|
headers: {
|
|
'X-Auth-Token': data.authToken,
|
|
'X-User-Id': data.userId,
|
|
},
|
|
}),
|
|
),
|
|
);
|
|
} finally {
|
|
await userApi.dispose();
|
|
}
|
|
}
|
|
|
|
export async function markRoomAsRead(api: BaseTest['api'], roomId: string): Promise<void> {
|
|
await api.post('/subscriptions.read', { rid: roomId });
|
|
}
|
|
|
|
export async function createTargetPrivateChannel(api: BaseTest['api'], options?: Omit<GroupsCreateProps, 'name'>): Promise<string> {
|
|
const name = faker.string.uuid();
|
|
await api.post('/groups.create', { name, ...options });
|
|
|
|
return name;
|
|
}
|
|
|
|
export async function createTargetTeam(api: BaseTest['api'], options?: Omit<GroupsCreateProps, 'name'>): Promise<string> {
|
|
const name = faker.string.uuid();
|
|
await api.post('/teams.create', { name, type: 1, members: ['user2', 'user1'], ...options });
|
|
|
|
return name;
|
|
}
|
|
|
|
export async function deleteTeam(api: BaseTest['api'], teamName: string): Promise<void> {
|
|
await api.post('/teams.delete', { teamName });
|
|
}
|
|
|
|
export async function createDirectMessage(api: BaseTest['api']): Promise<void> {
|
|
await api.post('/dm.create', {
|
|
usernames: 'user1,user2',
|
|
});
|
|
}
|
|
|
|
export async function createTargetDiscussion(api: BaseTest['api']): Promise<Record<string, string>> {
|
|
const channelName = faker.string.uuid();
|
|
const discussionName = faker.string.uuid();
|
|
|
|
const channelResponse = await api.post('/channels.create', { name: channelName });
|
|
const { channel } = await channelResponse.json();
|
|
const discussionResponse = await api.post('/rooms.createDiscussion', { t_name: discussionName, prid: channel._id });
|
|
const { discussion } = await discussionResponse.json();
|
|
|
|
if (!discussion) {
|
|
throw new Error('Discussion not created');
|
|
}
|
|
|
|
return discussion;
|
|
}
|
|
|
|
export async function createChannelWithTeam(api: BaseTest['api']): Promise<Record<string, string>> {
|
|
const channelName = faker.string.uuid();
|
|
const teamName = faker.string.uuid();
|
|
|
|
const teamResponse = await api.post('/teams.create', { name: teamName, type: 1, members: ['user2'] });
|
|
const { team } = await teamResponse.json();
|
|
|
|
await api.post('/channels.create', { name: channelName, members: ['user1'], extraData: { teamId: team._id } });
|
|
|
|
return { channelName, teamName };
|
|
}
|
|
|
|
export async function createArchivedChannel(api: BaseTest['api']): Promise<string> {
|
|
const { channel } = await createTargetChannelAndReturnFullRoom(api);
|
|
|
|
try {
|
|
await api.post('/channels.archive', { roomId: channel._id });
|
|
} catch (error) {
|
|
throw new Error(`Error archiving the channel: ${error}`);
|
|
}
|
|
|
|
if (!channel.name) {
|
|
throw new Error('Invalid channel was created');
|
|
}
|
|
|
|
return channel.name;
|
|
}
|
|
|
|
export async function createTargetGroupAndReturnFullRoom(
|
|
api: BaseTest['api'],
|
|
options?: Omit<GroupsCreateProps, 'name'>,
|
|
): Promise<{ group: IRoom }> {
|
|
const name = faker.string.uuid();
|
|
return (await api.post('/groups.create', { name, ...options })).json();
|
|
}
|
|
|
|
export async function sendMessage(api: BaseTest['api'], roomId: string, msg: string, threadId?: string): Promise<string> {
|
|
const payload: { message: { rid: string; msg: string; tmid?: string } } = { message: { rid: roomId, msg } };
|
|
if (threadId) {
|
|
payload.message.tmid = threadId;
|
|
}
|
|
|
|
const response = await api.post('/chat.sendMessage', payload);
|
|
const data: { success?: boolean; message?: { _id: string } } = await response.json();
|
|
|
|
if (!data.success || !data.message?._id) {
|
|
throw new Error(`Error sending message: ${JSON.stringify(data)}`);
|
|
}
|
|
|
|
return data.message._id;
|
|
}
|
|
|
|
export async function createDiscussion(api: BaseTest['api'], parentRoomId: string, parentMessageId: string, name: string): Promise<string> {
|
|
const response = await api.post('/rooms.createDiscussion', {
|
|
prid: parentRoomId,
|
|
pmid: parentMessageId,
|
|
t_name: name,
|
|
});
|
|
|
|
const data: { success?: boolean; discussion?: { _id: string } } = await response.json();
|
|
|
|
if (!data.discussion?._id) {
|
|
throw new Error(`Error creating discussion: ${JSON.stringify(data)}`);
|
|
}
|
|
|
|
return data.discussion._id;
|
|
}
|
|
|
|
export async function createDirectMessageRoom(api: BaseTest['api'], username: string): Promise<string> {
|
|
const response = await api.post('/im.create', { username });
|
|
const data: { success?: boolean; room?: { _id: string } } = await response.json();
|
|
|
|
if (!data.room?._id) {
|
|
throw new Error(`Error creating direct message room: ${JSON.stringify(data)}`);
|
|
}
|
|
|
|
return data.room._id;
|
|
}
|