-
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.
Merge branch 'categorise-senders' into next15
- Loading branch information
Showing
86 changed files
with
4,034 additions
and
398 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
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { describe, it, expect, vi } from "vitest"; | ||
import { aiCategorizeSenders } from "@/utils/ai/categorize-sender/ai-categorize-senders"; | ||
import { getEnabledCategories } from "@/utils/categories"; | ||
|
||
vi.mock("server-only", () => ({})); | ||
|
||
describe("aiCategorizeSenders", () => { | ||
const user = { | ||
email: "[email protected]", | ||
aiProvider: null, | ||
aiModel: null, | ||
aiApiKey: null, | ||
}; | ||
|
||
it("should categorize senders using AI", async () => { | ||
const senders = [ | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
]; | ||
|
||
const result = await aiCategorizeSenders({ | ||
user, | ||
senders: senders.map((sender) => ({ emailAddress: sender, snippet: "" })), | ||
categories: getEnabledCategories().map((c) => c.label), | ||
}); | ||
|
||
expect(result).toHaveLength(senders.length); | ||
expect(result).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
sender: expect.any(String), | ||
category: expect.any(String), | ||
}), | ||
]), | ||
); | ||
|
||
// Check specific senders | ||
const newsletterResult = result.find( | ||
(r) => r.sender === "[email protected]", | ||
); | ||
expect(newsletterResult?.category).toBe("newsletter"); | ||
|
||
const supportResult = result.find( | ||
(r) => r.sender === "[email protected]", | ||
); | ||
expect(supportResult?.category).toBe("support"); | ||
|
||
// The unknown sender might be categorized as "RequestMoreInformation" | ||
const unknownResult = result.find( | ||
(r) => r.sender === "[email protected]", | ||
); | ||
expect(unknownResult?.category).toBe("RequestMoreInformation"); | ||
}, 15_000); // Increased timeout for AI call | ||
|
||
it("should handle empty senders list", async () => { | ||
const result = await aiCategorizeSenders({ | ||
user, | ||
senders: [], | ||
categories: [], | ||
}); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should categorize senders for all valid SenderCategory values", async () => { | ||
const senders = getEnabledCategories() | ||
.filter((category) => category.label !== "Unknown") | ||
.map((category) => `${category.label}@example.com`); | ||
|
||
const result = await aiCategorizeSenders({ | ||
user, | ||
senders: senders.map((sender) => ({ emailAddress: sender, snippet: "" })), | ||
categories: getEnabledCategories().map((c) => c.label), | ||
}); | ||
|
||
expect(result).toHaveLength(senders.length); | ||
|
||
for (const sender of senders) { | ||
const category = sender.split("@")[0]; | ||
const senderResult = result.find((r) => r.sender === sender); | ||
expect(senderResult).toBeDefined(); | ||
expect(senderResult?.category).toBe(category); | ||
} | ||
}, 15_000); | ||
}); |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.