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
136 lines
3.8 KiB
TypeScript
136 lines
3.8 KiB
TypeScript
import { expect } from 'chai';
|
|
import { before, after, describe, it } from 'mocha';
|
|
import type { Response } from 'supertest';
|
|
|
|
import { api, request, credentials, getCredentials } from '../../../data/api-data';
|
|
import { updatePermission } from '../../../data/permissions.helper';
|
|
|
|
describe('Mailer', () => {
|
|
before((done) => getCredentials(done));
|
|
|
|
describe('POST mailer', async () => {
|
|
before(async () => {
|
|
return updatePermission('send-mail', ['admin']);
|
|
});
|
|
|
|
after(async () => {
|
|
return updatePermission('send-mail', ['admin']);
|
|
});
|
|
|
|
it('should send an email if the payload is correct', async () => {
|
|
await request
|
|
.post(api('mailer'))
|
|
.set(credentials)
|
|
.send({
|
|
from: 'rocketchat.internal.admin.test@rocket.chat',
|
|
subject: 'Test email subject',
|
|
body: 'Test email body [unsubscribe]',
|
|
dryrun: true,
|
|
query: '',
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', true);
|
|
});
|
|
});
|
|
it('should throw an error if the request is incorrect', async () => {
|
|
await request
|
|
.post(api('mailer'))
|
|
.set(credentials)
|
|
.send({
|
|
from: 12345,
|
|
subject: {},
|
|
body: 'Test email body',
|
|
dryrun: true,
|
|
query: '',
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
});
|
|
});
|
|
it('should throw an error if the "from" param is missing', async () => {
|
|
await request
|
|
.post(api('mailer'))
|
|
.set(credentials)
|
|
.send({
|
|
subject: 'Test email subject',
|
|
body: 'Test email body',
|
|
dryrun: true,
|
|
query: '',
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
});
|
|
});
|
|
it('should throw an error if user does NOT have the send-mail permission', async () => {
|
|
await updatePermission('send-mail', []);
|
|
await request
|
|
.post(api('mailer'))
|
|
.set(credentials)
|
|
.send({
|
|
from: 'test-mail@test.com',
|
|
subject: 'Test email subject',
|
|
body: 'Test email body',
|
|
dryrun: true,
|
|
query: '',
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(403)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
expect(res.body).to.have.property('error', 'User does not have the permissions required for this action [error-unauthorized]');
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Mailer Unsubscribe', () => {
|
|
describe('POST mailer unsubscribe', () => {
|
|
it('should unsubscribe to mailer if the request is correct', async () => {
|
|
await request
|
|
.post(api('mailer.unsubscribe'))
|
|
.set(credentials)
|
|
.send({
|
|
_id: credentials['X-User-Id'],
|
|
createdAt: new Date().getTime().toString(),
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(200)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', true);
|
|
});
|
|
});
|
|
it('should throw an error if the "_id" param is missing', async () => {
|
|
await request
|
|
.post(api('mailer.unsubscribe'))
|
|
.set(credentials)
|
|
.send({
|
|
createdAt: new Date().getTime().toString(),
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
});
|
|
});
|
|
it('should throw an error if the "createdAt" param is missing', async () => {
|
|
await request
|
|
.post(api('mailer.unsubscribe'))
|
|
.set(credentials)
|
|
.send({
|
|
_id: credentials['X-User-Id'],
|
|
})
|
|
.expect('Content-Type', 'application/json')
|
|
.expect(400)
|
|
.expect((res: Response) => {
|
|
expect(res.body).to.have.property('success', false);
|
|
});
|
|
});
|
|
});
|
|
});
|