@@ -379,59 +379,42 @@ func TestNotificationTest(t *testing.T) {
379
379
}
380
380
381
381
const (
382
+ // These are valid keys for a push notification subscription.
383
+ // DO NOT REUSE THESE IN ANY REAL CODE.
382
384
validEndpointAuthKey = "zqbxT6JKstKSY9JKibZLSQ=="
383
385
validEndpointP256dhKey = "BNNL5ZaTfK81qhXOx23+wewhigUeFb632jN6LvRWCFH1ubQr77FE/9qV1FuojuRmHP42zmf34rXgW80OvUVDgTk="
384
386
)
385
387
386
388
func TestPushNotificationSubscription (t * testing.T ) {
387
389
t .Parallel ()
388
390
389
- t .Run ("Create" , func (t * testing.T ) {
390
- t .Parallel ()
391
-
392
- ctx := testutil .Context (t , testutil .WaitShort )
393
-
394
- notificationSent := false
395
- server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
396
- notificationSent = true
397
- w .WriteHeader (http .StatusOK )
398
- }))
399
- defer server .Close ()
400
-
401
- client := coderdtest .New (t , nil )
402
- coderdtest .CreateFirstUser (t , client )
403
-
404
- err := client .CreateNotificationPushSubscription (ctx , "me" , codersdk.PushNotificationSubscription {
405
- Endpoint : server .URL ,
406
- AuthKey : validEndpointAuthKey ,
407
- P256DHKey : validEndpointP256dhKey ,
408
- })
409
- require .NoError (t , err )
410
- require .True (t , notificationSent )
411
- })
412
- t .Run ("Delete" , func (t * testing.T ) {
391
+ t .Run ("CRUD" , func (t * testing.T ) {
413
392
t .Parallel ()
414
393
415
394
ctx := testutil .Context (t , testutil .WaitShort )
416
395
417
396
client := coderdtest .New (t , nil )
418
- coderdtest .CreateFirstUser (t , client )
397
+ owner := coderdtest .CreateFirstUser (t , client )
398
+ memberClient , _ := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID )
419
399
400
+ handlerCalled := make (chan bool , 1 )
420
401
server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
421
- w .WriteHeader (http .StatusOK )
402
+ w .WriteHeader (http .StatusCreated )
403
+ handlerCalled <- true
422
404
}))
423
405
defer server .Close ()
424
406
425
- err := client .CreateNotificationPushSubscription (ctx , "me" , codersdk.PushNotificationSubscription {
407
+ err := memberClient .CreateNotificationPushSubscription (ctx , "me" , codersdk.PushNotificationSubscription {
426
408
Endpoint : server .URL ,
427
409
AuthKey : validEndpointAuthKey ,
428
410
P256DHKey : validEndpointP256dhKey ,
429
411
})
430
- require .NoError (t , err )
412
+ require .NoError (t , err , "create notification push subscription" )
413
+ require .True (t , <- handlerCalled , "handler should have been called" )
431
414
432
- err = client .DeleteNotificationPushSubscription (ctx , "me" , codersdk.DeletePushNotificationSubscription {
415
+ err = memberClient .DeleteNotificationPushSubscription (ctx , "me" , codersdk.DeletePushNotificationSubscription {
433
416
Endpoint : server .URL ,
434
417
})
435
- require .NoError (t , err )
418
+ require .NoError (t , err , "delete notification push subscription" )
436
419
})
437
420
}
0 commit comments