11import { INFO_SAVED_SUCCESSFULLY } from './../../shared/messages' ;
2- import { TestBed } from '@angular/core/testing' ;
3- import { provideMockActions } from '@ngrx/effects/testing' ;
4- import { EntryEffects } from './entry.effects' ;
5- import { Observable , of , throwError } from 'rxjs' ;
6- import { HttpClientTestingModule } from '@angular/common/http/testing' ;
2+ import { TestBed } from '@angular/core/testing' ;
3+ import { provideMockActions } from '@ngrx/effects/testing' ;
4+ import { EntryEffects } from './entry.effects' ;
5+ import { Observable , of , throwError } from 'rxjs' ;
6+ import { HttpClientTestingModule } from '@angular/common/http/testing' ;
77import { ToastrModule , ToastrService } from 'ngx-toastr' ;
8- import { Action } from '@ngrx/store' ;
9- import { DatePipe } from '@angular/common' ;
10- import { EntryActionTypes } from './entry.actions' ;
11- import { EntryService } from '../services/entry.service' ;
12- import { TimeEntriesTimeRange } from '../models/time-entries-time-range' ;
8+ import { Action } from '@ngrx/store' ;
9+ import { DatePipe } from '@angular/common' ;
10+ import { EntryActionTypes } from './entry.actions' ;
11+ import { EntryService } from '../services/entry.service' ;
12+ import { TimeEntriesTimeRange } from '../models/time-entries-time-range' ;
13+ import * as moment from 'moment' ;
1314
1415describe ( 'TimeEntryActionEffects' , ( ) => {
1516
@@ -37,7 +38,7 @@ describe('TimeEntryActionEffects', () => {
3738 expect ( effects ) . toBeTruthy ( ) ;
3839 } ) ;
3940
40- it ( 'returns an action with type LOAD_ENTRIES_SUMMARY_SUCCESS when the service returns a value' , ( ) => {
41+ it ( 'returns an action with type LOAD_ENTRIES_SUMMARY_SUCCESS when the service returns a value' , ( ) => {
4142 actions$ = of ( { type : EntryActionTypes . LOAD_ENTRIES_SUMMARY } ) ;
4243 const serviceSpy = spyOn ( service , 'summary' ) ;
4344 serviceSpy . and . returnValue ( of ( { } ) ) ;
@@ -47,7 +48,7 @@ describe('TimeEntryActionEffects', () => {
4748 } ) ;
4849 } ) ;
4950
50- it ( 'returns an action with type LOAD_ENTRIES_SUMMARY_FAIL when the service fails' , ( ) => {
51+ it ( 'returns an action with type LOAD_ENTRIES_SUMMARY_FAIL when the service fails' , ( ) => {
5152 actions$ = of ( { type : EntryActionTypes . LOAD_ENTRIES_SUMMARY } ) ;
5253 spyOn ( service , 'summary' ) . and . returnValue ( throwError ( 'any error' ) ) ;
5354
@@ -56,9 +57,10 @@ describe('TimeEntryActionEffects', () => {
5657 } ) ;
5758 } ) ;
5859
59- it ( 'When the service returns a value, then LOAD_ENTRIES_BY_TIME_RANGE_SUCCESS should be triggered' , ( ) => {
60- const timeRange : TimeEntriesTimeRange = { start_date : new Date ( ) , end_date : new Date ( ) , user_id : '*' } ;
61- actions$ = of ( { type : EntryActionTypes . LOAD_ENTRIES_BY_TIME_RANGE , timeRange} ) ;
60+ it ( 'When the service returns a value, then LOAD_ENTRIES_BY_TIME_RANGE_SUCCESS should be triggered' , ( ) => {
61+ const timeRange : TimeEntriesTimeRange = { start_date : moment ( new Date ( ) ) , end_date : moment ( new Date ( ) ) } ;
62+ const userId = '*' ;
63+ actions$ = of ( { type : EntryActionTypes . LOAD_ENTRIES_BY_TIME_RANGE , timeRange, userId} ) ;
6264 const serviceSpy = spyOn ( service , 'loadEntriesByTimeRange' ) ;
6365 serviceSpy . and . returnValue ( of ( [ ] ) ) ;
6466
@@ -69,13 +71,14 @@ describe('TimeEntryActionEffects', () => {
6971 } ) ;
7072
7173 it ( 'When the service fails, then LOAD_ENTRIES_BY_TIME_RANGE_FAIL should be triggered' , async ( ) => {
72- const timeRange : TimeEntriesTimeRange = { start_date : new Date ( ) , end_date : new Date ( ) , user_id : '*' } ;
73- actions$ = of ( { type : EntryActionTypes . LOAD_ENTRIES_BY_TIME_RANGE , timeRange} ) ;
74- spyOn ( service , 'loadEntriesByTimeRange' ) . and . returnValue ( throwError ( 'any error' ) ) ;
74+ const timeRange : TimeEntriesTimeRange = { start_date : moment ( new Date ( ) ) , end_date : moment ( new Date ( ) ) } ;
75+ const userId = '*' ;
76+ actions$ = of ( { type : EntryActionTypes . LOAD_ENTRIES_BY_TIME_RANGE , timeRange, userId} ) ;
77+ spyOn ( service , 'loadEntriesByTimeRange' ) . and . returnValue ( throwError ( 'any error' ) ) ;
7578
76- effects . loadEntriesByTimeRange$ . subscribe ( action => {
77- expect ( action . type ) . toEqual ( EntryActionTypes . LOAD_ENTRIES_BY_TIME_RANGE_FAIL ) ;
78- } ) ;
79+ effects . loadEntriesByTimeRange$ . subscribe ( action => {
80+ expect ( action . type ) . toEqual ( EntryActionTypes . LOAD_ENTRIES_BY_TIME_RANGE_FAIL ) ;
81+ } ) ;
7982 } ) ;
8083
8184 it ( 'returns a LOAD_ACTIVE_ENTRY_SUCCESS when the entry that is running it is in the same day' , async ( ) => {
@@ -91,7 +94,7 @@ describe('TimeEntryActionEffects', () => {
9194
9295 it ( 'returns a LOAD_ACTIVE_ENTRY_SUCCESS when the entry that is running it is in the same day' , async ( ) => {
9396 const startDateInPast = new Date ( ) ;
94- startDateInPast . setDate ( startDateInPast . getDate ( ) - 5 ) ;
97+ startDateInPast . setDate ( startDateInPast . getDate ( ) - 5 ) ;
9598 const activeEntry = { start_date : startDateInPast } ;
9699 actions$ = of ( { type : EntryActionTypes . LOAD_ACTIVE_ENTRY , activeEntry} ) ;
97100 const serviceSpy = spyOn ( service , 'loadActiveEntry' ) ;
0 commit comments