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
129 lines
3.9 KiB
TypeScript
129 lines
3.9 KiB
TypeScript
import { faker } from '@faker-js/faker';
|
|
import type { Credentials } from '@rocket.chat/api-client';
|
|
import { UserStatus, type ILivechatAgent, type IUser } from '@rocket.chat/core-typings';
|
|
import { Random } from '@rocket.chat/random';
|
|
|
|
import { api, credentials, request } from '../api-data';
|
|
import { password } from '../user';
|
|
import { createUser, login, setUserAway, setUserStatus } from '../users.helper';
|
|
import { createAgent, makeAgentAvailable, makeAgentUnavailable } from './rooms';
|
|
|
|
export const createBotAgent = async (): Promise<{
|
|
credentials: Credentials;
|
|
user: IUser;
|
|
}> => {
|
|
const agent = await createUser({
|
|
roles: ['bot'],
|
|
});
|
|
const createdUserCredentials = await login(agent.username, password);
|
|
await createAgent(agent.username);
|
|
await makeAgentAvailable(createdUserCredentials);
|
|
|
|
return {
|
|
credentials: createdUserCredentials,
|
|
user: agent,
|
|
};
|
|
};
|
|
|
|
export const getRandomVisitorToken = (): string => faker.string.alphanumeric(17);
|
|
|
|
export const getAgent = async (userId: string): Promise<ILivechatAgent> => {
|
|
const { body } = await request
|
|
.get(api(`livechat/users/agent/${userId}`))
|
|
.set(credentials)
|
|
.expect(200);
|
|
return body.user;
|
|
};
|
|
|
|
export const removeAgent = async (userId: string): Promise<void> => {
|
|
await request
|
|
.delete(api(`livechat/users/agent/${userId}`))
|
|
.set(credentials)
|
|
.expect(200);
|
|
};
|
|
|
|
export const createAgentAndReLogin = async (): Promise<{
|
|
credentials: Credentials;
|
|
user: IUser & { username: string };
|
|
}> => {
|
|
const username = `user.test.${Random.id()}`;
|
|
const email = `${username}@rocket.chat`;
|
|
const { body } = await request.post(api('users.create')).set(credentials).send({ email, name: username, username, password });
|
|
const agent = body.user;
|
|
const createdUserCredentials = await login(agent.username, password);
|
|
await createAgent(agent.username);
|
|
|
|
return {
|
|
credentials: createdUserCredentials,
|
|
user: agent,
|
|
};
|
|
};
|
|
|
|
export const createAnOnlineAgent = async (): Promise<{
|
|
credentials: Credentials;
|
|
user: IUser & { username: string };
|
|
}> => {
|
|
const { credentials: createdUserCredentials, user: agent } = await createAgentAndReLogin();
|
|
await makeAgentAvailable(createdUserCredentials);
|
|
|
|
return {
|
|
credentials: createdUserCredentials,
|
|
user: agent,
|
|
};
|
|
};
|
|
|
|
export const createAnOfflineAgent = async (): Promise<{
|
|
credentials: Credentials;
|
|
user: IUser & { username: string };
|
|
}> => {
|
|
const username = `user.test.${Date.now()}.offline`;
|
|
const email = `${username}.offline@rocket.chat`;
|
|
const { body } = await request.post(api('users.create')).set(credentials).send({ email, name: username, username, password });
|
|
const agent = body.user;
|
|
const createdUserCredentials = await login(agent.username, password);
|
|
await createAgent(agent.username);
|
|
await makeAgentUnavailable(createdUserCredentials);
|
|
|
|
return {
|
|
credentials: createdUserCredentials,
|
|
user: agent,
|
|
};
|
|
};
|
|
|
|
export const createAnAwayAgent = async (): Promise<{
|
|
credentials: Credentials;
|
|
user: IUser & { username: string };
|
|
}> => {
|
|
const username = `user.test.${Date.now()}.away`;
|
|
const email = `${username}.offline@rocket.chat`;
|
|
const { body } = await request.post(api('users.create')).set(credentials).send({ email, name: username, username, password });
|
|
const agent = body.user;
|
|
const createdUserCredentials = await login(agent.username, password);
|
|
await createAgent(agent.username);
|
|
await makeAgentAvailable(createdUserCredentials);
|
|
await setUserStatus(createdUserCredentials, UserStatus.AWAY);
|
|
await setUserAway(createdUserCredentials);
|
|
|
|
return {
|
|
credentials: createdUserCredentials,
|
|
user: agent,
|
|
};
|
|
};
|
|
|
|
export const updateLivechatSettingsForUser = async (
|
|
agentId: string,
|
|
livechatSettings: Record<string, any>,
|
|
agentDepartments: string[] = [],
|
|
): Promise<void> => {
|
|
await request
|
|
.post(api('livechat/agents.saveInfo'))
|
|
.set(credentials)
|
|
.send({
|
|
agentId,
|
|
agentData: livechatSettings,
|
|
agentDepartments,
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200);
|
|
};
|