chore: Refactoring event processors and service architecture (#2495)
This commit is contained in:
@ -6,7 +6,7 @@ import {
|
||||
EmailAuthenticationRequiredError,
|
||||
AuthenticationProviderDisabledError,
|
||||
} from "../errors";
|
||||
import { sendEmail } from "../mailer";
|
||||
import mailer from "../mailer";
|
||||
import { Collection, Team, User } from "../models";
|
||||
import teamCreator from "./teamCreator";
|
||||
import userCreator from "./userCreator";
|
||||
@ -87,7 +87,10 @@ export default async function accountProvisioner({
|
||||
const { isNewUser, user } = result;
|
||||
|
||||
if (isNewUser) {
|
||||
sendEmail("welcome", user.email, { teamUrl: team.url });
|
||||
await mailer.sendTemplate("welcome", {
|
||||
to: user.email,
|
||||
teamUrl: team.url,
|
||||
});
|
||||
}
|
||||
|
||||
if (isNewUser || isNewTeam) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// @flow
|
||||
import { sendEmail } from "../mailer";
|
||||
import mailer from "../mailer";
|
||||
import { Collection, UserAuthentication } from "../models";
|
||||
import { buildUser, buildTeam } from "../test/factories";
|
||||
import { flushdb } from "../test/support";
|
||||
@ -17,7 +17,7 @@ jest.mock("aws-sdk", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
// $FlowFixMe
|
||||
sendEmail.mockReset();
|
||||
mailer.sendTemplate.mockReset();
|
||||
|
||||
return flushdb();
|
||||
});
|
||||
@ -59,7 +59,7 @@ describe("accountProvisioner", () => {
|
||||
expect(user.email).toEqual("jenny@example.com");
|
||||
expect(isNewUser).toEqual(true);
|
||||
expect(isNewTeam).toEqual(true);
|
||||
expect(sendEmail).toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).toHaveBeenCalled();
|
||||
|
||||
const collectionCount = await Collection.count();
|
||||
expect(collectionCount).toEqual(1);
|
||||
@ -104,7 +104,7 @@ describe("accountProvisioner", () => {
|
||||
expect(user.email).toEqual(newEmail);
|
||||
expect(isNewTeam).toEqual(false);
|
||||
expect(isNewUser).toEqual(false);
|
||||
expect(sendEmail).not.toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).not.toHaveBeenCalled();
|
||||
|
||||
const collectionCount = await Collection.count();
|
||||
expect(collectionCount).toEqual(0);
|
||||
@ -187,7 +187,7 @@ describe("accountProvisioner", () => {
|
||||
expect(auth.scopes[0]).toEqual("read");
|
||||
expect(user.email).toEqual("jenny@example.com");
|
||||
expect(isNewUser).toEqual(true);
|
||||
expect(sendEmail).toHaveBeenCalled();
|
||||
expect(mailer.sendTemplate).toHaveBeenCalled();
|
||||
|
||||
// should provision welcome collection
|
||||
const collectionCount = await Collection.count();
|
||||
|
@ -7,6 +7,7 @@ import { getAllowedDomains } from "../utils/authentication";
|
||||
import { generateAvatarUrl } from "../utils/avatars";
|
||||
|
||||
const log = debug("server");
|
||||
|
||||
type TeamCreatorResult = {|
|
||||
team: Team,
|
||||
authenticationProvider: AuthenticationProvider,
|
||||
|
@ -34,7 +34,7 @@ describe("teamCreator", () => {
|
||||
expect(isNewTeam).toEqual(true);
|
||||
});
|
||||
|
||||
it("should now allow creating multiple teams in installation", async () => {
|
||||
it("should not allow creating multiple teams in installation", async () => {
|
||||
await buildTeam();
|
||||
let error;
|
||||
|
||||
|
@ -54,6 +54,7 @@ export default async function userInviter({
|
||||
service: null,
|
||||
});
|
||||
users.push(newUser);
|
||||
|
||||
await Event.create({
|
||||
name: "users.invite",
|
||||
actorId: user.id,
|
||||
@ -64,7 +65,8 @@ export default async function userInviter({
|
||||
},
|
||||
ip,
|
||||
});
|
||||
await mailer.invite({
|
||||
|
||||
await mailer.sendTemplate("invite", {
|
||||
to: invite.email,
|
||||
name: invite.name,
|
||||
actorName: user.name,
|
||||
|
Reference in New Issue
Block a user