import { datatype } from 'faker' import { TeleconsultationsCredit, TeleconsultationCreditReason, Appointment } from '../../models' import { factory } from '../../../test/factories' describe('TeleconsultationsCredit', () => { let subject: TeleconsultationsCredit beforeAll(async () => { subject = new TeleconsultationsCredit() }) afterEach(() => { jest.resetAllMocks() }) afterAll(() => { jest.restoreAllMocks() }) describe('.createBy', () => { const objectModel = { id: datatype.uuid() } beforeEach(async () => { subject = await factory.build('teleconsultations_credit') }) describe('when reason is related to an appointment', () => { describe.each` reason ${`appointment_cancellation`} ${`appointment_use`} `('when the reason is "$reason"', ({ reason }) => { beforeEach(() => { subject = TeleconsultationsCredit.createBy({ ...subject, objectModel: objectModel as Appointment, reason: reason as TeleconsultationCreditReason, }) }) it('adds the appointment id', async () => { expect(subject.appointment_id).toEqual(objectModel.id) }) }) }) describe('when reason is related to a subscription', () => { describe.each` reason ${`period_renewal`} ${`end_of_period_expiration`} ${`plan_subscription`} `('when the reason is "$reason"', ({ reason }) => { beforeEach(() => { subject = TeleconsultationsCredit.createBy({ ...subject, objectModel: objectModel as Appointment, reason: reason as TeleconsultationCreditReason, }) }) it('adds the appointment id', async () => { expect(subject.subscription_id).toEqual(objectModel.id) }) }) }) }) })