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
216 lines
7.6 KiB
TypeScript
216 lines
7.6 KiB
TypeScript
import type { IEmailInbox } 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 { createEmailInbox } from '../../../data/livechat/inboxes';
|
|
import { updatePermission } from '../../../data/permissions.helper';
|
|
|
|
describe('Email inbox', () => {
|
|
before((done) => getCredentials(done));
|
|
let testInbox = '';
|
|
before(async () => {
|
|
await request
|
|
.post(api('email-inbox'))
|
|
.set(credentials)
|
|
.send({
|
|
active: true,
|
|
name: 'test-email-inbox##',
|
|
email: 'test-email@example.com',
|
|
description: 'test email inbox',
|
|
senderInfo: 'test email inbox',
|
|
smtp: {
|
|
server: 'smtp.example.com',
|
|
port: 587,
|
|
username: 'example@example.com',
|
|
password: 'not-a-real-password',
|
|
secure: true,
|
|
},
|
|
imap: {
|
|
server: 'imap.example.com',
|
|
port: 993,
|
|
username: 'example@example.com',
|
|
password: 'not-a-real-password',
|
|
secure: true,
|
|
maxRetries: 10,
|
|
},
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success');
|
|
if (res.body.success === true) {
|
|
testInbox = res.body._id;
|
|
} else {
|
|
expect(res.body).to.have.property('error');
|
|
expect(res.body.error.includes('E11000')).to.be.eq(true);
|
|
}
|
|
});
|
|
});
|
|
after(async () => {
|
|
if (testInbox) {
|
|
await request
|
|
.delete(api(`email-inbox/${testInbox}`))
|
|
.set(credentials)
|
|
.send()
|
|
.expect(200);
|
|
}
|
|
});
|
|
describe('GET email-inbox.list', () => {
|
|
it('should fail if user doesnt have manage-email-inbox permission', async () => {
|
|
await updatePermission('manage-email-inbox', []);
|
|
await request.get(api('email-inbox.list')).set(credentials).expect(403);
|
|
});
|
|
it('should return a list of email inboxes', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
const res = await request.get(api('email-inbox.list')).set(credentials).send().expect('Content-Type', 'application/json').expect(200);
|
|
|
|
expect(res.body).to.have.property('emailInboxes');
|
|
expect(res.body.emailInboxes).to.be.an('array');
|
|
expect(res.body.emailInboxes).to.have.length.of.at.least(1);
|
|
expect(res.body.emailInboxes.filter((ibx: IEmailInbox) => ibx.email === 'test-email@example.com')).to.have.length.gte(1);
|
|
// make sure we delete the test inbox, even if creation failed on this test run
|
|
testInbox = res.body.emailInboxes.filter((ibx: IEmailInbox) => ibx.email === 'test-email@example.com')[0]._id;
|
|
expect(res.body).to.have.property('total');
|
|
expect(res.body.total).to.be.a('number');
|
|
expect(res.body).to.have.property('count');
|
|
expect(res.body.count).to.be.a('number');
|
|
expect(res.body).to.have.property('offset');
|
|
expect(res.body.offset).to.be.a('number');
|
|
});
|
|
});
|
|
|
|
describe('POST email-inbox', () => {
|
|
let inboxId: string;
|
|
const mockedPayload = {
|
|
name: 'test',
|
|
active: false,
|
|
email: `test${new Date().getTime()}@test.com`,
|
|
description: 'Updated test description',
|
|
senderInfo: 'test',
|
|
smtp: {
|
|
server: 'smtp.example.com',
|
|
port: 587,
|
|
username: 'xxxx',
|
|
password: 'xxxx',
|
|
secure: true,
|
|
},
|
|
imap: {
|
|
server: 'imap.example.com',
|
|
port: 993,
|
|
username: 'xxxx',
|
|
password: 'xxxx',
|
|
secure: true,
|
|
maxRetries: 10,
|
|
},
|
|
};
|
|
it('should fail if user doesnt have manage-email-inbox permission', async () => {
|
|
await updatePermission('manage-email-inbox', []);
|
|
await request.post(api('email-inbox')).set(credentials).send(mockedPayload).expect(403);
|
|
});
|
|
it('should fail if smtp config is not on body params', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
await request.post(api('email-inbox')).set(credentials).send({}).expect(400);
|
|
});
|
|
it('should fail if imap config is not on body params', async () => {
|
|
const { imap, ...payload } = mockedPayload;
|
|
await request.post(api('email-inbox')).set(credentials).send(payload).expect(400);
|
|
});
|
|
it('should fail if name is not on body params', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
const { name, ...payload } = mockedPayload;
|
|
await request.post(api('email-inbox')).set(credentials).send(payload).expect(400);
|
|
});
|
|
it('should fail if active is not on body params', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
const { active, ...payload } = mockedPayload;
|
|
await request.post(api('email-inbox')).set(credentials).send(payload).expect(400);
|
|
});
|
|
it('should fail if email is not on body params', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
const { email, ...payload } = mockedPayload;
|
|
await request.post(api('email-inbox')).set(credentials).send(payload).expect(400);
|
|
});
|
|
it('should save an email inbox', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
const { email, ...payload } = mockedPayload;
|
|
const { body } = await request
|
|
.post(api('email-inbox'))
|
|
.set(credentials)
|
|
.send({
|
|
...payload,
|
|
email: `test${new Date().getTime()}@test.com`,
|
|
})
|
|
.expect(200);
|
|
|
|
expect(body).to.have.property('_id');
|
|
inboxId = body._id;
|
|
});
|
|
it('should update an email inbox when _id is passed in the object', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
const { body } = await request
|
|
.post(api('email-inbox'))
|
|
.set(credentials)
|
|
.send({
|
|
...mockedPayload,
|
|
_id: inboxId,
|
|
description: 'Updated test description',
|
|
})
|
|
.expect(200);
|
|
|
|
expect(body).to.have.property('_id');
|
|
});
|
|
});
|
|
describe('GET email-inbox/:_id', () => {
|
|
it('should fail if user doesnt have manage-email-inbox permission', async () => {
|
|
await updatePermission('manage-email-inbox', []);
|
|
await request.get(api('email-inbox/123')).set(credentials).expect(403);
|
|
});
|
|
it('should fail when email inbox does not exist', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
await request.get(api('email-inbox/123')).set(credentials).expect(404);
|
|
});
|
|
it('should return an email inbox', async () => {
|
|
const inbox = await createEmailInbox();
|
|
const { body } = await request
|
|
.get(api(`email-inbox/${inbox._id}`))
|
|
.set(credentials)
|
|
.expect(200);
|
|
|
|
expect(body).to.have.property('_id');
|
|
expect(body).to.have.property('name', 'test');
|
|
});
|
|
});
|
|
describe('DELETE email-inbox/:_id', () => {
|
|
it('should fail if user doesnt have manage-email-inbox permission', async () => {
|
|
await updatePermission('manage-email-inbox', []);
|
|
await request.delete(api('email-inbox/123')).set(credentials).expect(403);
|
|
});
|
|
it('should return nothing when email inbox does not exist', async () => {
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
await request.delete(api('email-inbox/123')).set(credentials).expect(404);
|
|
});
|
|
it('should delete an email inbox', async () => {
|
|
const inbox = await createEmailInbox();
|
|
const { body } = await request
|
|
.delete(api(`email-inbox/${inbox._id}`))
|
|
.set(credentials)
|
|
.expect(200);
|
|
|
|
expect(body).to.have.property('success', true);
|
|
});
|
|
});
|
|
describe('GET email-inbox.search', () => {
|
|
it('should fail if user doesnt have manage-email-inbox permission', async () => {
|
|
await updatePermission('manage-email-inbox', []);
|
|
await request.get(api('email-inbox.search')).set(credentials).expect(403);
|
|
});
|
|
it('should return an email inbox matching email', async () => {
|
|
await createEmailInbox();
|
|
await updatePermission('manage-email-inbox', ['admin']);
|
|
await request.get(api('email-inbox.search')).query({ email: 'test' }).set(credentials).expect(200);
|
|
});
|
|
});
|
|
});
|