@@ -35,12 +35,12 @@ describe('AuditLogDialogComponent', () => {
3535 success : true ,
3636 } ;
3737
38- const mockAuditLogResponse : AuditLogResponse = {
38+ const createMockAuditLogResponse = ( ) : AuditLogResponse => ( {
3939 data : [ mockAuditLogEntry ] ,
4040 pagination : { total : 1 , currentPage : 1 , perPage : 20 , lastPage : 1 } ,
41- } ;
41+ } ) ;
4242
43- const mockMultipleLogsResponse : AuditLogResponse = {
43+ const createMockMultipleLogsResponse = ( ) : AuditLogResponse => ( {
4444 data : [
4545 mockAuditLogEntry ,
4646 {
@@ -74,11 +74,11 @@ describe('AuditLogDialogComponent', () => {
7474 } ,
7575 ] ,
7676 pagination : { total : 5 , currentPage : 1 , perPage : 20 , lastPage : 1 } ,
77- } ;
77+ } ) ;
7878
7979 beforeEach ( async ( ) => {
8080 mockSecretsService = jasmine . createSpyObj ( 'SecretsService' , [ 'getAuditLog' ] ) ;
81- mockSecretsService . getAuditLog . and . returnValue ( of ( mockAuditLogResponse ) ) ;
81+ mockSecretsService . getAuditLog . and . callFake ( ( ) => of ( createMockAuditLogResponse ( ) ) ) ;
8282
8383 mockDialogRef = jasmine . createSpyObj ( 'MatDialogRef' , [ 'close' ] ) ;
8484
@@ -204,23 +204,23 @@ describe('AuditLogDialogComponent', () => {
204204 describe ( 'loadAuditLog' , ( ) => {
205205 it ( 'should set loading to true while fetching' , ( ) => {
206206 component . loading = false ;
207- mockSecretsService . getAuditLog . and . returnValue ( of ( mockAuditLogResponse ) ) ;
207+ mockSecretsService . getAuditLog . and . callFake ( ( ) => of ( createMockAuditLogResponse ( ) ) ) ;
208208
209209 component . loadAuditLog ( ) ;
210210
211211 expect ( component . loading ) . toBeFalse ( ) ;
212212 } ) ;
213213
214214 it ( 'should update logs on successful fetch' , ( ) => {
215- mockSecretsService . getAuditLog . and . returnValue ( of ( mockMultipleLogsResponse ) ) ;
215+ mockSecretsService . getAuditLog . and . callFake ( ( ) => of ( createMockMultipleLogsResponse ( ) ) ) ;
216216
217217 component . loadAuditLog ( ) ;
218218
219219 expect ( component . logs . length ) . toBe ( 5 ) ;
220220 } ) ;
221221
222222 it ( 'should update pagination on successful fetch' , ( ) => {
223- mockSecretsService . getAuditLog . and . returnValue ( of ( mockMultipleLogsResponse ) ) ;
223+ mockSecretsService . getAuditLog . and . callFake ( ( ) => of ( createMockMultipleLogsResponse ( ) ) ) ;
224224
225225 component . loadAuditLog ( ) ;
226226
@@ -246,6 +246,11 @@ describe('AuditLogDialogComponent', () => {
246246 length : 100
247247 } ;
248248
249+ // Update mock to return pagination matching the page change
250+ mockSecretsService . getAuditLog . and . callFake ( ( ) => of ( {
251+ data : [ mockAuditLogEntry ] ,
252+ pagination : { total : 100 , currentPage : 3 , perPage : 50 , lastPage : 2 }
253+ } ) ) ;
249254 mockSecretsService . getAuditLog . calls . reset ( ) ;
250255 component . onPageChange ( pageEvent ) ;
251256
@@ -270,7 +275,7 @@ describe('AuditLogDialogComponent', () => {
270275
271276 describe ( 'with multiple audit log entries' , ( ) => {
272277 beforeEach ( ( ) => {
273- mockSecretsService . getAuditLog . and . returnValue ( of ( mockMultipleLogsResponse ) ) ;
278+ mockSecretsService . getAuditLog . and . callFake ( ( ) => of ( createMockMultipleLogsResponse ( ) ) ) ;
274279 component . loadAuditLog ( ) ;
275280 } ) ;
276281
0 commit comments