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: 1 addition & 1 deletion src/lib/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function createNotification(
resourceId,
resourceType,
actorId,
includeActor,
includeActor = true,
issueTitle,
machineName,
formattedIssueId,
Expand Down
2 changes: 0 additions & 2 deletions src/services/issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ describe("Issue Service", () => {
resourceId: issueId,
resourceType: "issue",
actorId,
includeActor: true,
issueTitle: "Test Issue",
machineName: "Test Machine",
formattedIssueId: "MM-01",
Expand Down Expand Up @@ -144,7 +143,6 @@ describe("Issue Service", () => {
resourceId: "issue-new",
resourceType: "issue",
actorId: "user-1",
includeActor: true,
issueTitle: "New Issue",
machineName: "Test Machine",
formattedIssueId: "MM-01",
Expand Down
3 changes: 0 additions & 3 deletions src/services/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ export async function createIssue({
resourceId: issue.id,
resourceType: "issue",
...(reportedBy ? { actorId: reportedBy } : {}),
includeActor: true,
issueTitle: title,
machineName: updatedMachine.name,
formattedIssueId: formatIssueId(machineInitials, issueNumber),
Expand Down Expand Up @@ -282,7 +281,6 @@ export async function updateIssueStatus({
resourceId: issueId,
resourceType: "issue",
actorId: userId,
includeActor: true,
issueTitle: currentIssue.title,
machineName: currentIssue.machine.name,
formattedIssueId: formatIssueId(
Expand Down Expand Up @@ -506,7 +504,6 @@ export async function assignIssue({
resourceId: issueId,
resourceType: "issue",
actorId,
includeActor: true,
issueTitle: currentIssue.title,
machineName: currentIssue.machine.name,
formattedIssueId: formatIssueId(
Expand Down
3 changes: 2 additions & 1 deletion src/test/integration/database-queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ describe("Database Queries (PGlite)", () => {
type: "new_issue",
resourceId: issue.id,
resourceType: "issue",
actorId: "some-other-user-id", // Actor is someone else
actorId: "00000000-0000-0000-0000-000000000002", // Actor is someone else
includeActor: false, // Exclude actor to test global watch behavior
issueTitle: "Test Issue",
machineName: "Test Machine",
issueContext: {
Expand Down
52 changes: 51 additions & 1 deletion src/test/integration/notifications.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { eq } from "drizzle-orm";
import { eq, sql } from "drizzle-orm";
import { createNotification } from "~/lib/notifications";
import { sendEmail } from "~/lib/email/client";
import { getTestDb, setupTestDb } from "~/test/setup/pglite";
Expand Down Expand Up @@ -66,6 +66,7 @@ describe("createNotification (Integration)", () => {
resourceId: issue.id,
resourceType: "issue",
actorId: actor.id,
includeActor: false, // Explicitly test actor exclusion
commentContent: "Test comment",
},
db
Comment on lines 66 to 72
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical test coverage gap: There is no test that validates the new default behavior where actors ARE notified by default. The existing tests either explicitly exclude the actor with includeActor false, or they don't verify that the actor receives a notification. Consider adding a test like "should notify the actor by default" that creates a notification with an actor, doesn't specify includeActor, and verifies that the actor receives the notification. This would ensure the new default behavior is properly tested and prevent regressions.

Copilot uses AI. Check for mistakes.
Expand All @@ -77,6 +78,53 @@ describe("createNotification (Integration)", () => {
expect(sendEmail).not.toHaveBeenCalled();
});

it("should notify the actor by default", async () => {
const db = await getTestDb();

// Setup: Actor is also a watcher
const [actor] = await db
.insert(userProfiles)
.values(createTestUser())
.returning();
const [machine] = await db
.insert(machines)
.values(createTestMachine({ initials: "DEF" }))
.returning();
const [issue] = await db
.insert(issues)
.values(createTestIssue(machine.initials, { issueNumber: 1 }))
.returning();

await db.insert(issueWatchers).values({
issueId: issue.id,
userId: actor.id,
});

// Mock auth.users email for actor
await db.execute(
sql`INSERT INTO auth.users (id, email) VALUES (${actor.id}, 'actor@test.com')`
);

// Don't specify includeActor - should default to true
await createNotification(
{
type: "new_comment",
resourceId: issue.id,
resourceType: "issue",
actorId: actor.id,
commentContent: "Test comment",
},
db
);

// Verify actor receives notification (new default behavior)
const result = await db.query.notifications.findMany({
where: eq(notifications.userId, actor.id),
});
expect(result).toHaveLength(1);
expect(result[0].type).toBe("new_comment");
});

it("should respect main switches", async () => {
const db = await getTestDb();

Expand Down Expand Up @@ -127,6 +175,7 @@ describe("createNotification (Integration)", () => {
resourceId: issue.id,
resourceType: "issue",
actorId: actor.id,
includeActor: false, // Exclude actor to test recipient preferences
commentContent: "Test comment",
},
db
Expand Down Expand Up @@ -186,6 +235,7 @@ describe("createNotification (Integration)", () => {
resourceId: issue.id,
resourceType: "issue",
actorId: actor.id,
includeActor: false, // Exclude actor to test recipient granular toggles
commentContent: "Test comment",
},
db
Expand Down
Loading