This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
p61-project/tests/mocks/supabase/HabitProgress.ts

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-05-02 23:48:47 +02:00
import type { SupabaseHabitProgress } from "@/infrastructure/supabase/supabase"
import { HABIT_PROGRESS_MOCK } from "../domain/HabitProgress"
interface SupabaseHabitProgressMockCreateOptions {
id: SupabaseHabitProgress["id"]
habitId: SupabaseHabitProgress["habit_id"]
date?: Date
goalProgress: SupabaseHabitProgress["goal_progress"]
}
const supabaseHabitProgressMockCreate = (
options: SupabaseHabitProgressMockCreateOptions,
): SupabaseHabitProgress => {
const { id, habitId, date = new Date(), goalProgress } = options
return {
id,
habit_id: habitId,
date: date.toISOString(),
goal_progress: goalProgress,
}
}
const exampleByIds = Object.fromEntries(
Object.entries(HABIT_PROGRESS_MOCK.exampleByIds).map(
([id, habitProgress]) => {
return [
id,
supabaseHabitProgressMockCreate({
id: Number.parseInt(habitProgress.id, 10),
habitId: Number.parseInt(habitProgress.habitId, 10),
date: new Date(habitProgress.date),
goalProgress: habitProgress.goalProgress.isNumeric()
? habitProgress.goalProgress.progress
: habitProgress.goalProgress.isCompleted()
? 1
: 0,
}),
]
},
),
) as {
[key in keyof (typeof HABIT_PROGRESS_MOCK)["exampleByIds"]]: SupabaseHabitProgress
}
export const SUPABASE_HABIT_PROGRESS_MOCK = {
create: supabaseHabitProgressMockCreate,
exampleByIds,
examples: Object.values(exampleByIds),
}