Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/modules/time-clock/store/entry.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class LoadActiveEntry implements Action {

export class LoadActiveEntrySuccess implements Action {
readonly type = EntryActionTypes.LOAD_ACTIVE_ENTRY_SUCCESS;
constructor(readonly payload: NewEntry[]) {}
constructor(readonly payload) {}
}

export class LoadActiveEntryFail implements Action {
Expand Down
24 changes: 24 additions & 0 deletions src/app/modules/time-clock/store/entry.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ describe('TimeEntryActionEffects', () => {
});
});

it('returns a LOAD_ACTIVE_ENTRY_SUCCESS when the entry that is running it is in the same day', async () => {
const activeEntry = {start_date: new Date()};
actions$ = of({type: EntryActionTypes.LOAD_ACTIVE_ENTRY, activeEntry});
const serviceSpy = spyOn(service, 'loadActiveEntry');
serviceSpy.and.returnValue(of(activeEntry));

effects.loadActiveEntry$.subscribe(action => {
expect(action.type).toEqual(EntryActionTypes.LOAD_ACTIVE_ENTRY_SUCCESS);
});
});

it('returns a LOAD_ACTIVE_ENTRY_SUCCESS when the entry that is running it is in the same day', async () => {
const startDateInPast = new Date();
startDateInPast.setDate( startDateInPast.getDate() - 5);
const activeEntry = {start_date: startDateInPast};
actions$ = of({type: EntryActionTypes.LOAD_ACTIVE_ENTRY, activeEntry});
const serviceSpy = spyOn(service, 'loadActiveEntry');
serviceSpy.and.returnValue(of(activeEntry));

effects.loadActiveEntry$.subscribe(action => {
expect(action.type).toEqual(EntryActionTypes.UPDATE_ACTIVE_ENTRY);
});
});

// TODO Implement the remaining unit tests for the other effects.

});
16 changes: 15 additions & 1 deletion src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@ export class EntryEffects {
mergeMap(() =>
this.entryService.loadActiveEntry().pipe(
map((activeEntry) => {
return new actions.LoadActiveEntrySuccess(activeEntry);
if (activeEntry) {
const today = new Date();
const entryStartDate = new Date (activeEntry.start_date);
const isSameDay = (today.getDate() === entryStartDate.getDate()
&& today.getMonth() === entryStartDate.getMonth()
&& today.getFullYear() === entryStartDate.getFullYear());
if (isSameDay) {
return new actions.LoadActiveEntrySuccess(activeEntry);
} else {
const endDate = activeEntry.start_date;
endDate.setHours(23, 59, 59);
activeEntry.end_date = new Date(endDate.toISOString());
return new actions.UpdateActiveEntry(activeEntry);
}
}
}),
catchError((error) => {
return of(new actions.LoadActiveEntryFail(error));
Expand Down