fix: Failure case during account provision that can result in no welcome collection
This commit is contained in:
@ -7,7 +7,7 @@ import {
|
||||
AuthenticationProviderDisabledError,
|
||||
} from "../errors";
|
||||
import { sendEmail } from "../mailer";
|
||||
import { Team, User } from "../models";
|
||||
import { Collection, Team, User } from "../models";
|
||||
import teamCreator from "./teamCreator";
|
||||
import userCreator from "./userCreator";
|
||||
|
||||
@ -90,8 +90,20 @@ export default async function accountProvisioner({
|
||||
sendEmail("welcome", user.email, { teamUrl: team.url });
|
||||
}
|
||||
|
||||
if (isNewTeam) {
|
||||
await team.provisionFirstCollection(user.id);
|
||||
if (isNewUser || isNewTeam) {
|
||||
let provision = isNewTeam;
|
||||
|
||||
// accounts for the case where a team is provisioned, but the user creation
|
||||
// failed. In this case we have a valid previously created team but no
|
||||
// onboarding collection.
|
||||
if (!isNewTeam) {
|
||||
const count = await Collection.count({ where: { teamId: team.id } });
|
||||
provision = count === 0;
|
||||
}
|
||||
|
||||
if (provision) {
|
||||
await team.provisionFirstCollection(user.id);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -189,7 +189,8 @@ describe("accountProvisioner", () => {
|
||||
expect(isNewUser).toEqual(true);
|
||||
expect(sendEmail).toHaveBeenCalled();
|
||||
|
||||
// should provision welcome collection
|
||||
const collectionCount = await Collection.count();
|
||||
expect(collectionCount).toEqual(0);
|
||||
expect(collectionCount).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user