mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 11:54:03 +00:00
fix(review): harden miniapp auth and finance flows
This commit is contained in:
@@ -232,11 +232,12 @@ export function createFinanceCommandService(repository: FinanceRepository): Fina
|
||||
|
||||
await repository.openCycle(period, currency)
|
||||
|
||||
return {
|
||||
id: '',
|
||||
period,
|
||||
currency
|
||||
const cycle = await repository.getCycleByPeriod(period)
|
||||
if (!cycle) {
|
||||
throw new Error(`Failed to load billing cycle for period ${period}`)
|
||||
}
|
||||
|
||||
return cycle
|
||||
},
|
||||
|
||||
async closeCycle(periodArg) {
|
||||
|
||||
@@ -44,6 +44,10 @@ describe('createReminderJobService', () => {
|
||||
|
||||
test('claims a dispatch once and returns the dedupe key', async () => {
|
||||
const repository = new ReminderDispatchRepositoryStub()
|
||||
repository.nextResult = {
|
||||
dedupeKey: '2026-03:rent-due',
|
||||
claimed: true
|
||||
}
|
||||
const service = createReminderJobService(repository)
|
||||
|
||||
const result = await service.handleJob({
|
||||
@@ -53,6 +57,7 @@ describe('createReminderJobService', () => {
|
||||
})
|
||||
|
||||
expect(result.status).toBe('claimed')
|
||||
expect(result.dedupeKey).toBe('2026-03:rent-due')
|
||||
expect(repository.lastClaim).toMatchObject({
|
||||
householdId: 'household-1',
|
||||
period: '2026-03',
|
||||
|
||||
@@ -11,6 +11,10 @@ function computePayloadHash(payload: object): string {
|
||||
return createHash('sha256').update(JSON.stringify(payload)).digest('hex')
|
||||
}
|
||||
|
||||
function buildReminderDedupeKey(period: string, reminderType: ReminderType): string {
|
||||
return `${period}:${reminderType}`
|
||||
}
|
||||
|
||||
function createReminderMessage(reminderType: ReminderType, period: string): string {
|
||||
switch (reminderType) {
|
||||
case 'utilities':
|
||||
@@ -56,7 +60,7 @@ export function createReminderJobService(
|
||||
if (input.dryRun === true) {
|
||||
return {
|
||||
status: 'dry-run',
|
||||
dedupeKey: `${period}:${input.reminderType}`,
|
||||
dedupeKey: buildReminderDedupeKey(period, input.reminderType),
|
||||
payloadHash,
|
||||
reminderType: input.reminderType,
|
||||
period,
|
||||
|
||||
Reference in New Issue
Block a user