Skip to content
Draft
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
56 changes: 56 additions & 0 deletions src/jobs/notifications/send-task-create-notifications.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { TaskWithWorkflowState } from '@/types/db'

const mockSendTaskCreateNotifications = jest.fn()

jest.mock('@trigger.dev/sdk/v3', () => ({
task: (config: unknown) => config,
logger: { log: jest.fn(), error: jest.fn(), warn: jest.fn() },
}))

jest.mock('@api/tasks/task-notifications.service', () => ({
TaskNotificationsService: jest.fn().mockImplementation(() => ({
sendTaskCreateNotifications: (...args: unknown[]) => mockSendTaskCreateNotifications(...args),
})),
}))

import { TaskNotificationsService } from '@api/tasks/task-notifications.service'

import { sendTaskCreateNotifications } from './send-task-create-notifications'

const taskConfig = sendTaskCreateNotifications as unknown as {
retry: {
maxAttempts: number
factor: number
minTimeoutInMs: number
maxTimeoutInMs: number
randomize: boolean
}
run: (payload: { user: unknown; task: TaskWithWorkflowState }, ctx: unknown) => Promise<unknown>
}

describe('sendTaskCreateNotifications job', () => {
beforeEach(() => {
jest.clearAllMocks()
mockSendTaskCreateNotifications.mockReset()
})

it('retries transient notification failures with bounded backoff', () => {
expect(taskConfig.retry).toEqual({
maxAttempts: 3,
factor: 2,
minTimeoutInMs: 1_000,
maxTimeoutInMs: 15_000,
randomize: true,
})
})

it('delegates notification delivery to TaskNotificationsService', async () => {
const user = { workspaceId: 'ws_1' }
const task = { id: 'task_1' } as TaskWithWorkflowState

await taskConfig.run({ user, task }, { ctx: { runId: 'run_1' } })

expect(TaskNotificationsService).toHaveBeenCalledWith(user)
expect(mockSendTaskCreateNotifications).toHaveBeenCalledWith(task)
})
})
1 change: 1 addition & 0 deletions src/jobs/notifications/send-task-create-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const sendTaskCreateNotifications = task({
queue: {
concurrencyLimit: 5,
},
retry: { maxAttempts: 3, factor: 2, minTimeoutInMs: 1_000, maxTimeoutInMs: 15_000, randomize: true },

run: async (payload: CreateTaskNotificationPayload, { ctx }) => {
logger.log('Sending task creation notifications for:', { payload, ctx })
Expand Down
Loading