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