@@ -22,6 +22,19 @@ describe('TimeEntryActionEffects', () => {
2222 let toastrService ;
2323 const entry : Entry = { project_id : 'p-id' , start_date : new Date ( ) , id : 'id' } ;
2424
25+ const dateTest = moment ( ) . format ( 'YYYY-MM-DD' ) ;
26+ const endHourTest = moment ( ) . subtract ( 5 , 'hours' ) . format ( 'HH:mm:ss' ) ;
27+ const startHourTest = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
28+ const endDateTest = new Date ( `${ dateTest } T${ endHourTest . trim ( ) } ` ) ;
29+ const startDateTest = new Date ( `${ dateTest } T${ startHourTest . trim ( ) } ` ) ;
30+
31+ const entryUpdate = {
32+ id : 'id' ,
33+ project_id : 'p-id' ,
34+ start_date : startDateTest ,
35+ start_hour : moment ( ) . subtract ( 1 , 'hours' ) . format ( 'HH:mm' ) ,
36+ } ;
37+
2538 beforeEach ( ( ) => {
2639 TestBed . configureTestingModule ( {
2740 providers : [
@@ -340,21 +353,33 @@ describe('TimeEntryActionEffects', () => {
340353 } ) ;
341354 } ) ;
342355
343- it ( 'action type is UPDATE_ENTRY when UPDATE_TWO_ENTRIES executed' , async ( ) => {
344- actions$ = of ( { type : EntryActionTypes . UPDATE_TWO_ENTRIES , payload : entry } ) ;
356+ it ( 'should update last entry when UPDATE_CURRENT_OR_LAST_ENTRY is executed' , async ( ) => {
357+ actions$ = of ( { type : EntryActionTypes . UPDATE_CURRENT_OR_LAST_ENTRY , payload : entry } ) ;
345358 spyOn ( service , 'loadEntries' ) . and . returnValue ( of ( [ entry , entry ] ) ) ;
346359
347- effects . updateLastEntryAndNew $. subscribe ( action => {
360+ effects . updateCurrentOrLastEntry $. subscribe ( action => {
348361 expect ( action . type ) . toEqual ( EntryActionTypes . UPDATE_ENTRY ) ;
349362 } ) ;
350363 } ) ;
351364
352- it ( 'action type is UPDATE_TWO_ENTRIES_FAIL when service fail in execution' , async ( ) => {
353- actions$ = of ( { type : EntryActionTypes . UPDATE_TWO_ENTRIES , payload : entry } ) ;
365+ it ( 'should update current entry when UPDATE_CURRENT_OR_LAST_ENTRY is executed' , async ( ) => {
366+ const lastEntry : Entry = { project_id : 'p-id' , start_date : new Date ( ) , id : 'id' , end_date : endDateTest } ;
367+ actions$ = of ( { type : EntryActionTypes . UPDATE_CURRENT_OR_LAST_ENTRY , payload : entryUpdate } ) ;
368+ spyOn ( service , 'loadEntries' ) . and . returnValue ( of ( [ lastEntry , lastEntry ] ) ) ;
369+ spyOn ( toastrService , 'success' ) ;
370+
371+ effects . updateCurrentOrLastEntry$ . subscribe ( action => {
372+ expect ( toastrService . success ) . toHaveBeenCalledWith ( 'You change the time-in successfully' ) ;
373+ expect ( action . type ) . toEqual ( EntryActionTypes . UPDATE_ENTRY_RUNNING ) ;
374+ } ) ;
375+ } ) ;
376+
377+ it ( 'action type is UPDATE_CURRENT_OR_LAST_ENTRY_FAIL when service fail in execution' , async ( ) => {
378+ actions$ = of ( { type : EntryActionTypes . UPDATE_CURRENT_OR_LAST_ENTRY , payload : entry } ) ;
354379 spyOn ( service , 'loadEntries' ) . and . returnValue ( throwError ( { error : { message : 'fail!' } } ) ) ;
355380
356- effects . updateLastEntryAndNew $. subscribe ( ( action ) => {
357- expect ( action . type ) . toEqual ( EntryActionTypes . UPDATE_TWO_ENTRIES_FAIL ) ;
381+ effects . updateCurrentOrLastEntry $. subscribe ( ( action ) => {
382+ expect ( action . type ) . toEqual ( EntryActionTypes . UPDATE_CURRENT_OR_LAST_ENTRY_FAIL ) ;
358383 } ) ;
359384 } ) ;
360385} ) ;
0 commit comments