@@ -4476,6 +4476,169 @@ func (s *MethodTestSuite) TestNotifications() {
4476
4476
Disableds : []bool {true ,false },
4477
4477
}).Asserts (rbac .ResourceNotificationPreference .WithOwner (user .ID .String ()),policy .ActionUpdate )
4478
4478
}))
4479
+
4480
+ s .Run ("FetchUnreadInboxNotificationsByUserID" ,s .Subtest (func (db database.Store ,check * expects ) {
4481
+ u := dbgen .User (s .T (),db , database.User {})
4482
+ o := dbgen .Organization (s .T (),db , database.Organization {})
4483
+ tpl := dbgen .Template (s .T (),db , database.Template {
4484
+ OrganizationID :o .ID ,
4485
+ CreatedBy :u .ID ,
4486
+ })
4487
+
4488
+ notifID := uuid .New ()
4489
+
4490
+ notif := dbgen .NotificationInbox (s .T (),db , database.InsertInboxNotificationParams {
4491
+ ID :notifID ,
4492
+ UserID :u .ID ,
4493
+ TemplateID :tpl .ID ,
4494
+ Title :"test title" ,
4495
+ Content :"test content notification" ,
4496
+ Icon :"test icon" ,
4497
+ })
4498
+
4499
+ check .Args (u .ID ).Asserts (rbac .ResourceNotificationInbox .WithID (notifID ).WithOwner (u .ID .String ()),policy .ActionRead ).Returns ([]database.NotificationsInbox {notif })
4500
+ }))
4501
+
4502
+ s .Run ("FetchInboxNotificationsByUserID" ,s .Subtest (func (db database.Store ,check * expects ) {
4503
+ u := dbgen .User (s .T (),db , database.User {})
4504
+ o := dbgen .Organization (s .T (),db , database.Organization {})
4505
+ tpl := dbgen .Template (s .T (),db , database.Template {
4506
+ OrganizationID :o .ID ,
4507
+ CreatedBy :u .ID ,
4508
+ })
4509
+
4510
+ notifID := uuid .New ()
4511
+
4512
+ notif := dbgen .NotificationInbox (s .T (),db , database.InsertInboxNotificationParams {
4513
+ ID :notifID ,
4514
+ UserID :u .ID ,
4515
+ TemplateID :tpl .ID ,
4516
+ Title :"test title" ,
4517
+ Content :"test content notification" ,
4518
+ Icon :"test icon" ,
4519
+ })
4520
+
4521
+ check .Args (u .ID ).Asserts (rbac .ResourceNotificationInbox .WithID (notifID ).WithOwner (u .ID .String ()),policy .ActionRead ).Returns ([]database.NotificationsInbox {notif })
4522
+ }))
4523
+
4524
+ s .Run ("FetchInboxNotificationsByUserIDAndTemplateIDAndTargets" ,s .Subtest (func (db database.Store ,check * expects ) {
4525
+ u := dbgen .User (s .T (),db , database.User {})
4526
+ o := dbgen .Organization (s .T (),db , database.Organization {})
4527
+ tpl := dbgen .Template (s .T (),db , database.Template {
4528
+ OrganizationID :o .ID ,
4529
+ CreatedBy :u .ID ,
4530
+ })
4531
+
4532
+ notifID := uuid .New ()
4533
+
4534
+ targets := []uuid.UUID {u .ID ,tpl .ID }
4535
+
4536
+ notif := dbgen .NotificationInbox (s .T (),db , database.InsertInboxNotificationParams {
4537
+ ID :notifID ,
4538
+ UserID :u .ID ,
4539
+ TemplateID :tpl .ID ,
4540
+ Targets :targets ,
4541
+ Title :"test title" ,
4542
+ Content :"test content notification" ,
4543
+ Icon :"test icon" ,
4544
+ })
4545
+
4546
+ check .Args (database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetsParams {
4547
+ UserID :u .ID ,
4548
+ TemplateID :tpl .ID ,
4549
+ Targets : []uuid.UUID {u .ID },
4550
+ }).Asserts (rbac .ResourceNotificationInbox .WithID (notifID ).WithOwner (u .ID .String ()),policy .ActionRead ).Returns ([]database.NotificationsInbox {notif })
4551
+ }))
4552
+
4553
+ s .Run ("FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargets" ,s .Subtest (func (db database.Store ,check * expects ) {
4554
+ u := dbgen .User (s .T (),db , database.User {})
4555
+ o := dbgen .Organization (s .T (),db , database.Organization {})
4556
+ tpl := dbgen .Template (s .T (),db , database.Template {
4557
+ OrganizationID :o .ID ,
4558
+ CreatedBy :u .ID ,
4559
+ })
4560
+
4561
+ notifID := uuid .New ()
4562
+
4563
+ targets := []uuid.UUID {u .ID ,tpl .ID }
4564
+
4565
+ notif := dbgen .NotificationInbox (s .T (),db , database.InsertInboxNotificationParams {
4566
+ ID :notifID ,
4567
+ UserID :u .ID ,
4568
+ TemplateID :tpl .ID ,
4569
+ Targets :targets ,
4570
+ Title :"test title" ,
4571
+ Content :"test content notification" ,
4572
+ Icon :"test icon" ,
4573
+ })
4574
+
4575
+ check .Args (database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetsParams {
4576
+ UserID :u .ID ,
4577
+ TemplateID :tpl .ID ,
4578
+ Targets : []uuid.UUID {u .ID },
4579
+ }).Asserts (rbac .ResourceNotificationInbox .WithID (notifID ).WithOwner (u .ID .String ()),policy .ActionRead ).Returns ([]database.NotificationsInbox {notif })
4580
+ }))
4581
+
4582
+ s .Run ("GetInboxNotificationByID" ,s .Subtest (func (db database.Store ,check * expects ) {
4583
+ u := dbgen .User (s .T (),db , database.User {})
4584
+ o := dbgen .Organization (s .T (),db , database.Organization {})
4585
+ tpl := dbgen .Template (s .T (),db , database.Template {
4586
+ OrganizationID :o .ID ,
4587
+ CreatedBy :u .ID ,
4588
+ })
4589
+
4590
+ notifID := uuid .New ()
4591
+
4592
+ targets := []uuid.UUID {u .ID ,tpl .ID }
4593
+
4594
+ notif := dbgen .NotificationInbox (s .T (),db , database.InsertInboxNotificationParams {
4595
+ ID :notifID ,
4596
+ UserID :u .ID ,
4597
+ TemplateID :tpl .ID ,
4598
+ Targets :targets ,
4599
+ Title :"test title" ,
4600
+ Content :"test content notification" ,
4601
+ Icon :"test icon" ,
4602
+ })
4603
+
4604
+ check .Args (notifID ).Asserts (rbac .ResourceNotificationInbox .WithID (notifID ).WithOwner (u .ID .String ()),policy .ActionRead ).Returns (notif )
4605
+ }))
4606
+
4607
+ s .Run ("InsertInboxNotification" ,s .Subtest (func (_ database.Store ,check * expects ) {
4608
+ owner := uuid.UUID {}
4609
+ check .Args (database.InsertInboxNotificationParams {}).Asserts (rbac .ResourceNotificationInbox .WithOwner (owner .String ()),policy .ActionCreate )
4610
+ }))
4611
+
4612
+ s .Run ("SetInboxNotificationAsRead" ,s .Subtest (func (db database.Store ,check * expects ) {
4613
+ u := dbgen .User (s .T (),db , database.User {})
4614
+ o := dbgen .Organization (s .T (),db , database.Organization {})
4615
+ tpl := dbgen .Template (s .T (),db , database.Template {
4616
+ OrganizationID :o .ID ,
4617
+ CreatedBy :u .ID ,
4618
+ })
4619
+
4620
+ notifID := uuid .New ()
4621
+
4622
+ targets := []uuid.UUID {u .ID ,tpl .ID }
4623
+ readAt := dbtestutil .NowInDefaultTimezone ()
4624
+
4625
+ notif := dbgen .NotificationInbox (s .T (),db , database.InsertInboxNotificationParams {
4626
+ ID :notifID ,
4627
+ UserID :u .ID ,
4628
+ TemplateID :tpl .ID ,
4629
+ Targets :targets ,
4630
+ Title :"test title" ,
4631
+ Content :"test content notification" ,
4632
+ Icon :"test icon" ,
4633
+ })
4634
+
4635
+ notif .ReadAt = sql.NullTime {Time :readAt ,Valid :true }
4636
+
4637
+ check .Args (database.SetInboxNotificationAsReadParams {
4638
+ ID :notifID ,
4639
+ ReadAt : sql.NullTime {Time :readAt ,Valid :true },
4640
+ }).Asserts (rbac .ResourceNotificationInbox .WithID (notifID ).WithOwner (u .ID .String ()),policy .ActionUpdate )
4641
+ }))
4479
4642
}
4480
4643
4481
4644
func (s * MethodTestSuite )TestOAuth2ProviderApps () {