mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 21:04:03 +00:00
refactor(bot): replace reminder polling with scheduled dispatches
This commit is contained in:
46
apps/bot/src/aws-scheduled-dispatch-scheduler.test.ts
Normal file
46
apps/bot/src/aws-scheduled-dispatch-scheduler.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
|
||||
import { Temporal } from '@household/domain'
|
||||
|
||||
import { createAwsScheduledDispatchScheduler } from './aws-scheduled-dispatch-scheduler'
|
||||
|
||||
describe('createAwsScheduledDispatchScheduler', () => {
|
||||
test('creates one-shot EventBridge schedules targeting the bot lambda', async () => {
|
||||
const calls: unknown[] = []
|
||||
const scheduler = createAwsScheduledDispatchScheduler({
|
||||
region: 'eu-central-1',
|
||||
targetLambdaArn: 'arn:aws:lambda:eu-central-1:123:function:bot',
|
||||
roleArn: 'arn:aws:iam::123:role/scheduler',
|
||||
groupName: 'dispatches',
|
||||
client: {
|
||||
send: async (command) => {
|
||||
calls.push(command.input)
|
||||
return {}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = await scheduler.scheduleOneShotDispatch({
|
||||
dispatchId: 'dispatch-1',
|
||||
dueAt: Temporal.Instant.from('2026-03-24T12:00:00Z')
|
||||
})
|
||||
|
||||
expect(result.providerDispatchId).toContain('dispatch-dispatch-1-')
|
||||
expect(calls[0]).toMatchObject({
|
||||
GroupName: 'dispatches',
|
||||
ScheduleExpression: 'at(2026-03-24T12:00:00Z)',
|
||||
ActionAfterCompletion: 'DELETE',
|
||||
FlexibleTimeWindow: {
|
||||
Mode: 'OFF'
|
||||
},
|
||||
Target: {
|
||||
Arn: 'arn:aws:lambda:eu-central-1:123:function:bot',
|
||||
RoleArn: 'arn:aws:iam::123:role/scheduler',
|
||||
Input: JSON.stringify({
|
||||
source: 'household.scheduled-dispatch',
|
||||
dispatchId: 'dispatch-1'
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user