fix(review): harden miniapp auth and finance flows

This commit is contained in:
2026-03-09 00:30:31 +04:00
parent 91a040f2ee
commit c8b17136be
22 changed files with 327 additions and 157 deletions

View File

@@ -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) {

View File

@@ -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',

View File

@@ -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,