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 2s
383 lines
13 KiB
TypeScript
383 lines
13 KiB
TypeScript
import { expect } from 'chai';
|
|
import { after, afterEach, before, describe, it } from 'mocha';
|
|
import type { Response } from 'supertest';
|
|
|
|
import { getCredentials, api, request, credentials } from '../../data/api-data';
|
|
import { updatePermission } from '../../data/permissions.helper';
|
|
import { password } from '../../data/user';
|
|
import { createUser, deleteUser, login } from '../../data/users.helper';
|
|
|
|
async function createCustomUserStatus(name: string, statusType?: string): Promise<string> {
|
|
const res = await request.post(api('custom-user-status.create')).set(credentials).send({ name, statusType }).expect(200);
|
|
return res.body.customUserStatus._id;
|
|
}
|
|
|
|
async function deleteCustomUserStatus(id: string): Promise<void> {
|
|
await request.post(api('custom-user-status.delete')).set(credentials).send({ customUserStatusId: id }).expect(200);
|
|
}
|
|
|
|
describe('[CustomUserStatus]', () => {
|
|
let unauthorizedUser: any;
|
|
let unauthorizedUserCredentials: any;
|
|
|
|
before((done) => {
|
|
getCredentials(done);
|
|
});
|
|
|
|
before(async () => {
|
|
unauthorizedUser = await createUser();
|
|
unauthorizedUserCredentials = await login(unauthorizedUser.username, password);
|
|
});
|
|
|
|
after(() => Promise.all([updatePermission('manage-user-status', ['admin']), deleteUser(unauthorizedUser)]));
|
|
|
|
describe('[/custom-user-status.list]', () => {
|
|
let customUserStatusId: string;
|
|
let customUserStatusName: string;
|
|
|
|
before(async () => {
|
|
customUserStatusName = `test-${Date.now()}`;
|
|
customUserStatusId = await createCustomUserStatus(customUserStatusName);
|
|
});
|
|
|
|
after(async () => {
|
|
await deleteCustomUserStatus(customUserStatusId);
|
|
});
|
|
|
|
it('should return custom user status', async () => {
|
|
const res = await request.get(api('custom-user-status.list')).set(credentials).expect(200);
|
|
|
|
expect(res.body).to.have.property('statuses').and.to.be.an('array');
|
|
expect(res.body).to.have.property('total');
|
|
expect(res.body).to.have.property('offset');
|
|
expect(res.body).to.have.property('count');
|
|
});
|
|
|
|
it('should return custom user status even requested with count and offset params', async () => {
|
|
const res = await request.get(api('custom-user-status.list')).set(credentials).expect(200).query({
|
|
count: 5,
|
|
offset: 0,
|
|
});
|
|
|
|
expect(res.body).to.have.property('statuses').and.to.be.an('array');
|
|
expect(res.body).to.have.property('total');
|
|
expect(res.body).to.have.property('offset');
|
|
expect(res.body).to.have.property('count');
|
|
});
|
|
|
|
it('should return one custom user status when requested with id param', async () => {
|
|
const res = await request.get(api('custom-user-status.list')).set(credentials).expect(200).query({
|
|
_id: customUserStatusId,
|
|
});
|
|
|
|
expect(res.body).to.have.property('statuses').and.to.be.an('array').and.to.have.lengthOf(1);
|
|
expect(res.body).to.have.property('total').and.to.equal(1);
|
|
expect(res.body).to.have.property('offset').and.to.equal(0);
|
|
expect(res.body).to.have.property('count').and.to.equal(1);
|
|
});
|
|
|
|
it('should return empty array when requested with an existing name param', async () => {
|
|
const res = await request.get(api('custom-user-status.list')).set(credentials).expect(200).query({
|
|
name: customUserStatusName,
|
|
});
|
|
|
|
expect(res.body).to.have.property('statuses').and.to.be.an('array').and.to.have.lengthOf(1);
|
|
expect(res.body).to.have.property('total').and.to.equal(1);
|
|
expect(res.body).to.have.property('offset').and.to.equal(0);
|
|
expect(res.body).to.have.property('count').and.to.equal(1);
|
|
});
|
|
|
|
it('should return empty array when requested with unknown name param', async () => {
|
|
const res = await request.get(api('custom-user-status.list')).set(credentials).expect(200).query({
|
|
name: 'testxxx',
|
|
});
|
|
|
|
expect(res.body).to.have.property('statuses').and.to.be.an('array').and.to.have.lengthOf(0);
|
|
expect(res.body).to.have.property('total').and.to.equal(0);
|
|
expect(res.body).to.have.property('offset').and.to.equal(0);
|
|
expect(res.body).to.have.property('count').and.to.equal(0);
|
|
});
|
|
});
|
|
|
|
describe('[/custom-user-status.create]', () => {
|
|
let customUserStatusId: string;
|
|
|
|
afterEach(async () => {
|
|
await updatePermission('manage-user-status', ['admin']);
|
|
|
|
if (customUserStatusId) {
|
|
await deleteCustomUserStatus(customUserStatusId);
|
|
customUserStatusId = '';
|
|
}
|
|
});
|
|
|
|
it('should throw an error if not authenticated', async () => {
|
|
await request
|
|
.post(api('custom-user-status.create'))
|
|
.send({ name: 'test-status' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(401)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('status', 'error');
|
|
});
|
|
});
|
|
|
|
it('should throw an error if user does not have manage-user-status permission', async () => {
|
|
await updatePermission('manage-user-status', []);
|
|
|
|
await request
|
|
.post(api('custom-user-status.create'))
|
|
.set(unauthorizedUserCredentials)
|
|
.send({ name: 'test-status' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('errorType', 'not_authorized');
|
|
});
|
|
});
|
|
|
|
it('should create a custom user status successfully', async () => {
|
|
const statusName = `test-create-${Date.now()}`;
|
|
|
|
await request
|
|
.post(api('custom-user-status.create'))
|
|
.set(credentials)
|
|
.send({ name: statusName, statusType: 'busy' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', true);
|
|
expect(res.body).to.have.property('customUserStatus');
|
|
expect(res.body.customUserStatus).to.have.property('_id');
|
|
expect(res.body.customUserStatus).to.have.property('name', statusName);
|
|
expect(res.body.customUserStatus).to.have.property('statusType', 'busy');
|
|
customUserStatusId = res.body.customUserStatus._id;
|
|
});
|
|
});
|
|
|
|
it('should throw an error if name already exists', async () => {
|
|
const statusName = `test-duplicate-${Date.now()}`;
|
|
customUserStatusId = await createCustomUserStatus(statusName);
|
|
|
|
await request
|
|
.post(api('custom-user-status.create'))
|
|
.set(credentials)
|
|
.send({ name: statusName })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('errorType', 'Custom_User_Status_Error_Name_Already_In_Use');
|
|
});
|
|
});
|
|
|
|
it('should throw an error if statusType is invalid', async () => {
|
|
await request
|
|
.post(api('custom-user-status.create'))
|
|
.set(credentials)
|
|
.send({ name: `test-invalid-status-type-${Date.now()}`, statusType: 'invalid' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('errorType', 'error-input-is-not-a-valid-field');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('[/custom-user-status.update]', () => {
|
|
let customUserStatusId: string;
|
|
let customUserStatusName: string;
|
|
|
|
before(async () => {
|
|
customUserStatusName = `test-update-${Date.now()}`;
|
|
customUserStatusId = await createCustomUserStatus(customUserStatusName);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await updatePermission('manage-user-status', ['admin']);
|
|
});
|
|
|
|
after(async () => {
|
|
if (customUserStatusId) {
|
|
await deleteCustomUserStatus(customUserStatusId);
|
|
}
|
|
await updatePermission('manage-user-status', ['admin']);
|
|
});
|
|
|
|
it('should throw an error if not authenticated', async () => {
|
|
await request
|
|
.post(api('custom-user-status.update'))
|
|
.send({ _id: customUserStatusId, name: 'updated-name' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(401)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('status', 'error');
|
|
});
|
|
});
|
|
|
|
it('should throw an error if user does not have manage-user-status permission', async () => {
|
|
await updatePermission('manage-user-status', []);
|
|
|
|
await request
|
|
.post(api('custom-user-status.update'))
|
|
.set(unauthorizedUserCredentials)
|
|
.send({ _id: customUserStatusId, name: 'updated-name' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('errorType', 'not_authorized');
|
|
});
|
|
});
|
|
|
|
it('should throw an error if custom user status does not exist', async () => {
|
|
await request
|
|
.post(api('custom-user-status.update'))
|
|
.set(credentials)
|
|
.send({ _id: 'invalid-id', name: 'updated-name' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
});
|
|
});
|
|
|
|
it('should update custom user status successfully', async () => {
|
|
const newName = `test-updated-${Date.now()}`;
|
|
|
|
await request
|
|
.post(api('custom-user-status.update'))
|
|
.set(credentials)
|
|
.send({ _id: customUserStatusId, name: newName, statusType: 'away' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', true);
|
|
expect(res.body).to.have.property('customUserStatus');
|
|
expect(res.body.customUserStatus).to.have.property('_id', customUserStatusId);
|
|
expect(res.body.customUserStatus).to.have.property('name', newName);
|
|
expect(res.body.customUserStatus).to.have.property('statusType', 'away');
|
|
});
|
|
|
|
customUserStatusName = newName;
|
|
});
|
|
|
|
it('should throw an error if status name already exists', async () => {
|
|
const existingStatusName = `test-update-duplicate-${Date.now()}`;
|
|
const existingStatusId = await createCustomUserStatus(existingStatusName);
|
|
|
|
await request
|
|
.post(api('custom-user-status.update'))
|
|
.set(credentials)
|
|
.send({ _id: customUserStatusId, name: existingStatusName })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('errorType', 'Custom_User_Status_Error_Name_Already_In_Use');
|
|
});
|
|
|
|
await deleteCustomUserStatus(existingStatusId);
|
|
});
|
|
|
|
it('should throw an error if statusType is invalid', async () => {
|
|
await request
|
|
.post(api('custom-user-status.update'))
|
|
.set(credentials)
|
|
.send({ _id: customUserStatusId, name: customUserStatusName, statusType: 'invalid' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('errorType', 'error-input-is-not-a-valid-field');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('[/custom-user-status.delete]', () => {
|
|
let customUserStatusId: string;
|
|
|
|
beforeEach(async () => {
|
|
const statusName = `test-delete-${Date.now()}`;
|
|
customUserStatusId = await createCustomUserStatus(statusName);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await updatePermission('manage-user-status', ['admin']);
|
|
|
|
if (customUserStatusId) {
|
|
await deleteCustomUserStatus(customUserStatusId);
|
|
customUserStatusId = '';
|
|
}
|
|
});
|
|
|
|
it('should throw an error if not authenticated', async () => {
|
|
await request
|
|
.post(api('custom-user-status.delete'))
|
|
.send({ customUserStatusId })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(401)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('status', 'error');
|
|
});
|
|
});
|
|
|
|
it('should throw an error if user does not have manage-user-status permission', async () => {
|
|
await updatePermission('manage-user-status', []);
|
|
|
|
await request
|
|
.post(api('custom-user-status.delete'))
|
|
.set(unauthorizedUserCredentials)
|
|
.send({ customUserStatusId })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('errorType', 'not_authorized');
|
|
});
|
|
});
|
|
|
|
it('should throw an error if customUserStatusId is not provided', async () => {
|
|
await request
|
|
.post(api('custom-user-status.delete'))
|
|
.set(credentials)
|
|
.send({})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('error', "must have required property 'customUserStatusId'");
|
|
});
|
|
});
|
|
|
|
it('should throw an error if custom user status does not exist', async () => {
|
|
await request
|
|
.post(api('custom-user-status.delete'))
|
|
.set(credentials)
|
|
.send({ customUserStatusId: 'invalid-id' })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('errorType', 'Custom_User_Status_Error_Invalid_User_Status');
|
|
});
|
|
});
|
|
|
|
it('should delete custom user status successfully', async () => {
|
|
await request
|
|
.post(api('custom-user-status.delete'))
|
|
.set(credentials)
|
|
.send({ customUserStatusId })
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', true);
|
|
});
|
|
|
|
customUserStatusId = '';
|
|
});
|
|
});
|
|
});
|