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

This commit is contained in:
upstream-mirror
2026-09-16 01:21:02 +05:00
commit 30810eecd7
10161 changed files with 987110 additions and 0 deletions

View File

@@ -0,0 +1,154 @@
import { MeteorError } from '@rocket.chat/core-services';
import { expect } from 'chai';
import { describe, it, beforeEach, afterEach } from 'mocha';
import mock from 'proxyquire';
import Sinon from 'sinon';
type SendUserEmailFn = (subject: string, html: string, user: { email?: string; password?: string; name?: string }) => Promise<void>;
type SendHelperFn = (user: { email?: string; password?: string; name?: string }) => Promise<void>;
const userData = {
email: 'test@example.com',
password: '123456',
name: 'Test User',
};
const makeStubs = () => {
const MailerStub = {
getTemplate: Sinon.stub(),
send: Sinon.stub(),
};
const SettingsStub = {
settings: {
get: Sinon.stub().callsFake((key: string) => {
if (key === 'From_Email') return 'no-reply@example.com';
if (key === 'Accounts_UserAddedEmail_Subject') return 'Welcome [name]!';
if (key === 'Password_Changed_Email_Subject') return 'Password Changed';
return '';
}),
},
};
const MeteorStub = {
Meteor: {
startup: Sinon.stub(),
},
};
return { MailerStub, SettingsStub, MeteorStub };
};
describe('sendUserEmail (Mocha + TS)', () => {
let MailerStub: { getTemplate: Sinon.SinonStub; send: Sinon.SinonStub };
let SettingsStub: { settings: { get: Sinon.SinonStub } };
let MeteorStub: { Meteor: { startup: Sinon.SinonStub } };
let sendUserEmail: SendUserEmailFn;
let sendWelcomeEmail: SendHelperFn;
let sendPasswordEmail: SendHelperFn;
beforeEach(() => {
const stubs = makeStubs();
MailerStub = stubs.MailerStub as any;
SettingsStub = stubs.SettingsStub as any;
MeteorStub = stubs.MeteorStub as any;
const mod = mock.noCallThru().load('../../../../../../server/lib/users/saveUser/sendUserEmail.ts', {
'../../notifications/email/api': MailerStub,
'../../../settings': SettingsStub,
'meteor/meteor': MeteorStub,
}) as any;
sendUserEmail = mod.sendUserEmail as SendUserEmailFn;
sendWelcomeEmail = mod.sendWelcomeEmail as SendHelperFn;
sendPasswordEmail = mod.sendPasswordEmail as SendHelperFn;
});
afterEach(() => {
Sinon.restore();
});
describe('sendUserEmail', () => {
it('should not send email if userData.email is missing', async () => {
await sendUserEmail('subject', '<p>html</p>', { ...userData, email: undefined });
Sinon.assert.notCalled(MailerStub.send);
});
it('should send email with correct parameters', async () => {
await sendUserEmail('subject', '<p>html</p>', userData);
Sinon.assert.calledOnce(MailerStub.send);
const callArg = MailerStub.send.getCall(0).args[0];
expect(callArg).to.be.an('object');
expect(callArg).to.include({
to: userData.email,
from: SettingsStub.settings.get('From_Email'),
subject: 'subject',
html: '<p>html</p>',
});
expect(callArg.data).to.include({
email: userData.email,
password: userData.password,
name: userData.name,
});
});
it('should throw MeteorError if Mailer.send fails', async () => {
MailerStub.send.throws(new Error('fail'));
let thrown = false;
try {
await sendUserEmail('subject', '<p>html</p>', userData);
} catch (err) {
thrown = true;
expect(err).to.be.instanceOf(MeteorError);
}
expect(thrown).to.equal(true);
});
it('should mask password in email data if password is not provided', async () => {
await sendUserEmail('subject', '<p>html</p>', { ...userData, password: undefined });
Sinon.assert.calledOnce(MailerStub.send);
const callArg = MailerStub.send.getCall(0).args[0];
expect(callArg.data).to.include({
email: userData.email,
password: '******',
name: userData.name,
});
});
});
describe('sendWelcomeEmail', () => {
it('should call sendUserEmail with welcome subject and template', async () => {
await sendWelcomeEmail(userData);
Sinon.assert.calledOnce(MailerStub.send);
const callArg = MailerStub.send.getCall(0).args[0];
expect(callArg).to.include({
subject: `Welcome [name]!`,
to: userData.email,
});
expect(callArg.data).to.deep.equal({
email: userData.email,
password: userData.password,
name: userData.name,
});
});
});
describe('sendPasswordEmail', () => {
it('should call sendUserEmail with password subject and template', async () => {
await sendPasswordEmail(userData);
Sinon.assert.calledOnce(MailerStub.send);
const callArg = MailerStub.send.getCall(0).args[0];
expect(callArg).to.include({
subject: 'Password Changed',
to: userData.email,
});
});
});
});