@@ -18,6 +18,9 @@ import type { PerAccountState } from '../../reduxTypes';
18
18
19
19
const currentTimestamp = Date . now ( ) / 1000 ;
20
20
21
+ // TODO test offlineThresholdSeconds varying
22
+ const offlineThresholdSeconds = 140 ;
23
+
21
24
describe ( 'getAggregatedPresence' , ( ) => {
22
25
const oldAggregatedClientPresence = {
23
26
client : 'website' ,
@@ -27,11 +30,18 @@ describe('getAggregatedPresence', () => {
27
30
28
31
test ( 'aggregated status is active if any of the client has status active with age less than threshold' , ( ) => {
29
32
expect (
30
- getAggregatedPresence ( {
31
- website : { client : 'website' , timestamp : currentTimestamp - 100 , status : 'idle' } ,
32
- zulipMobile : { client : 'zulipMobile' , timestamp : currentTimestamp - 120 , status : 'active' } ,
33
- aggregated : oldAggregatedClientPresence ,
34
- } ) ,
33
+ getAggregatedPresence (
34
+ {
35
+ website : { client : 'website' , timestamp : currentTimestamp - 100 , status : 'idle' } ,
36
+ zulipMobile : {
37
+ client : 'zulipMobile' ,
38
+ timestamp : currentTimestamp - 120 ,
39
+ status : 'active' ,
40
+ } ,
41
+ aggregated : oldAggregatedClientPresence ,
42
+ } ,
43
+ offlineThresholdSeconds ,
44
+ ) ,
35
45
) . toEqual ( {
36
46
client : 'zulipMobile' ,
37
47
status : 'active' ,
@@ -41,49 +51,86 @@ describe('getAggregatedPresence', () => {
41
51
42
52
test ( 'aggregated status is idle if any of the client has status idle with age less than threshold and no client has status active with age has than threshold' , ( ) => {
43
53
expect (
44
- getAggregatedPresence ( {
45
- website : { client : 'website' , timestamp : currentTimestamp - 100 , status : 'idle' } ,
46
- zulipMobile : { client : 'zulipMobile' , timestamp : currentTimestamp - 220 , status : 'active' } ,
47
- aggregated : oldAggregatedClientPresence ,
48
- } ) ,
54
+ getAggregatedPresence (
55
+ {
56
+ website : { client : 'website' , timestamp : currentTimestamp - 100 , status : 'idle' } ,
57
+ zulipMobile : {
58
+ client : 'zulipMobile' ,
59
+ timestamp : currentTimestamp - 220 ,
60
+ status : 'active' ,
61
+ } ,
62
+ aggregated : oldAggregatedClientPresence ,
63
+ } ,
64
+ offlineThresholdSeconds ,
65
+ ) ,
49
66
) . toEqual ( { client : 'website' , status : 'idle' , timestamp : currentTimestamp - 100 } ) ;
50
67
} ) ;
51
68
52
69
test ( 'aggregated status is offline if no client has status active or idle with age less than threshold' , ( ) => {
53
70
expect (
54
- getAggregatedPresence ( {
55
- zulipMobile : { client : 'zulipMobile' , timestamp : currentTimestamp - 400 , status : 'active' } ,
56
- website : { client : 'website' , timestamp : currentTimestamp - 200 , status : 'idle' } ,
57
- zulipAndroid : {
58
- client : 'zulipAndroid' ,
59
- timestamp : currentTimestamp - 500 ,
60
- status : 'active' ,
71
+ getAggregatedPresence (
72
+ {
73
+ zulipMobile : {
74
+ client : 'zulipMobile' ,
75
+ timestamp : currentTimestamp - 400 ,
76
+ status : 'active' ,
77
+ } ,
78
+ website : { client : 'website' , timestamp : currentTimestamp - 200 , status : 'idle' } ,
79
+ zulipAndroid : {
80
+ client : 'zulipAndroid' ,
81
+ timestamp : currentTimestamp - 500 ,
82
+ status : 'active' ,
83
+ } ,
84
+ aggregated : oldAggregatedClientPresence ,
61
85
} ,
62
- aggregated : oldAggregatedClientPresence ,
63
- } ) ,
86
+ offlineThresholdSeconds ,
87
+ ) ,
64
88
) . toEqual ( { client : '' , timestamp : currentTimestamp - 200 , status : 'offline' } ) ;
65
89
} ) ;
66
90
67
- test ( 'do not consider presence if its age is greater than OFFLINE_THRESHOLD_SECS ' , ( ) => {
91
+ test ( 'do not consider presence if its age is greater than offline threshold ' , ( ) => {
68
92
expect (
69
- getAggregatedPresence ( {
70
- website : { client : 'website' , timestamp : currentTimestamp - 300 , status : 'active' } ,
71
- zulipMobile : { client : 'zulipMobile' , timestamp : currentTimestamp - 10 , status : 'idle' } ,
72
- aggregated : oldAggregatedClientPresence ,
73
- } ) ,
93
+ getAggregatedPresence (
94
+ {
95
+ website : { client : 'website' , timestamp : currentTimestamp - 300 , status : 'active' } ,
96
+ zulipMobile : { client : 'zulipMobile' , timestamp : currentTimestamp - 10 , status : 'idle' } ,
97
+ aggregated : oldAggregatedClientPresence ,
98
+ } ,
99
+ offlineThresholdSeconds ,
100
+ ) ,
74
101
) . toEqual ( {
75
102
client : 'zulipMobile' ,
76
103
status : 'idle' ,
77
104
timestamp : currentTimestamp - 10 ,
78
105
} ) ;
79
106
} ) ;
80
107
108
+ test ( 'Use specified offline threshold' , ( ) => {
109
+ expect (
110
+ getAggregatedPresence (
111
+ {
112
+ website : { client : 'website' , timestamp : currentTimestamp - 300 , status : 'active' } ,
113
+ zulipMobile : { client : 'zulipMobile' , timestamp : currentTimestamp - 10 , status : 'idle' } ,
114
+ aggregated : oldAggregatedClientPresence ,
115
+ } ,
116
+ 360 ,
117
+ ) ,
118
+ ) . toEqual ( {
119
+ client : 'website' ,
120
+ status : 'active' ,
121
+ timestamp : currentTimestamp - 10 ,
122
+ } ) ;
123
+ } ) ;
124
+
81
125
test ( 'Do not consider old aggregated' , ( ) => {
82
126
expect (
83
- getAggregatedPresence ( {
84
- aggregated : { client : 'website' , status : 'active' , timestamp : currentTimestamp - 100 } ,
85
- website : { client : 'website' , status : 'idle' , timestamp : currentTimestamp - 10 } ,
86
- } ) ,
127
+ getAggregatedPresence (
128
+ {
129
+ aggregated : { client : 'website' , status : 'active' , timestamp : currentTimestamp - 100 } ,
130
+ website : { client : 'website' , status : 'idle' , timestamp : currentTimestamp - 10 } ,
131
+ } ,
132
+ offlineThresholdSeconds ,
133
+ ) ,
87
134
) . toEqual ( { client : 'website' , status : 'idle' , timestamp : currentTimestamp - 10 } ) ;
88
135
} ) ;
89
136
} ) ;
0 commit comments