@@ -102,7 +102,7 @@ describe('Vaccination service', () => {
102102 ) ;
103103 expect ( vaccinationRepository . findAllVaccinations ) . toHaveBeenCalledWith (
104104 userId ,
105- { animalId : query . animalId } ,
105+ { where : { animalId : query . animalId } , limit : 10 , offset : 0 } ,
106106 ) ;
107107 } ) ;
108108
@@ -203,13 +203,15 @@ describe('Vaccination service', () => {
203203 } ) ;
204204
205205 test ( 'It should return a new vaccination' , async ( ) => {
206- vaccinationRepository . create . mockResolvedValue ( {
206+ const newVaccination = {
207207 ...dbResponse ,
208208 id : fakeUuid ,
209209 vaccine : vaccinationData . vaccine ,
210210 description : vaccinationData . description ,
211- } ) ;
211+ } ;
212+ vaccinationRepository . create . mockResolvedValue ( newVaccination ) ;
212213 animalRepository . findOne . mockResolvedValue ( animal1 ( ) ) ;
214+ vaccinationRepository . findOne . mockResolvedValue ( newVaccination ) ;
213215
214216 const result = await createVaccination ( userId , vaccinationData ) ;
215217
@@ -287,8 +289,9 @@ describe('Vaccination service', () => {
287289 } ) ;
288290
289291 test ( 'It should return an updated vaccination' , async ( ) => {
290- vaccinationRepository . findOne . mockResolvedValue ( vaccination1 ( ) ) ;
292+ vaccinationRepository . findOne . mockResolvedValueOnce ( vaccination1 ( ) ) ;
291293 vaccinationRepository . update . mockResolvedValue ( [ 1 , [ dbResponse ] ] ) ;
294+ vaccinationRepository . findOne . mockResolvedValueOnce ( dbResponse ) ;
292295
293296 const result = await updateVaccination (
294297 userId ,
@@ -299,15 +302,16 @@ describe('Vaccination service', () => {
299302 expect ( result . id ) . toBe ( vaccinationId ) ;
300303 expect ( result . vaccine ) . toBe ( vaccinationData . vaccine ) ;
301304 expect ( result . description ) . toBe ( vaccinationData . description ) ;
302- expect ( vaccinationRepository . findOne ) . toHaveBeenCalledTimes ( 1 ) ;
305+ expect ( vaccinationRepository . findOne ) . toHaveBeenCalledTimes ( 2 ) ;
303306 expect ( vaccinationRepository . update ) . toHaveBeenCalledTimes ( 1 ) ;
304307 } ) ;
305308
306309 test ( 'It should return an updated vaccination with only name updated' , async ( ) => {
307310 delete vaccinationData . description ;
308311
309- vaccinationRepository . findOne . mockResolvedValue ( vaccination1 ( ) ) ;
312+ vaccinationRepository . findOne . mockResolvedValueOnce ( vaccination1 ( ) ) ;
310313 vaccinationRepository . update . mockResolvedValue ( [ 1 , [ dbResponse ] ] ) ;
314+ vaccinationRepository . findOne . mockResolvedValueOnce ( dbResponse ) ;
311315
312316 const result = await updateVaccination (
313317 userId ,
@@ -318,7 +322,7 @@ describe('Vaccination service', () => {
318322 expect ( result . id ) . toBe ( vaccinationId ) ;
319323 expect ( result . vaccine ) . toBe ( vaccinationData . vaccine ) ;
320324 expect ( result . description ) . not . toBe ( vaccinationData . description ) ;
321- expect ( vaccinationRepository . findOne ) . toHaveBeenCalledTimes ( 1 ) ;
325+ expect ( vaccinationRepository . findOne ) . toHaveBeenCalledTimes ( 2 ) ;
322326 expect ( vaccinationRepository . update ) . toHaveBeenCalledTimes ( 1 ) ;
323327 } ) ;
324328
0 commit comments