-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" }), | ||
|