File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed
src/app/modules/time-clock/store Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ export class LoadActiveEntry implements Action {
5252
5353export class LoadActiveEntrySuccess implements Action {
5454 readonly type = EntryActionTypes . LOAD_ACTIVE_ENTRY_SUCCESS ;
55- constructor ( readonly payload : NewEntry [ ] ) { }
55+ constructor ( readonly payload ) { }
5656}
5757
5858export class LoadActiveEntryFail implements Action {
Original file line number Diff line number Diff line change @@ -56,6 +56,30 @@ describe('TimeEntryActionEffects', () => {
5656 } ) ;
5757 } ) ;
5858
59+ it ( 'returns a LOAD_ACTIVE_ENTRY_SUCCESS when the entry that is running it is in the same day' , async ( ) => {
60+ const activeEntry = { start_date : new Date ( ) } ;
61+ actions$ = of ( { type : EntryActionTypes . LOAD_ACTIVE_ENTRY , activeEntry} ) ;
62+ const serviceSpy = spyOn ( service , 'loadActiveEntry' ) ;
63+ serviceSpy . and . returnValue ( of ( activeEntry ) ) ;
64+
65+ effects . loadActiveEntry$ . subscribe ( action => {
66+ expect ( action . type ) . toEqual ( EntryActionTypes . LOAD_ACTIVE_ENTRY_SUCCESS ) ;
67+ } ) ;
68+ } ) ;
69+
70+ it ( 'returns a LOAD_ACTIVE_ENTRY_SUCCESS when the entry that is running it is in the same day' , async ( ) => {
71+ const startDateInPast = new Date ( ) ;
72+ startDateInPast . setDate ( startDateInPast . getDate ( ) - 5 ) ;
73+ const activeEntry = { start_date : startDateInPast } ;
74+ actions$ = of ( { type : EntryActionTypes . LOAD_ACTIVE_ENTRY , activeEntry} ) ;
75+ const serviceSpy = spyOn ( service , 'loadActiveEntry' ) ;
76+ serviceSpy . and . returnValue ( of ( activeEntry ) ) ;
77+
78+ effects . loadActiveEntry$ . subscribe ( action => {
79+ expect ( action . type ) . toEqual ( EntryActionTypes . UPDATE_ACTIVE_ENTRY ) ;
80+ } ) ;
81+ } ) ;
82+
5983 // TODO Implement the remaining unit tests for the other effects.
6084
6185} ) ;
Original file line number Diff line number Diff line change @@ -34,7 +34,21 @@ export class EntryEffects {
3434 mergeMap ( ( ) =>
3535 this . entryService . loadActiveEntry ( ) . pipe (
3636 map ( ( activeEntry ) => {
37- return new actions . LoadActiveEntrySuccess ( activeEntry ) ;
37+ if ( activeEntry ) {
38+ const today = new Date ( ) ;
39+ const entryStartDate = new Date ( activeEntry . start_date ) ;
40+ const isSameDay = ( today . getDate ( ) === entryStartDate . getDate ( )
41+ && today . getMonth ( ) === entryStartDate . getMonth ( )
42+ && today . getFullYear ( ) === entryStartDate . getFullYear ( ) ) ;
43+ if ( isSameDay ) {
44+ return new actions . LoadActiveEntrySuccess ( activeEntry ) ;
45+ } else {
46+ const endDate = activeEntry . start_date ;
47+ endDate . setHours ( 23 , 59 , 59 ) ;
48+ activeEntry . end_date = new Date ( endDate . toISOString ( ) ) ;
49+ return new actions . UpdateActiveEntry ( activeEntry ) ;
50+ }
51+ }
3852 } ) ,
3953 catchError ( ( error ) => {
4054 return of ( new actions . LoadActiveEntryFail ( error ) ) ;
You can’t perform that action at this time.
0 commit comments