@@ -4466,6 +4466,141 @@ func (s *MethodTestSuite) TestNotifications() {
4466
4466
Disableds : []bool {true , false },
4467
4467
}).Asserts (rbac .ResourceNotificationPreference .WithOwner (user .ID .String ()), policy .ActionUpdate )
4468
4468
}))
4469
+
4470
+ s .Run ("GetInboxNotificationsByUserID" , s .Subtest (func (db database.Store , check * expects ) {
4471
+ u := dbgen .User (s .T (), db , database.User {})
4472
+
4473
+ notifID := uuid .New ()
4474
+
4475
+ notif := dbgen .NotificationInbox (s .T (), db , database.InsertInboxNotificationParams {
4476
+ ID : notifID ,
4477
+ UserID : u .ID ,
4478
+ TemplateID : notifications .TemplateWorkspaceAutoUpdated ,
4479
+ Title : "test title" ,
4480
+ Content : "test content notification" ,
4481
+ Icon : "https://coder.com/favicon.ico" ,
4482
+ Actions : json .RawMessage ("{}" ),
4483
+ })
4484
+
4485
+ check .Args (database.GetInboxNotificationsByUserIDParams {
4486
+ UserID : u .ID ,
4487
+ ReadStatus : database .InboxNotificationReadStatusAll ,
4488
+ }).Asserts (rbac .ResourceInboxNotification .WithID (notifID ).WithOwner (u .ID .String ()), policy .ActionRead ).Returns ([]database.InboxNotification {notif })
4489
+ }))
4490
+
4491
+ s .Run ("GetFilteredInboxNotificationsByUserID" , s .Subtest (func (db database.Store , check * expects ) {
4492
+ u := dbgen .User (s .T (), db , database.User {})
4493
+
4494
+ notifID := uuid .New ()
4495
+
4496
+ targets := []uuid.UUID {u .ID , notifications .TemplateWorkspaceAutoUpdated }
4497
+
4498
+ notif := dbgen .NotificationInbox (s .T (), db , database.InsertInboxNotificationParams {
4499
+ ID : notifID ,
4500
+ UserID : u .ID ,
4501
+ TemplateID : notifications .TemplateWorkspaceAutoUpdated ,
4502
+ Targets : targets ,
4503
+ Title : "test title" ,
4504
+ Content : "test content notification" ,
4505
+ Icon : "https://coder.com/favicon.ico" ,
4506
+ Actions : json .RawMessage ("{}" ),
4507
+ })
4508
+
4509
+ check .Args (database.GetFilteredInboxNotificationsByUserIDParams {
4510
+ UserID : u .ID ,
4511
+ Templates : []uuid.UUID {notifications .TemplateWorkspaceAutoUpdated },
4512
+ Targets : []uuid.UUID {u .ID },
4513
+ ReadStatus : database .InboxNotificationReadStatusAll ,
4514
+ }).Asserts (rbac .ResourceInboxNotification .WithID (notifID ).WithOwner (u .ID .String ()), policy .ActionRead ).Returns ([]database.InboxNotification {notif })
4515
+ }))
4516
+
4517
+ s .Run ("GetInboxNotificationByID" , s .Subtest (func (db database.Store , check * expects ) {
4518
+ u := dbgen .User (s .T (), db , database.User {})
4519
+
4520
+ notifID := uuid .New ()
4521
+
4522
+ targets := []uuid.UUID {u .ID , notifications .TemplateWorkspaceAutoUpdated }
4523
+
4524
+ notif := dbgen .NotificationInbox (s .T (), db , database.InsertInboxNotificationParams {
4525
+ ID : notifID ,
4526
+ UserID : u .ID ,
4527
+ TemplateID : notifications .TemplateWorkspaceAutoUpdated ,
4528
+ Targets : targets ,
4529
+ Title : "test title" ,
4530
+ Content : "test content notification" ,
4531
+ Icon : "https://coder.com/favicon.ico" ,
4532
+ Actions : json .RawMessage ("{}" ),
4533
+ })
4534
+
4535
+ check .Args (notifID ).Asserts (rbac .ResourceInboxNotification .WithID (notifID ).WithOwner (u .ID .String ()), policy .ActionRead ).Returns (notif )
4536
+ }))
4537
+
4538
+ s .Run ("CountUnreadInboxNotificationsByUserID" , s .Subtest (func (db database.Store , check * expects ) {
4539
+ u := dbgen .User (s .T (), db , database.User {})
4540
+
4541
+ notifID := uuid .New ()
4542
+
4543
+ targets := []uuid.UUID {u .ID , notifications .TemplateWorkspaceAutoUpdated }
4544
+
4545
+ _ = dbgen .NotificationInbox (s .T (), db , database.InsertInboxNotificationParams {
4546
+ ID : notifID ,
4547
+ UserID : u .ID ,
4548
+ TemplateID : notifications .TemplateWorkspaceAutoUpdated ,
4549
+ Targets : targets ,
4550
+ Title : "test title" ,
4551
+ Content : "test content notification" ,
4552
+ Icon : "https://coder.com/favicon.ico" ,
4553
+ Actions : json .RawMessage ("{}" ),
4554
+ })
4555
+
4556
+ check .Args (u .ID ).Asserts (rbac .ResourceInboxNotification .WithOwner (u .ID .String ()), policy .ActionRead ).Returns (int64 (1 ))
4557
+ }))
4558
+
4559
+ s .Run ("InsertInboxNotification" , s .Subtest (func (db database.Store , check * expects ) {
4560
+ u := dbgen .User (s .T (), db , database.User {})
4561
+
4562
+ notifID := uuid .New ()
4563
+
4564
+ targets := []uuid.UUID {u .ID , notifications .TemplateWorkspaceAutoUpdated }
4565
+
4566
+ check .Args (database.InsertInboxNotificationParams {
4567
+ ID : notifID ,
4568
+ UserID : u .ID ,
4569
+ TemplateID : notifications .TemplateWorkspaceAutoUpdated ,
4570
+ Targets : targets ,
4571
+ Title : "test title" ,
4572
+ Content : "test content notification" ,
4573
+ Icon : "https://coder.com/favicon.ico" ,
4574
+ Actions : json .RawMessage ("{}" ),
4575
+ }).Asserts (rbac .ResourceInboxNotification .WithOwner (u .ID .String ()), policy .ActionCreate )
4576
+ }))
4577
+
4578
+ s .Run ("UpdateInboxNotificationReadStatus" , s .Subtest (func (db database.Store , check * expects ) {
4579
+ u := dbgen .User (s .T (), db , database.User {})
4580
+
4581
+ notifID := uuid .New ()
4582
+
4583
+ targets := []uuid.UUID {u .ID , notifications .TemplateWorkspaceAutoUpdated }
4584
+ readAt := dbtestutil .NowInDefaultTimezone ()
4585
+
4586
+ notif := dbgen .NotificationInbox (s .T (), db , database.InsertInboxNotificationParams {
4587
+ ID : notifID ,
4588
+ UserID : u .ID ,
4589
+ TemplateID : notifications .TemplateWorkspaceAutoUpdated ,
4590
+ Targets : targets ,
4591
+ Title : "test title" ,
4592
+ Content : "test content notification" ,
4593
+ Icon : "https://coder.com/favicon.ico" ,
4594
+ Actions : json .RawMessage ("{}" ),
4595
+ })
4596
+
4597
+ notif .ReadAt = sql.NullTime {Time : readAt , Valid : true }
4598
+
4599
+ check .Args (database.UpdateInboxNotificationReadStatusParams {
4600
+ ID : notifID ,
4601
+ ReadAt : sql.NullTime {Time : readAt , Valid : true },
4602
+ }).Asserts (rbac .ResourceInboxNotification .WithID (notifID ).WithOwner (u .ID .String ()), policy .ActionUpdate )
4603
+ }))
4469
4604
}
4470
4605
4471
4606
func (s * MethodTestSuite ) TestOAuth2ProviderApps () {
0 commit comments