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:
814
apps/meteor/tests/end-to-end/api/moderation.ts
Normal file
814
apps/meteor/tests/end-to-end/api/moderation.ts
Normal file
@@ -0,0 +1,814 @@
|
||||
import type { IMessage, IModerationAudit, IModerationReport, IUser } from '@rocket.chat/core-typings';
|
||||
import { expect } from 'chai';
|
||||
import { after, before, describe, it } from 'mocha';
|
||||
import type { Response } from 'supertest';
|
||||
|
||||
import { getCredentials, api, request, credentials } from '../../data/api-data';
|
||||
import { createUser, deleteUser } from '../../data/users.helper';
|
||||
|
||||
const makeModerationApiRequest = async (
|
||||
url: 'moderation.reportUser' | 'moderation.user.reportsByUserId',
|
||||
method: 'get' | 'post',
|
||||
data?: any,
|
||||
) => {
|
||||
let res: any;
|
||||
|
||||
if (method === 'get') {
|
||||
res = await request.get(api(url)).set(credentials).query(data);
|
||||
} else if (method === 'post') {
|
||||
res = await request.post(api(url)).set(credentials).send(data);
|
||||
}
|
||||
|
||||
return res.body;
|
||||
};
|
||||
|
||||
const reportUser = (userId: string, reason: string) => makeModerationApiRequest('moderation.reportUser', 'post', { userId, reason });
|
||||
|
||||
const getUsersReports = (userId: string) => makeModerationApiRequest('moderation.user.reportsByUserId', 'get', { userId });
|
||||
|
||||
describe('[Moderation]', () => {
|
||||
before((done) => getCredentials(done));
|
||||
|
||||
describe('[/moderation.reportsByUsers]', () => {
|
||||
it('should return an array of reports', async () => {
|
||||
await request
|
||||
.get(api('moderation.reportsByUsers'))
|
||||
.set(credentials)
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an array of reports even requested with count and offset params', async () => {
|
||||
await request
|
||||
.get(api('moderation.reportsByUsers'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
count: 5,
|
||||
offset: 0,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an array of reports even requested with oldest param', async () => {
|
||||
await request
|
||||
.get(api('moderation.reportsByUsers'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
oldest: new Date(),
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an array of reports even requested with latest param', async () => {
|
||||
await request
|
||||
.get(api('moderation.reportsByUsers'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
latest: new Date(),
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('[/moderation.userReports]', () => {
|
||||
it('should return an array of reports', async () => {
|
||||
await request
|
||||
.get(api('moderation.userReports'))
|
||||
.set(credentials)
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an array of reports even requested with count and offset params', async () => {
|
||||
await request
|
||||
.get(api('moderation.userReports'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
count: 5,
|
||||
offset: 0,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an array of reports even requested with oldest param', async () => {
|
||||
await request
|
||||
.get(api('moderation.userReports'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
oldest: new Date(),
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an array of reports even requested with latest param', async () => {
|
||||
await request
|
||||
.get(api('moderation.userReports'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
latest: new Date(),
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// test for testing out the moderation.dismissReports endpoint
|
||||
|
||||
describe('[/moderation.dismissReports]', () => {
|
||||
let reportedMessage: IModerationAudit;
|
||||
let message: IMessage;
|
||||
|
||||
// post a new message to the channel 'general' by sending a request to chat.postMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.sendMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
message: {
|
||||
rid: 'GENERAL',
|
||||
msg: 'Sample message 0',
|
||||
},
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
message = res.body.message;
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await request
|
||||
.post(api('chat.reportMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
messageId: message._id,
|
||||
description: 'sample report',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await request
|
||||
.get(api('moderation.reportsByUsers'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
count: 5,
|
||||
offset: 0,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
reportedMessage = res.body.reports[0];
|
||||
});
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await request
|
||||
.post(api('chat.delete'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
roomId: 'GENERAL',
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should hide reports of a user', async () => {
|
||||
await request
|
||||
.post(api('moderation.dismissReports'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
userId: reportedMessage.userId,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should hide reports of a message', async () => {
|
||||
await request
|
||||
.post(api('moderation.dismissReports'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the userId && msgId is not provided', async () => {
|
||||
await request
|
||||
.post(api('moderation.dismissReports'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
userId: '',
|
||||
msgId: '',
|
||||
})
|
||||
.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').and.to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('[/moderation.user.reportsByUserId]', () => {
|
||||
let reportedUser: IUser;
|
||||
|
||||
before(async () => {
|
||||
reportedUser = await createUser();
|
||||
await reportUser(reportedUser._id, 'sample report');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await deleteUser(reportedUser);
|
||||
});
|
||||
|
||||
it('should return an array of reports', async () => {
|
||||
await request
|
||||
.get(api('moderation.user.reportsByUserId'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
userId: reportedUser._id,
|
||||
count: 5,
|
||||
offset: 0,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect(async (res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array').and.to.have.lengthOf(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the userId is not provided', async () => {
|
||||
await request
|
||||
.get(api('moderation.user.reportsByUserId'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
userId: '',
|
||||
count: 5,
|
||||
offset: 0,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(400)
|
||||
.expect(async (res: Response) => {
|
||||
expect(res.body).to.have.property('success', false);
|
||||
expect(res.body).to.have.property('error');
|
||||
expect(res.body).to.have.property('errorType', 'invalid-params');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('[/moderation.dismissUserReports', () => {
|
||||
let reportedUser: IUser;
|
||||
|
||||
before(async () => {
|
||||
reportedUser = await createUser();
|
||||
await reportUser(reportedUser._id, 'sample report');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await deleteUser(reportedUser);
|
||||
});
|
||||
|
||||
it('should hide reports of a user', async () => {
|
||||
await request
|
||||
.post(api('moderation.dismissUserReports'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
userId: reportedUser._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
|
||||
await getUsersReports(reportedUser._id).then((res) => {
|
||||
expect(res.reports).to.have.lengthOf(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the userId is not provided', async () => {
|
||||
await request
|
||||
.post(api('moderation.dismissUserReports'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
userId: '',
|
||||
})
|
||||
.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').and.to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// test for testing out the moderation.reports endpoint
|
||||
|
||||
describe('[/moderation.reports]', () => {
|
||||
let message: IMessage;
|
||||
|
||||
// post a new message to the channel 'general' by sending a request to chat.postMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.postMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
channel: 'general',
|
||||
text: 'messageId',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('message').and.to.be.an('object');
|
||||
message = res.body.message;
|
||||
});
|
||||
});
|
||||
|
||||
// create a reported message by sending a request to chat.reportMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.reportMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
messageId: message._id,
|
||||
description: 'sample report',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await request
|
||||
.post(api('chat.delete'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
roomId: 'GENERAL',
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the reports for a message', async () => {
|
||||
await request
|
||||
.get(api('moderation.reports'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the msgId is not provided', async () => {
|
||||
await request
|
||||
.get(api('moderation.reports'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
msgId: '',
|
||||
})
|
||||
.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').and.to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// test for testing out the moderation.reportInfo endpoint
|
||||
|
||||
describe('[/moderation.reportInfo]', () => {
|
||||
let message: IMessage;
|
||||
let reportedMessage: IModerationReport;
|
||||
|
||||
// post a new message to the channel 'general' by sending a request to chat.postMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.postMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
channel: 'general',
|
||||
text: 'messageId',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('message').and.to.be.an('object');
|
||||
message = res.body.message;
|
||||
});
|
||||
});
|
||||
|
||||
// create a reported message by sending a request to chat.reportMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.reportMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
messageId: message._id,
|
||||
description: 'sample report',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
// get the report information by sending a request to moderation.reports
|
||||
before(async () => {
|
||||
await request
|
||||
.get(api('moderation.reports'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
reportedMessage = res.body.reports[0];
|
||||
});
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await request
|
||||
.post(api('chat.delete'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
roomId: 'GENERAL',
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the report information', async () => {
|
||||
await request
|
||||
.get(api('moderation.reportInfo'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
reportId: reportedMessage._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('report').and.to.be.an('object');
|
||||
expect(res.body.report).to.have.property('_id', reportedMessage._id);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the reportId is not provided', async () => {
|
||||
await request
|
||||
.get(api('moderation.reportInfo'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
reportId: '',
|
||||
})
|
||||
.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').and.to.be.a('string');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the reportId is invalid', async () => {
|
||||
await request
|
||||
.get(api('moderation.reportInfo'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
reportId: '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('error').and.to.be.a('string');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the reportId is not found', async () => {
|
||||
await request
|
||||
.get(api('moderation.reportInfo'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
reportId: '123456789012345678901234',
|
||||
})
|
||||
.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').and.to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// test for testing out the moderation.user.reportedMessages endpoint
|
||||
|
||||
describe('[/moderation.user.reportedMessages]', () => {
|
||||
let message: IMessage;
|
||||
let reportedMessage: IModerationReport;
|
||||
|
||||
// post a new message to the channel 'general' by sending a request to chat.postMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.postMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
channel: 'general',
|
||||
text: 'messageId',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('message').and.to.be.an('object');
|
||||
message = res.body.message;
|
||||
});
|
||||
});
|
||||
|
||||
// create a reported message by sending a request to chat.reportMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.reportMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
messageId: message._id,
|
||||
description: 'sample report',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
// get the report information by sending a request to moderation.reports
|
||||
before(async () => {
|
||||
await request
|
||||
.get(api('moderation.reports'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
reportedMessage = res.body.reports[0];
|
||||
});
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await request
|
||||
.post(api('chat.delete'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
roomId: 'GENERAL',
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the message history', async () => {
|
||||
await request
|
||||
.get(api('moderation.user.reportedMessages'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
userId: reportedMessage.reportedBy._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('messages').and.to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the userId is not provided', async () => {
|
||||
await request
|
||||
.get(api('moderation.user.reportedMessages'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
userId: '',
|
||||
})
|
||||
.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').and.to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// test for testing out the moderation.user.deleteReportedMessages endpoint
|
||||
|
||||
describe('[/moderation.user.deleteReportedMessages]', () => {
|
||||
let message: IMessage;
|
||||
let reportedMessage: IModerationReport;
|
||||
|
||||
// post a new message to the channel 'general' by sending a request to chat.postMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.postMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
channel: 'general',
|
||||
text: 'messageId',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('message').and.to.be.an('object');
|
||||
message = res.body.message;
|
||||
});
|
||||
});
|
||||
|
||||
// create a reported message by sending a request to chat.reportMessage
|
||||
before(async () => {
|
||||
await request
|
||||
.post(api('chat.reportMessage'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
messageId: message._id,
|
||||
description: 'sample report',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
// get the report information by sending a request to moderation.reports
|
||||
before(async () => {
|
||||
await request
|
||||
.get(api('moderation.reports'))
|
||||
.set(credentials)
|
||||
.query({
|
||||
msgId: message._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
expect(res.body).to.have.property('reports').and.to.be.an('array');
|
||||
reportedMessage = res.body.reports[0];
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete the message history', async () => {
|
||||
await request
|
||||
.post(api('moderation.user.deleteReportedMessages'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
userId: reportedMessage.reportedBy._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the userId is not provided', async () => {
|
||||
await request
|
||||
.post(api('moderation.user.deleteReportedMessages'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
userId: '',
|
||||
})
|
||||
.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').and.to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('[/moderation.reportUser]', () => {
|
||||
let userToBeReported: IUser;
|
||||
|
||||
before(async () => {
|
||||
userToBeReported = await createUser();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await deleteUser(userToBeReported);
|
||||
});
|
||||
|
||||
it('should report an user', async () => {
|
||||
await request
|
||||
.post(api('moderation.reportUser'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
userId: userToBeReported?._id,
|
||||
description: 'sample report',
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(200)
|
||||
.expect((res: Response) => {
|
||||
expect(res.body).to.have.property('success', true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to report an user if not provided description', async () => {
|
||||
await request
|
||||
.post(api('moderation.reportUser'))
|
||||
.set(credentials)
|
||||
.send({
|
||||
userId: userToBeReported?._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('error');
|
||||
expect(res.body).to.have.property('errorType', 'invalid-params');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user