The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/tests/unit/app/mailer/getEmailContent.spec.ts

95 lines
2.1 KiB

/* eslint-disable @typescript-eslint/no-empty-function */
import { expect } from 'chai';
import { describe, it } from 'mocha';
import proxyquire from 'proxyquire';
const mocks = {
'@rocket.chat/string-helpers': {
escapeHTML: (str: string) => str,
},
'meteor/meteor': {
Meteor: {
startup: () => {},
},
},
'../../../../../server/lib/callbacks': {
callbacks: {
run: () => {},
},
},
'../../../../../server/lib/i18n': {
i18n: {
t: (trans: string) => trans,
},
},
'../../../../../server/lib/rooms/roomCoordinator': {
roomCoordinator: {
getRoomDirectives: () => ({
isGroupChat: () => true,
}),
getRoomName: () => '',
},
},
'../../../../mailer/server/api': {
getTemplate: () => {},
send: () => {},
replace: () => {},
},
'../../../../settings/server': {
settings: {
get: () => true,
watch: () => {},
},
},
'../../../../metrics/server': {
metrics: {},
},
'../../../../utils/server/getURL': {
getURL: () => {},
},
};
const message = {
u: {
name: 'rocket.cat',
username: 'rocket.cat',
},
};
const room = {
fname: 'room',
name: 'room',
t: 'p',
};
describe('getEmailContent', () => {
it('should return preview string for encrypted message', async () => {
const { getEmailContent } = proxyquire.noCallThru().load('../../../../app/lib/server/functions/notifications/email.js', mocks);
const result = await getEmailContent({
message: { ...message, t: 'e2e' },
user: undefined,
room,
});
expect(result).to.be.equal('Encrypted_message_preview_unavailable');
});
it('should return header for encrypted message if Email_notification_show_message is turned off', async () => {
const { getEmailContent } = proxyquire.noCallThru().load('../../../../app/lib/server/functions/notifications/email.js', {
...mocks,
'../../../../settings/server': {
settings: {
get: () => false,
watch: () => {},
},
},
});
const result = await getEmailContent({
message: { ...message, t: 'e2e' },
user: undefined,
room,
});
expect(result).to.be.equal('User_sent_a_message_on_channel');
});
});