Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/web/__tests__/ai-categorize-senders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const isAiTest = process.env.RUN_AI_TESTS === "true";
vi.mock("server-only", () => ({}));

const testUser = {
userId: "user1",
email: "user@test.com",
aiProvider: null,
aiModel: null,
aiApiKey: null,
about: null,
};

const testSenders = [
Expand Down
14 changes: 2 additions & 12 deletions apps/web/__tests__/ai-choose-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, test, vi } from "vitest";
import { type Action, ActionType, LogicalOperator } from "@prisma/client";
import type { ParsedMessage, RuleWithActions } from "@/utils/types";
import { getActionItemsWithAiArgs } from "@/utils/ai/choose-rule/choose-args";
import { getUser } from "@/__tests__/helpers";

// pnpm test-ai ai-choose-args

Expand Down Expand Up @@ -197,7 +198,7 @@ function getRule(
enabled: true,
categoryFilterType: null,
conditionalOperator: LogicalOperator.AND,
type: null,
systemType: null,
};
}

Expand Down Expand Up @@ -228,14 +229,3 @@ function getParsedMessage({
},
};
}

function getUser() {
return {
id: "userId",
aiModel: null,
aiProvider: null,
email: "user@test.com",
aiApiKey: null,
about: null,
};
}
24 changes: 1 addition & 23 deletions apps/web/__tests__/ai-choose-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, test, vi } from "vitest";
import { aiChooseRule } from "@/utils/ai/choose-rule/ai-choose-rule";
import { type Action, ActionType, LogicalOperator } from "@prisma/client";
import { defaultReplyTrackerInstructions } from "@/utils/reply-tracker/consts";
import { getEmail, getUser } from "@/__tests__/helpers";

// pnpm test-ai ai-choose-rule

Expand Down Expand Up @@ -347,26 +348,3 @@ function getRule(instructions: string, actions: Action[] = []) {
conditionalOperator: LogicalOperator.AND,
};
}

function getEmail({
from = "from@test.com",
subject = "subject",
content = "content",
}: { from?: string; subject?: string; content?: string } = {}) {
return {
id: "id",
from,
subject,
content,
};
}

function getUser() {
return {
aiModel: null,
aiProvider: null,
email: "user@test.com",
aiApiKey: null,
about: null,
};
}
10 changes: 2 additions & 8 deletions apps/web/__tests__/ai-create-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { gmail_v1 } from "@googleapis/gmail";
import { aiGenerateGroupItems } from "@/utils/ai/group/create-group";
import { queryBatchMessages } from "@/utils/gmail/message";
import type { ParsedMessage } from "@/utils/types";
import { getUser } from "@/__tests__/helpers";

// pnpm test-ai ai-create-group

