@@ -105,8 +105,9 @@ pub async fn handler(
105
105
mod tests {
106
106
use chrono:: Duration ;
107
107
use hyper:: { Request , StatusCode } ;
108
+ use insta:: assert_json_snapshot;
108
109
use mas_storage:: { Clock , RepositoryAccess , user:: UserRepository } ;
109
- use sqlx:: { PgPool , types :: Json } ;
110
+ use sqlx:: PgPool ;
110
111
111
112
use crate :: test_utils:: { RequestBuilderExt , ResponseExt , TestState , setup} ;
112
113
@@ -137,15 +138,37 @@ mod tests {
137
138
serde_json:: json!( state. clock. now( ) )
138
139
) ;
139
140
140
- // It should have scheduled a deactivation job for the user
141
- // XXX: we don't have a good way to look for the deactivation job
142
- let job: Json < serde_json:: Value > = sqlx:: query_scalar (
143
- "SELECT payload FROM queue_jobs WHERE queue_name = 'deactivate-user'" ,
144
- )
145
- . fetch_one ( & pool)
146
- . await
147
- . expect ( "Deactivation job to be scheduled" ) ;
148
- assert_eq ! ( job[ "user_id" ] , serde_json:: json!( user. id) ) ;
141
+ // Make sure to run the jobs in the queue
142
+ state. run_jobs_in_queue ( ) . await ;
143
+
144
+ let request = Request :: get ( format ! ( "/api/admin/v1/users/{}" , user. id) )
145
+ . bearer ( & token)
146
+ . empty ( ) ;
147
+ let response = state. request ( request) . await ;
148
+ response. assert_status ( StatusCode :: OK ) ;
149
+ let body: serde_json:: Value = response. json ( ) ;
150
+
151
+ assert_json_snapshot ! ( body, @r#"
152
+ {
153
+ "data": {
154
+ "type": "user",
155
+ "id": "01FSHN9AG0MZAA6S4AF7CTV32E",
156
+ "attributes": {
157
+ "username": "alice",
158
+ "created_at": "2022-01-16T14:40:00Z",
159
+ "locked_at": "2022-01-16T14:40:00Z",
160
+ "deactivated_at": "2022-01-16T14:40:00Z",
161
+ "admin": false
162
+ },
163
+ "links": {
164
+ "self": "/api/admin/v1/users/01FSHN9AG0MZAA6S4AF7CTV32E"
165
+ }
166
+ },
167
+ "links": {
168
+ "self": "/api/admin/v1/users/01FSHN9AG0MZAA6S4AF7CTV32E"
169
+ }
170
+ }
171
+ "# ) ;
149
172
}
150
173
151
174
#[ sqlx:: test( migrator = "mas_storage_pg::MIGRATOR" ) ]
@@ -179,15 +202,37 @@ mod tests {
179
202
serde_json:: json!( state. clock. now( ) )
180
203
) ;
181
204
182
- // It should have scheduled a deactivation job for the user
183
- // XXX: we don't have a good way to look for the deactivation job
184
- let job: Json < serde_json:: Value > = sqlx:: query_scalar (
185
- "SELECT payload FROM queue_jobs WHERE queue_name = 'deactivate-user'" ,
186
- )
187
- . fetch_one ( & pool)
188
- . await
189
- . expect ( "Deactivation job to be scheduled" ) ;
190
- assert_eq ! ( job[ "user_id" ] , serde_json:: json!( user. id) ) ;
205
+ // Make sure to run the jobs in the queue
206
+ state. run_jobs_in_queue ( ) . await ;
207
+
208
+ let request = Request :: get ( format ! ( "/api/admin/v1/users/{}" , user. id) )
209
+ . bearer ( & token)
210
+ . empty ( ) ;
211
+ let response = state. request ( request) . await ;
212
+ response. assert_status ( StatusCode :: OK ) ;
213
+ let body: serde_json:: Value = response. json ( ) ;
214
+
215
+ assert_json_snapshot ! ( body, @r#"
216
+ {
217
+ "data": {
218
+ "type": "user",
219
+ "id": "01FSHN9AG0MZAA6S4AF7CTV32E",
220
+ "attributes": {
221
+ "username": "alice",
222
+ "created_at": "2022-01-16T14:40:00Z",
223
+ "locked_at": "2022-01-16T14:40:00Z",
224
+ "deactivated_at": "2022-01-16T14:41:00Z",
225
+ "admin": false
226
+ },
227
+ "links": {
228
+ "self": "/api/admin/v1/users/01FSHN9AG0MZAA6S4AF7CTV32E"
229
+ }
230
+ },
231
+ "links": {
232
+ "self": "/api/admin/v1/users/01FSHN9AG0MZAA6S4AF7CTV32E"
233
+ }
234
+ }
235
+ "# ) ;
191
236
}
192
237
193
238
#[ sqlx:: test( migrator = "mas_storage_pg::MIGRATOR" ) ]
0 commit comments