1- import { TestBed } from '@angular/core/testing' ;
21import { TimePlanningPnPlanningsService } from './time-planning-pn-plannings.service' ;
32import { ApiBaseService } from 'src/app/common/services' ;
43import { of } from 'rxjs' ;
54
65describe ( 'TimePlanningPnPlanningsService' , ( ) => {
76 let service : TimePlanningPnPlanningsService ;
8- let mockApiBaseService : jasmine . SpyObj < ApiBaseService > ;
7+ let mockApiBaseService : jest . Mocked < ApiBaseService > ;
98
109 beforeEach ( ( ) => {
11- mockApiBaseService = jasmine . createSpyObj ( 'ApiBaseService' , [ 'post' , 'put' , 'get' ] ) ;
10+ mockApiBaseService = {
11+ post : jest . fn ( ) ,
12+ put : jest . fn ( ) ,
13+ get : jest . fn ( ) ,
14+ } as any ;
1215
13- TestBed . configureTestingModule ( {
14- providers : [
15- TimePlanningPnPlanningsService ,
16- { provide : ApiBaseService , useValue : mockApiBaseService }
17- ]
18- } ) ;
19-
20- service = TestBed . inject ( TimePlanningPnPlanningsService ) ;
16+ service = new TimePlanningPnPlanningsService ( mockApiBaseService ) ;
2117 } ) ;
2218
2319 it ( 'should be created' , ( ) => {
2420 expect ( service ) . toBeTruthy ( ) ;
2521 } ) ;
2622
2723 describe ( 'getPlannings' , ( ) => {
28- it ( 'should call apiBaseService.post with correct parameters' , ( ) => {
24+ it ( 'should call apiBaseService.post with correct parameters' , ( done ) => {
2925 const mockRequest = {
3026 dateFrom : '2024-01-01' ,
3127 dateTo : '2024-01-07' ,
@@ -35,10 +31,11 @@ describe('TimePlanningPnPlanningsService', () => {
3531 showResignedSites : false
3632 } ;
3733 const mockResponse = { success : true , model : [ ] } ;
38- mockApiBaseService . post . and . returnValue ( of ( mockResponse as any ) ) ;
34+ mockApiBaseService . post . mockReturnValue ( of ( mockResponse as any ) ) ;
3935
4036 service . getPlannings ( mockRequest ) . subscribe ( result => {
4137 expect ( result ) . toEqual ( mockResponse as any ) ;
38+ done ( ) ;
4239 } ) ;
4340
4441 expect ( mockApiBaseService . post ) . toHaveBeenCalledWith (
@@ -47,7 +44,7 @@ describe('TimePlanningPnPlanningsService', () => {
4744 ) ;
4845 } ) ;
4946
50- it ( 'should handle empty response' , ( ) => {
47+ it ( 'should handle empty response' , ( done ) => {
5148 const mockRequest = {
5249 dateFrom : '2024-01-01' ,
5350 dateTo : '2024-01-07' ,
@@ -57,27 +54,29 @@ describe('TimePlanningPnPlanningsService', () => {
5754 showResignedSites : false
5855 } ;
5956 const mockResponse = { success : true , model : [ ] } ;
60- mockApiBaseService . post . and . returnValue ( of ( mockResponse as any ) ) ;
57+ mockApiBaseService . post . mockReturnValue ( of ( mockResponse as any ) ) ;
6158
6259 service . getPlannings ( mockRequest ) . subscribe ( result => {
6360 expect ( result . model ) . toEqual ( [ ] ) ;
61+ done ( ) ;
6462 } ) ;
6563 } ) ;
6664 } ) ;
6765
6866 describe ( 'updatePlanning' , ( ) => {
69- it ( 'should call apiBaseService.put with correct parameters' , ( ) => {
67+ it ( 'should call apiBaseService.put with correct parameters' , ( done ) => {
7068 const mockPlanningModel = {
7169 id : 123 ,
7270 planHours : 8 ,
7371 message : 1 ,
7472 planText : 'Test planning'
7573 } as any ;
7674 const mockResponse = { success : true } ;
77- mockApiBaseService . put . and . returnValue ( of ( mockResponse as any ) ) ;
75+ mockApiBaseService . put . mockReturnValue ( of ( mockResponse as any ) ) ;
7876
7977 service . updatePlanning ( mockPlanningModel , 123 ) . subscribe ( result => {
8078 expect ( result ) . toEqual ( mockResponse as any ) ;
79+ done ( ) ;
8180 } ) ;
8281
8382 expect ( mockApiBaseService . put ) . toHaveBeenCalledWith (
@@ -89,7 +88,7 @@ describe('TimePlanningPnPlanningsService', () => {
8988 it ( 'should construct correct URL with id parameter' , ( ) => {
9089 const mockPlanningModel = { id : 456 } as any ;
9190 const mockResponse = { success : true } ;
92- mockApiBaseService . put . and . returnValue ( of ( mockResponse as any ) ) ;
91+ mockApiBaseService . put . mockReturnValue ( of ( mockResponse as any ) ) ;
9392
9493 service . updatePlanning ( mockPlanningModel , 456 ) . subscribe ( ) ;
9594
0 commit comments