chore: Refactoring event processors and service architecture (#2495)
This commit is contained in:
@@ -4,7 +4,7 @@ import Router from "koa-router";
|
||||
import { find } from "lodash";
|
||||
import { parseDomain, isCustomSubdomain } from "../../../shared/utils/domains";
|
||||
import { AuthorizationError } from "../../errors";
|
||||
import mailer, { sendEmail } from "../../mailer";
|
||||
import mailer from "../../mailer";
|
||||
import errorHandling from "../../middlewares/errorHandling";
|
||||
import methodOverride from "../../middlewares/methodOverride";
|
||||
import validation from "../../middlewares/validation";
|
||||
@@ -108,7 +108,7 @@ router.post("email", errorHandling(), async (ctx) => {
|
||||
}
|
||||
|
||||
// send email to users registered address with a short-lived token
|
||||
mailer.signin({
|
||||
await mailer.sendTemplate("signin", {
|
||||
to: user.email,
|
||||
token: user.getEmailSigninToken(),
|
||||
teamUrl: team.url,
|
||||
@@ -138,7 +138,10 @@ router.get("email.callback", async (ctx) => {
|
||||
return ctx.redirect("/?notice=suspended");
|
||||
}
|
||||
if (user.isInvited) {
|
||||
sendEmail("welcome", user.email, { teamUrl: user.team.url });
|
||||
await mailer.sendTemplate("welcome", {
|
||||
to: user.email,
|
||||
teamUrl: user.team.url,
|
||||
});
|
||||
}
|
||||
|
||||
await user.update({ lastActiveAt: new Date() });
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// @flow
|
||||
import TestServer from "fetch-test-server";
|
||||
import app from "../../app";
|
||||
import mailer from "../../mailer";
|
||||
import webService from "../../services/web";
|
||||
import { buildUser, buildGuestUser, buildTeam } from "../../test/factories";
|
||||
import { flushdb } from "../../test/support";
|
||||
|
||||
const app = webService();
|
||||
const server = new TestServer(app.callback());
|
||||
|
||||
jest.mock("../../mailer");
|
||||
@@ -13,7 +14,7 @@ beforeEach(async () => {
|
||||
await flushdb();
|
||||
|
||||
// $FlowFixMe – does not understand Jest mocks
|
||||
mailer.signin.mockReset();
|
||||
mailer.sendTemplate.mockReset();
|
||||
});
|
||||
afterAll(() => server.close());
|
||||
|
||||
@@ -39,7 +40,7 @@ describe("email", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.redirect).toMatch("slack");
|
||||
expect(mailer.signin).not.toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should respond with redirect location when user is SSO enabled on another subdomain", async () => {
|
||||
@@ -60,7 +61,7 @@ describe("email", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.redirect).toMatch("slack");
|
||||
expect(mailer.signin).not.toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should respond with success when user is not SSO enabled", async () => {
|
||||
@@ -73,7 +74,7 @@ describe("email", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.success).toEqual(true);
|
||||
expect(mailer.signin).toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should respond with success regardless of whether successful to prevent crawling email logins", async () => {
|
||||
@@ -84,7 +85,7 @@ describe("email", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.success).toEqual(true);
|
||||
expect(mailer.signin).not.toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("with multiple users matching email", () => {
|
||||
@@ -108,7 +109,7 @@ describe("email", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.redirect).toMatch("slack");
|
||||
expect(mailer.signin).not.toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should default to current subdomain with guest email", async () => {
|
||||
@@ -131,7 +132,7 @@ describe("email", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.success).toEqual(true);
|
||||
expect(mailer.signin).toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should default to custom domain with SSO", async () => {
|
||||
@@ -151,7 +152,7 @@ describe("email", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.redirect).toMatch("slack");
|
||||
expect(mailer.signin).not.toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should default to custom domain with guest email", async () => {
|
||||
@@ -171,7 +172,7 @@ describe("email", () => {
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.success).toEqual(true);
|
||||
expect(mailer.signin).toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user