1
1
use lib <lib >;
2
2
use Testo;
3
- use Temp::Path;
4
- use DBIish;
5
3
4
+ plan 21 ;
5
+
6
+ use Temp::Path;
6
7
use P6lert::Model::Alerts;
7
8
9
+ my $ public-delay := 4 ;
8
10
my $ db-file := make-temp-path. extension : ' sqlite' , : parts(0 .. * );
9
- my $ alerts := P6lert::Model::Alerts. new : : $ db-file ;
11
+ my $ alerts := P6lert::Model::Alerts. new : : $ db-file , : $ public-delay ;
10
12
is $ alerts , P6lert::Model::Alerts, ' .new constructs right object' ;
11
13
is $ db-file , *. e , " .new creates db file $ db-file" ;
12
14
13
15
is (my $ id = $ alerts . add: ' test♥1' ), UInt : D , 「 .add returns new alert's ID」 ;
14
-
16
+ is $ alerts . public, 0 , ' .public gives 0 alerts ' ;
15
17
is $ alerts . all , 1 , ' have total 1 alert in db' ;
16
18
group ' .all.head object' => 7 => {
17
19
with $ alerts . all . head -> \a {
@@ -27,12 +29,14 @@ group '.all.head object' => 7 => {
27
29
28
30
is $ alerts . delete ($ id ), * , ' deleting alert' ;
29
31
is $ alerts . all , 0 , ' no alerts in db any more' ;
32
+ is $ alerts . public, 0 , ' .public still gives 0 alerts' ;
30
33
31
34
is $ alerts . add(' test♥2' ), UInt : D , 「 re-added first message」 ;
32
35
is $ alerts . add(
33
36
' meow2' , : creator<Zof >, : affects(' 2017.12 and earlier' ), : severity<critical >,
34
37
), UInt : D , 「 added second message」 ;
35
38
is $ alerts . all , 2 , ' two messages in db' ;
39
+ is $ alerts . public, 0 , ' .public still gives 0 alerts' ;
36
40
37
41
group ' first message' => 7 => {
38
42
with $ alerts . all . head -> \a {
@@ -57,3 +61,34 @@ group 'second message' => 7 => {
57
61
is a. affects, ' 2017.12 and earlier' , ' .affects' ;
58
62
}
59
63
}
64
+
65
+ is * , * , ' waiting for public delay expire' ;
66
+ sleep $ public-delay + 1;
67
+
68
+ is $ alerts . add(' unpublic' ), UInt : D , 「 added third, not-yet public message」 ;
69
+ is $ alerts . all , 3 , ' have 3 total alerts in db' ;
70
+ is $ alerts . public, 2 , ' have 2 total public alerts in db' ;
71
+
72
+ group ' first public message' => 7 => {
73
+ with $ alerts . public. head -> \a {
74
+ is a, P6lert::Alert, ' righ type' ;
75
+ is a. id, 2 , ' .id' ;
76
+ is a. alert, ' test♥2' , ' .alert' ;
77
+ is a. time , /^ \d ** 9.. 11$ /, ' .time looks approximately right' ;
78
+ is a. creator, ' Anonymous' , ' .creator' ;
79
+ is a. severity, ' normal' , ' .severity' ;
80
+ is a. affects, ' ' , ' .affects' ;
81
+ }
82
+ }
83
+
84
+ group ' second public message' => 7 => {
85
+ with $ alerts . public. tail -> \a {
86
+ is a, P6lert::Alert, ' righ type' ;
87
+ is a. id, 3 , ' .id' ;
88
+ is a. alert, ' meow2' , ' .alert' ;
89
+ is a. time , /^ \d ** 9.. 11$ /, ' .time looks approximately right' ;
90
+ is a. creator, ' Zof' , ' .creator' ;
91
+ is a. severity, ' critical' , ' .severity' ;
92
+ is a. affects, ' 2017.12 and earlier' , ' .affects' ;
93
+ }
94
+ }
0 commit comments