@@ -285,3 +285,58 @@ pub async fn handler(
285
285
& base,
286
286
) ) )
287
287
}
288
+
289
+ #[ cfg( test) ]
290
+ mod tests {
291
+ use hyper:: { Request , StatusCode } ;
292
+ use sqlx:: PgPool ;
293
+
294
+ use crate :: test_utils:: { setup, RequestBuilderExt , ResponseExt , TestState } ;
295
+
296
+ #[ sqlx:: test( migrator = "mas_storage_pg::MIGRATOR" ) ]
297
+ async fn test_oauth2_simple_session_list ( pool : PgPool ) {
298
+ setup ( ) ;
299
+ let mut state = TestState :: from_pool ( pool) . await . unwrap ( ) ;
300
+ let token = state. token_with_scope ( "urn:mas:admin" ) . await ;
301
+
302
+ // We already have a session because of the token above
303
+ let request = Request :: get ( "/api/admin/v1/oauth2-sessions" )
304
+ . bearer ( & token)
305
+ . empty ( ) ;
306
+ let response = state. request ( request) . await ;
307
+ response. assert_status ( StatusCode :: OK ) ;
308
+ let body: serde_json:: Value = response. json ( ) ;
309
+ insta:: assert_json_snapshot!( body, @r###"
310
+ {
311
+ "meta": {
312
+ "count": 1
313
+ },
314
+ "data": [
315
+ {
316
+ "type": "oauth2-session",
317
+ "id": "01FSHN9AG0MKGTBNZ16RDR3PVY",
318
+ "attributes": {
319
+ "created_at": "2022-01-16T14:40:00Z",
320
+ "finished_at": null,
321
+ "user_id": null,
322
+ "user_session_id": null,
323
+ "client_id": "01FSHN9AG0FAQ50MT1E9FFRPZR",
324
+ "scope": "urn:mas:admin",
325
+ "user_agent": null,
326
+ "last_active_at": null,
327
+ "last_active_ip": null
328
+ },
329
+ "links": {
330
+ "self": "/api/admin/v1/oauth2-sessions/01FSHN9AG0MKGTBNZ16RDR3PVY"
331
+ }
332
+ }
333
+ ],
334
+ "links": {
335
+ "self": "/api/admin/v1/oauth2-sessions?page[first]=10",
336
+ "first": "/api/admin/v1/oauth2-sessions?page[first]=10",
337
+ "last": "/api/admin/v1/oauth2-sessions?page[last]=10"
338
+ }
339
+ }
340
+ "### ) ;
341
+ }
342
+ }
0 commit comments