fix(core): Prevent calling internal hook email event if emailing is disabled (#8462)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Iván Ovejero
2024-01-29 16:15:30 +01:00
committed by GitHub
parent c9b3649b7e
commit 9e93980957
10 changed files with 597 additions and 568 deletions

View File

@@ -19,6 +19,7 @@ import { createUser } from '../shared/db/users';
import { createWorkflow, getWorkflowSharing, shareWorkflowWithUsers } from '../shared/db/workflows';
import { License } from '@/License';
import { UserManagementMailer } from '@/UserManagement/email';
import config from '@/config';
let owner: User;
let member: User;
@@ -149,7 +150,7 @@ describe('PUT /workflows/:id', () => {
const secondSharedWorkflows = await getWorkflowSharing(workflow);
expect(secondSharedWorkflows).toHaveLength(2);
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(1);
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(2);
});
test('PUT /workflows/:id/share should allow sharing by the owner of the workflow', async () => {
@@ -225,6 +226,20 @@ describe('PUT /workflows/:id', () => {
expect(sharedWorkflows).toHaveLength(1);
expect(mailer.notifyWorkflowShared).toHaveBeenCalledTimes(0);
});
test('should not call internal hooks listener for email sent if emailing is disabled', async () => {
config.set('userManagement.emails.mode', '');
const workflow = await createWorkflow({}, owner);
const response = await authOwnerAgent
.put(`/workflows/${workflow.id}/share`)
.send({ shareWithIds: [member.id] });
expect(response.statusCode).toBe(200);
config.set('userManagement.emails.mode', 'smtp');
});
});
describe('GET /workflows/new', () => {