improve test coverage

This commit is contained in:
Alex Holliday committed 2025-11-24 22:49:55 +00:00
1 parent d5f1032bdf
commit 1e26fb1e3b
15 files changed
+388 -71

No files matched your search

@@ -69,6 +69,16 @@ class InviteService implements IInviteService {
throw new ApiError("User is already a team member", 409);
}
// Check if inivite already exists
const existingInvite = await Invite.findOne({
email,
teamId,
});
if (existingInvite) {
throw new ApiError("An invite already exists for this email", 409);
}
const token = crypto.randomBytes(32).toString("hex");
const tokenHash = crypto.createHash("sha256").update(token).digest("hex");
@@ -10,6 +10,7 @@ import {
IOrgMembership,
} from "@/db/models/index.js";
import ApiError from "@/utils/ApiError.js";
import { invalidateCachesForUser } from "@/middleware/AddUserContext.js";
const SERVICE_NAME = "TeamMemberService";
export interface ITeamMemberService {
@@ -117,11 +118,21 @@ class TeamMemberService implements ITeamMemberService {
throw new ApiError("Role not found", 404);
}
const teamMembership = await TeamMembership.findOneAndUpdate(
const updated = await TeamMembership.findOneAndUpdate(
{ orgId: orgId, _id: teamMembershipId },
{ roleId: roleId },
{ new: true }
)
);
if (!updated) {
throw new ApiError("Team membership not found", 404);
}
invalidateCachesForUser(updated.userId.toString());
const teamMembership = await TeamMembership.findOne({
orgId: orgId,
_id: teamMembershipId,
})
.populate<IUser>("userId", "firstName lastName email")
.populate<IRole>("roleId", "name scope permissions");
@@ -140,6 +151,7 @@ class TeamMemberService implements ITeamMemberService {
if (!tm) {
throw new ApiError("Team member not found", 404);
}
invalidateCachesForUser(tm.userId.toString());
await TeamMembership.findOneAndDelete({ _id: teamMemberId, orgId: orgId });
return true;
};
@@ -33,7 +33,7 @@ export interface IEmailService extends IMessageService {
sendGeneric: (
to: string,
subject: string,
content: string
content: { text?: string; html?: string }
) => Promise<boolean>;
testTransport: (transport: IEmailTransport) => Promise<boolean>;
rebuildTransport: (transport: IEmailTransport) => Promise<boolean>;
@@ -186,7 +186,11 @@ class EmailService implements IEmailService {
);
};
sendGeneric = async (to: string, subject: string, content: string) => {
sendGeneric = async (
to: string,
subject: string,
content: { text?: string; html?: string }
) => {
try {
if (this.transporter === null) {
this.transporter = await this.buildTransport();
@@ -196,7 +200,8 @@ class EmailService implements IEmailService {
from: `"Checkmate" <${this.from}>`,
to: to,
subject: subject,
text: content,
text: content.text,
html: content.html,
});
return true;
} catch (error) {