1+ module ForestLiana
2+ describe LineStatGetter do
3+ describe 'Check client_timezone function' do
4+ describe 'with a SQLite database' do
5+ it 'should return nil' do
6+ expect ( LineStatGetter . new ( Owner , {
7+ timezone : "Europe/Paris" ,
8+ aggregate : "Count" ,
9+ } ) . client_timezone ) . to eq ( nil )
10+ end
11+ end
12+
13+ describe 'with a non-SQLite database' do
14+ it 'should return the timezone' do
15+ ActiveRecord ::Base . connection . stub ( :adapter_name ) { 'NotSQLite' }
16+ expect ( LineStatGetter . new ( Owner , {
17+ timezone : "Europe/Paris" ,
18+ aggregate : "Count" ,
19+ } ) . client_timezone ) . to eq ( 'Europe/Paris' )
20+ end
21+ end
22+ end
23+
24+ describe 'Check perform function' do
25+ describe 'Using a Count aggregation' do
26+ describe 'Using a Week time range' do
27+ it 'should return consistent data based on monday as week_start ' do
28+
29+ # Week should start on monday
30+ # 08-05-2021 was a Saturday
31+ Owner . create ( name : 'Michel' , hired_at : Date . parse ( '08-05-2021' ) ) ;
32+ Owner . create ( name : 'Robert' , hired_at : Date . parse ( '09-05-2021' ) ) ;
33+ Owner . create ( name : 'José' , hired_at : Date . parse ( '10-05-2021' ) ) ;
34+ Owner . create ( name : 'Yves' , hired_at : Date . parse ( '11-05-2021' ) ) ;
35+
36+ stat = LineStatGetter . new ( Owner , {
37+ timezone : "Europe/Paris" ,
38+ aggregate : "Count" ,
39+ time_range : "Week" ,
40+ group_by_date_field : "hired_at" ,
41+ } ) . perform
42+
43+ expect ( stat . value . find { |item | item [ :label ] == "W18-2021" } [ :values ] [ :value ] ) . to eq ( 2 )
44+ expect ( stat . value . find { |item | item [ :label ] == "W19-2021" } [ :values ] [ :value ] ) . to eq ( 2 )
45+ end
46+ end
47+ end
48+ end
49+ end
50+ end
0 commit comments