@@ -33,6 +33,7 @@ async fn test_user_repo(pool: PgPool) {
33
33
let non_admin = all. cannot_request_admin_only ( ) ;
34
34
let active = all. active_only ( ) ;
35
35
let locked = all. locked_only ( ) ;
36
+ let deactivated = all. deactivated_only ( ) ;
36
37
37
38
// Initially, the user shouldn't exist
38
39
assert ! ( !repo. user( ) . exists( USERNAME ) . await . unwrap( ) ) ;
@@ -49,6 +50,7 @@ async fn test_user_repo(pool: PgPool) {
49
50
assert_eq ! ( repo. user( ) . count( non_admin) . await . unwrap( ) , 0 ) ;
50
51
assert_eq ! ( repo. user( ) . count( active) . await . unwrap( ) , 0 ) ;
51
52
assert_eq ! ( repo. user( ) . count( locked) . await . unwrap( ) , 0 ) ;
53
+ assert_eq ! ( repo. user( ) . count( deactivated) . await . unwrap( ) , 0 ) ;
52
54
53
55
// Adding the user should work
54
56
let user = repo
@@ -73,6 +75,7 @@ async fn test_user_repo(pool: PgPool) {
73
75
assert_eq ! ( repo. user( ) . count( non_admin) . await . unwrap( ) , 1 ) ;
74
76
assert_eq ! ( repo. user( ) . count( active) . await . unwrap( ) , 1 ) ;
75
77
assert_eq ! ( repo. user( ) . count( locked) . await . unwrap( ) , 0 ) ;
78
+ assert_eq ! ( repo. user( ) . count( deactivated) . await . unwrap( ) , 0 ) ;
76
79
77
80
// Adding a second time should give a conflict
78
81
// It should not poison the transaction though
@@ -93,6 +96,7 @@ async fn test_user_repo(pool: PgPool) {
93
96
assert_eq ! ( repo. user( ) . count( non_admin) . await . unwrap( ) , 1 ) ;
94
97
assert_eq ! ( repo. user( ) . count( active) . await . unwrap( ) , 0 ) ;
95
98
assert_eq ! ( repo. user( ) . count( locked) . await . unwrap( ) , 1 ) ;
99
+ assert_eq ! ( repo. user( ) . count( deactivated) . await . unwrap( ) , 0 ) ;
96
100
97
101
// Check that the property is retrieved on lookup
98
102
let user = repo. user ( ) . lookup ( user. id ) . await . unwrap ( ) . unwrap ( ) ;
@@ -123,6 +127,7 @@ async fn test_user_repo(pool: PgPool) {
123
127
assert_eq ! ( repo. user( ) . count( non_admin) . await . unwrap( ) , 0 ) ;
124
128
assert_eq ! ( repo. user( ) . count( active) . await . unwrap( ) , 1 ) ;
125
129
assert_eq ! ( repo. user( ) . count( locked) . await . unwrap( ) , 0 ) ;
130
+ assert_eq ! ( repo. user( ) . count( deactivated) . await . unwrap( ) , 0 ) ;
126
131
127
132
// Check that the property is retrieved on lookup
128
133
let user = repo. user ( ) . lookup ( user. id ) . await . unwrap ( ) . unwrap ( ) ;
@@ -145,6 +150,26 @@ async fn test_user_repo(pool: PgPool) {
145
150
assert_eq ! ( repo. user( ) . count( non_admin) . await . unwrap( ) , 1 ) ;
146
151
assert_eq ! ( repo. user( ) . count( active) . await . unwrap( ) , 1 ) ;
147
152
assert_eq ! ( repo. user( ) . count( locked) . await . unwrap( ) , 0 ) ;
153
+ assert_eq ! ( repo. user( ) . count( deactivated) . await . unwrap( ) , 0 ) ;
154
+
155
+ // Deactivating the user should work
156
+ let user = repo. user ( ) . deactivate ( & clock, user) . await . unwrap ( ) ;
157
+ assert ! ( user. deactivated_at. is_some( ) ) ;
158
+
159
+ // Check that the property is retrieved on lookup
160
+ let user = repo. user ( ) . lookup ( user. id ) . await . unwrap ( ) . unwrap ( ) ;
161
+ assert ! ( user. deactivated_at. is_some( ) ) ;
162
+
163
+ // Deactivating a second time should not fail
164
+ let user = repo. user ( ) . deactivate ( & clock, user) . await . unwrap ( ) ;
165
+ assert ! ( user. deactivated_at. is_some( ) ) ;
166
+
167
+ assert_eq ! ( repo. user( ) . count( all) . await . unwrap( ) , 1 ) ;
168
+ assert_eq ! ( repo. user( ) . count( admin) . await . unwrap( ) , 0 ) ;
169
+ assert_eq ! ( repo. user( ) . count( non_admin) . await . unwrap( ) , 1 ) ;
170
+ assert_eq ! ( repo. user( ) . count( active) . await . unwrap( ) , 0 ) ;
171
+ assert_eq ! ( repo. user( ) . count( locked) . await . unwrap( ) , 0 ) ;
172
+ assert_eq ! ( repo. user( ) . count( deactivated) . await . unwrap( ) , 1 ) ;
148
173
149
174
// Check the list method
150
175
let list = repo. user ( ) . list ( all, Pagination :: first ( 10 ) ) . await . unwrap ( ) ;
@@ -171,8 +196,7 @@ async fn test_user_repo(pool: PgPool) {
171
196
. list ( active, Pagination :: first ( 10 ) )
172
197
. await
173
198
. unwrap ( ) ;
174
- assert_eq ! ( list. edges. len( ) , 1 ) ;
175
- assert_eq ! ( list. edges[ 0 ] . id, user. id) ;
199
+ assert_eq ! ( list. edges. len( ) , 0 ) ;
176
200
177
201
let list = repo
178
202
. user ( )
@@ -181,6 +205,14 @@ async fn test_user_repo(pool: PgPool) {
181
205
. unwrap ( ) ;
182
206
assert_eq ! ( list. edges. len( ) , 0 ) ;
183
207
208
+ let list = repo
209
+ . user ( )
210
+ . list ( deactivated, Pagination :: first ( 10 ) )
211
+ . await
212
+ . unwrap ( ) ;
213
+ assert_eq ! ( list. edges. len( ) , 1 ) ;
214
+ assert_eq ! ( list. edges[ 0 ] . id, user. id) ;
215
+
184
216
repo. save ( ) . await . unwrap ( ) ;
185
217
}
186
218
0 commit comments