@@ -105,8 +105,9 @@ pub async fn handler(
105105mod tests {
106106 use chrono:: Duration ;
107107 use hyper:: { Request , StatusCode } ;
108+ use insta:: assert_json_snapshot;
108109 use mas_storage:: { Clock , RepositoryAccess , user:: UserRepository } ;
109- use sqlx:: { PgPool , types :: Json } ;
110+ use sqlx:: PgPool ;
110111
111112 use crate :: test_utils:: { RequestBuilderExt , ResponseExt , TestState , setup} ;
112113
@@ -137,15 +138,37 @@ mod tests {
137138 serde_json:: json!( state. clock. now( ) )
138139 ) ;
139140
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+ "# ) ;
149172 }
150173
151174 #[ sqlx:: test( migrator = "mas_storage_pg::MIGRATOR" ) ]
@@ -179,15 +202,37 @@ mod tests {
179202 serde_json:: json!( state. clock. now( ) )
180203 ) ;
181204
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+ "# ) ;
191236 }
192237
193238 #[ sqlx:: test( migrator = "mas_storage_pg::MIGRATOR" ) ]
0 commit comments