refactor: modularize notification job creation and enforce plan-based channel availability in policy resolver

This commit is contained in:
2026-07-27 22:51:33 -03:00
parent dc020d94d2
commit 68d98e8b40
6 changed files with 333 additions and 58 deletions
@@ -309,4 +309,43 @@ describe("PolicyResolver", () => {
expect(result.channels).toEqual([]);
});
it("resolves available channels from company defaults and plan limits without client preferences", async () => {
mockCompanyPolicyFindOne.mockResolvedValue({
companyId: "company-1",
defaultChannels: ["whatsapp" as NotificationChannel, "email" as NotificationChannel],
mutedChannels: ["email" as NotificationChannel],
timezone: "America/Argentina/Buenos_Aires",
});
(PlanSubscriptionsList.checkFeature as jest.Mock).mockResolvedValue(true);
const result = await resolver.resolveAvailableChannels("company-1", [
"whatsapp",
"email",
"system",
]);
expect(result).toEqual(["whatsapp", "email"]);
expect(mockClientPreferencesFindOne).not.toHaveBeenCalled();
expect(mockOverrideFindOne).not.toHaveBeenCalled();
});
it("removes available channels disallowed by the owner plan", async () => {
mockCompanyPolicyFindOne.mockResolvedValue({
companyId: "company-1",
defaultChannels: ["whatsapp" as NotificationChannel, "email" as NotificationChannel],
timezone: "America/Argentina/Buenos_Aires",
});
(PlanSubscriptionsList.checkFeature as jest.Mock).mockImplementation(
async (params: { feature: string }) =>
params.feature !== PlanFeatures.WAP_NOTIFICATIONS
);
const result = await resolver.resolveAvailableChannels("company-1", [
"whatsapp",
"email",
]);
expect(result).toEqual(["email"]);
});
});