import { subMonths } from 'date-fns' import { factory } from 'factory-bot' import { datatype, random } from 'faker' import { sample } from 'lodash' import { Appointment, AppointmentCancellationReasons, AppointmentCancelReason } from '../../src/models' export const AVG_CONSULTATION_DURATION = 2700 factory.define( 'appointment', Appointment, { id: () => datatype.uuid(), assistant_user_id: () => datatype.uuid(), patient_id: () => datatype.uuid(), user_id: () => datatype.uuid(), state: () => 'scheduled', created_at: () => subMonths(new Date(), 1), updated_at: () => subMonths(new Date(), 1), scheduled_to: () => subMonths(new Date(), 1), timezone: () => '-03', consultation_duration_in_seconds: () => AVG_CONSULTATION_DURATION, is_return: () => datatype.boolean(), origin_appointment_id: () => datatype.uuid(), }, Appointment, ) factory.extend('appointment', 'appointment:cancelled', { state: () => 'cancelled', canceled_at: () => subMonths(new Date(), 1), }) factory.extend('appointment', 'appointment:food_plan_pending', { state: () => 'food_plan_pending', consultation_started_at: () => subMonths(new Date(), 1), consultation_finished_at: () => subMonths(new Date(), 1), }) factory.extend('appointment:food_plan_pending', 'appointment:food_plan_in_construction', { state: () => 'food_plan_in_construction', }) factory.extend('appointment:food_plan_in_construction', 'appointment:finished', { state: () => 'finished', finished_at: () => subMonths(new Date(), 1), }) factory.extend('appointment', 'appointment:patient', { patient: factory.build('patient'), }) factory.define( 'appointment_cancel_reason', AppointmentCancelReason, { value: () => sample(Object.values(AppointmentCancellationReasons)), description: random.words, decrease_credit: datatype.boolean, visible: datatype.boolean, block_when_transfer: datatype.boolean, type: () => sample(['nutritionist', 'patient']), }, AppointmentCancelReason, ) export { factory }