Skip to content

Commit

Permalink
ai + category non match test
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Dec 20, 2024
1 parent 37d8662 commit e7847c8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions apps/web/utils/ai/choose-rule/match-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,37 @@ describe("findMatchingRule", () => {
expect(aiChooseRule).toHaveBeenCalledOnce();
});

it("doesn't match when AI condition fails (category matches but AI doesn't)", async () => {
prisma.newsletter.findUnique.mockResolvedValue(
getNewsletter({ categoryId: "newsletterCategory" }),
);

const rule = getRule({
conditionalOperator: LogicalOperator.AND,
instructions: "Match if the email is an AI newsletter",
categoryFilters: [getCategory({ id: "newsletterCategory" })],
});

(aiChooseRule as ReturnType<typeof vi.fn>).mockImplementationOnce(() => {
return {
reason: "Not an AI newsletter",
rule: undefined,
};
});

const rules = [rule];
const message = getMessage({
headers: getHeaders({ from: "[email protected]" }),
});
const user = getUser();

const result = await findMatchingRule(rules, message, user);

expect(result.rule).toBeUndefined();
expect(result.reason).toBeDefined();
expect(aiChooseRule).toHaveBeenCalledOnce();
});

it("doesn't match with only one of category or group", async () => {
prisma.newsletter.findUnique.mockResolvedValue(
getNewsletter({ categoryId: "category1" }),
Expand Down

0 comments on commit e7847c8

Please sign in to comment.