refactor: modularize notification job creation and enforce plan-based channel availability in policy resolver
This commit is contained in:
@@ -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"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user