Expand All @@ -15,15 +16,8 @@ vi.mock("@/utils/gmail/message", () => ({

describe.runIf(isAiTest)("aiGenerateGroupItems", () => {
it("should generate group items based on user prompt", async () => {
const user = {
email: "user@test.com",
aiProvider: null,
aiModel: null,
aiApiKey: null,
};

const user = getUser();
const gmail = {} as gmail_v1.Gmail;
const accessToken = "fake-access-token";
const group = {
name: "Work Emails",
prompt:
Expand Down
12 changes: 1 addition & 11 deletions apps/web/__tests__/ai-detect-recurring-pattern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, test, vi, beforeEach } from "vitest";
import { aiDetectRecurringPattern } from "@/utils/ai/choose-rule/ai-detect-recurring-pattern";
import type { EmailForLLM } from "@/utils/types";
import { RuleName } from "@/utils/rule/consts";
import { getUser } from "@/__tests__/helpers";

// Run with: pnpm test-ai ai-detect-recurring-pattern

Expand All @@ -28,17 +29,6 @@ describe.runIf(isAiTest)(
vi.clearAllMocks();
});

function getUser() {
return {
id: "user-1",
email: "user@test.com",
aiModel: null,
aiProvider: null,
aiApiKey: null,
about: null,
};
}

function getRealisticRules() {
return [
{
Expand Down
15 changes: 3 additions & 12 deletions apps/web/__tests__/ai-diff-rules.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect, vi } from "vitest";
import { aiDiffRules } from "@/utils/ai/rule/diff-rules";
import { getUser } from "@/__tests__/helpers";

// pnpm test-ai ai-diff-rules

Expand All @@ -9,12 +10,7 @@ vi.mock("server-only", () => ({}));

describe.runIf(isAiTest)("aiDiffRules", () => {
it("should correctly identify added, edited, and removed rules", async () => {
const user = {
email: "user@test.com",
aiModel: null,
aiProvider: null,
aiApiKey: null,
};
const user = getUser();

const oldPromptFile = `
* Label receipts as "Receipt"
Expand Down Expand Up @@ -45,12 +41,7 @@ describe.runIf(isAiTest)("aiDiffRules", () => {
}, 15_000);

it("should handle errors gracefully", async () => {
const user = {
email: "test@example.com",
aiProvider: null,
aiModel: null,
aiApiKey: "invalid-api-key",
};
const user = { ...getUser(), aiApiKey: "invalid-api-key" };
const oldPromptFile = "Some old prompt";
const newPromptFile = "Some new prompt";

Expand Down
9 changes: 2 additions & 7 deletions apps/web/__tests__/ai-example-matches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { aiFindExampleMatches } from "@/utils/ai/example-matches/find-example-ma
import { queryBatchMessages } from "@/utils/gmail/message";
import type { ParsedMessage } from "@/utils/types";
import { findExampleMatchesSchema } from "@/utils/ai/example-matches/find-example-matches";
import { getUser } from "@/__tests__/helpers";

// pnpm test-ai ai-find-example-matches

Expand All @@ -16,15 +17,9 @@ vi.mock("@/utils/gmail/message", () => ({

describe.runIf(isAiTest)("aiFindExampleMatches", () => {
it("should find example matches based on user prompt", async () => {
const user = {
email: "user@test.com",
aiProvider: null,
aiModel: null,
aiApiKey: null,
};
const user = getUser();

const gmail = {} as gmail_v1.Gmail;
const accessToken = "fake-access-token";
const rulesPrompt = `
* Label newsletters as "Newsletter" and archive them.
* Label emails that require a reply as "Reply Required".
Expand Down
12 changes: 1 addition & 11 deletions apps/web/__tests__/ai-extract-from-email-history.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test, vi, beforeEach } from "vitest";
import { aiExtractFromEmailHistory } from "@/utils/ai/knowledge/extract-from-email-history";
import type { EmailForLLM } from "@/utils/types";
import { getUser } from "@/__tests__/helpers";

// pnpm test-ai extract-from-email-history

Expand All @@ -9,17 +10,6 @@ vi.mock("server-only", () => ({}));
// Skip tests unless explicitly running AI tests
const isAiTest = process.env.RUN_AI_TESTS === "true";

function getUser() {
return {
id: "test-user-id",
email: "user@test.com",
aiModel: null,
aiProvider: null,
aiApiKey: null,
about: null,
};
}

function getMockMessage(overrides = {}): EmailForLLM {
return {
id: "msg1",
Expand Down
12 changes: 1 addition & 11 deletions apps/web/__tests__/ai-extract-knowledge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, test, vi, beforeEach } from "vitest";
import { aiExtractRelevantKnowledge } from "@/utils/ai/knowledge/extract";
import type { Knowledge } from "@prisma/client";
import type { UserEmailWithAI } from "@/utils/llms/types";
import { getUser } from "@/__tests__/helpers";

// pnpm test-ai ai-extract-knowledge

Expand All @@ -10,17 +11,6 @@ vi.mock("server-only", () => ({}));
// Skip tests unless explicitly running AI tests
const isAiTest = process.env.RUN_AI_TESTS === "true";

function getUser(): UserEmailWithAI {
return {
id: "test-user-id",
email: "influencer@test.com",
about: null,
aiModel: null,
aiProvider: null,
aiApiKey: null,
};
}

function getKnowledgeBase(): Knowledge[] {
return [
{
Expand Down
28 changes: 1 addition & 27 deletions apps/web/__tests__/ai-find-snippets.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test, vi } from "vitest";
import { aiFindSnippets } from "@/utils/ai/snippets/find-snippets";
import type { EmailForLLM } from "@/utils/types";
import { getEmail, getUser } from "@/__tests__/helpers";
// pnpm test-ai ai-find-snippets

const isAiTest = process.env.RUN_AI_TESTS === "true";
Expand Down Expand Up @@ -63,30 +64,3 @@ describe.runIf(isAiTest)("aiFindSnippets", () => {
expect(result.snippets).toHaveLength(0);
});
});

// helpers
function getEmail({
from = "user@test.com",
subject = "Test Subject",
content = "Test content",
replyTo,
cc,
}: Partial<EmailForLLM> = {}): EmailForLLM {
return {
from,
subject,
content,
...(replyTo && { replyTo }),
...(cc && { cc }),
};
}

function getUser() {
return {
aiModel: null,
aiProvider: null,
email: "user@test.com",
aiApiKey: null,
about: null,
};
}
13 changes: 2 additions & 11 deletions apps/web/__tests__/ai-process-user-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ParsedMessage, ParsedMessageHeaders } from "@/utils/types";
import type { RuleWithRelations } from "@/utils/ai/rule/create-prompt-from-rule";
import type { Category, GroupItem, Prisma } from "@prisma/client";
import { GroupItemType, LogicalOperator } from "@prisma/client";
import { getUser } from "@/__tests__/helpers";

// pnpm test-ai ai-process-user-request

Expand Down Expand Up @@ -445,6 +446,7 @@ function getRule(rule: Partial<RuleWithRelations>): RuleWithRelations {
enabled: true,
createdAt: new Date(),
updatedAt: new Date(),
systemType: null,
...rule,
};
}
Expand Down Expand Up @@ -477,17 +479,6 @@ function getParsedMessage(
};
}

function getUser() {
return {
id: "user1",
aiModel: null,
aiProvider: null,
email: "user@test.com",
aiApiKey: null,
about: null,
};
}

type Group = Prisma.GroupGetPayload<{
select: {
id: true;
Expand Down
14 changes: 13 additions & 1 deletion apps/web/__tests__/ai-prompt-to-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe.runIf(isAiTest)("aiPromptToRules", () => {
aiModel: null,
aiProvider: null,
aiApiKey: null,
userId: "user123",
about: null,
};

const prompts = [
Expand Down Expand Up @@ -114,6 +116,8 @@ describe.runIf(isAiTest)("aiPromptToRules", () => {
aiProvider: null,
aiModel: null,
aiApiKey: "invalid-api-key",
about: null,
userId: "user123",
};
const promptFile = "Some prompt";

Expand All @@ -132,6 +136,8 @@ describe.runIf(isAiTest)("aiPromptToRules", () => {
aiModel: null,
aiProvider: null,
aiApiKey: null,
about: null,
userId: "user123",
};

const promptFile = `
Expand Down Expand Up @@ -207,6 +213,8 @@ describe.runIf(isAiTest)("aiPromptToRules", () => {
aiModel: null,
aiProvider: null,
aiApiKey: null,
about: null,
userId: "user123",
};

const promptFile = `
Expand Down Expand Up @@ -249,6 +257,8 @@ describe.runIf(isAiTest)("aiPromptToRules", () => {
aiModel: null,
aiProvider: null,
aiApiKey: null,
about: null,
userId: "user123",
};

const promptFile = `
Expand Down Expand Up @@ -291,6 +301,8 @@ describe.runIf(isAiTest)("aiPromptToRules", () => {
aiModel: null,
aiProvider: null,
aiApiKey: null,
about: null,
userId: "user123",
};

const promptFile = `
Expand Down Expand Up @@ -329,6 +341,6 @@ describe.runIf(isAiTest)("aiPromptToRules", () => {
const replyAction = result[0].actions.find(
(a) => a.type === ActionType.REPLY,
);
expect(replyAction?.content).toContain("{{firstName}}");
expect(replyAction?.fields?.content).toContain("{{firstName}}");
}, 15_000);
});
Loading
Loading