()
| 5215 | } |
| 5216 | |
| 5217 | func (s *MethodTestSuite) TestNotifications() { |
| 5218 | // System functions |
| 5219 | s.Run("AcquireNotificationMessages", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) { |
| 5220 | dbm.EXPECT().AcquireNotificationMessages(gomock.Any(), database.AcquireNotificationMessagesParams{}).Return([]database.AcquireNotificationMessagesRow{}, nil).AnyTimes() |
| 5221 | check.Args(database.AcquireNotificationMessagesParams{}).Asserts(rbac.ResourceNotificationMessage, policy.ActionUpdate) |
| 5222 | })) |
| 5223 | s.Run("BulkMarkNotificationMessagesFailed", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) { |
| 5224 | dbm.EXPECT().BulkMarkNotificationMessagesFailed(gomock.Any(), database.BulkMarkNotificationMessagesFailedParams{}).Return(int64(0), nil).AnyTimes() |
| 5225 | check.Args(database.BulkMarkNotificationMessagesFailedParams{}).Asserts(rbac.ResourceNotificationMessage, policy.ActionUpdate) |
| 5226 | })) |
| 5227 | s.Run("BulkMarkNotificationMessagesSent", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) { |
| 5228 | dbm.EXPECT().BulkMarkNotificationMessagesSent(gomock.Any(), database.BulkMarkNotificationMessagesSentParams{}).Return(int64(0), nil).AnyTimes() |
| 5229 | check.Args(database.BulkMarkNotificationMessagesSentParams{}).Asserts(rbac.ResourceNotificationMessage, policy.ActionUpdate) |
| 5230 | })) |
| 5231 | s.Run("DeleteOldNotificationMessages", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) { |
| 5232 | dbm.EXPECT().DeleteOldNotificationMessages(gomock.Any()).Return(nil).AnyTimes() |
| 5233 | check.Args().Asserts(rbac.ResourceNotificationMessage, policy.ActionDelete) |
| 5234 | })) |
| 5235 | s.Run("EnqueueNotificationMessage", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) { |
| 5236 | arg := database.EnqueueNotificationMessageParams{Method: database.NotificationMethodWebhook, Payload: []byte("{}")} |
| 5237 | dbm.EXPECT().EnqueueNotificationMessage(gomock.Any(), arg).Return(nil).AnyTimes() |
| 5238 | // TODO: update this test once we have a specific role for notifications |
| 5239 | check.Args(arg).Asserts(rbac.ResourceNotificationMessage, policy.ActionCreate) |
| 5240 | })) |
| 5241 | s.Run("FetchNewMessageMetadata", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 5242 | u := testutil.Fake(s.T(), faker, database.User{}) |
| 5243 | dbm.EXPECT().FetchNewMessageMetadata(gomock.Any(), database.FetchNewMessageMetadataParams{UserID: u.ID}).Return(database.FetchNewMessageMetadataRow{}, nil).AnyTimes() |
| 5244 | check.Args(database.FetchNewMessageMetadataParams{UserID: u.ID}). |
| 5245 | Asserts(rbac.ResourceNotificationMessage, policy.ActionRead) |
| 5246 | })) |
| 5247 | s.Run("GetNotificationMessagesByStatus", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) { |
| 5248 | arg := database.GetNotificationMessagesByStatusParams{Status: database.NotificationMessageStatusLeased, Limit: 10} |
| 5249 | dbm.EXPECT().GetNotificationMessagesByStatus(gomock.Any(), arg).Return([]database.NotificationMessage{}, nil).AnyTimes() |
| 5250 | check.Args(arg).Asserts(rbac.ResourceNotificationMessage, policy.ActionRead) |
| 5251 | })) |
| 5252 | |
| 5253 | // webpush subscriptions |
| 5254 | s.Run("GetWebpushSubscriptionsByUserID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 5255 | user := testutil.Fake(s.T(), faker, database.User{}) |
| 5256 | dbm.EXPECT().GetWebpushSubscriptionsByUserID(gomock.Any(), user.ID).Return([]database.WebpushSubscription{}, nil).AnyTimes() |
| 5257 | check.Args(user.ID).Asserts(rbac.ResourceWebpushSubscription.WithOwner(user.ID.String()), policy.ActionRead) |
| 5258 | })) |
| 5259 | s.Run("InsertWebpushSubscription", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 5260 | user := testutil.Fake(s.T(), faker, database.User{}) |
| 5261 | arg := database.InsertWebpushSubscriptionParams{UserID: user.ID} |
| 5262 | dbm.EXPECT().InsertWebpushSubscription(gomock.Any(), arg).Return(testutil.Fake(s.T(), faker, database.WebpushSubscription{UserID: user.ID}), nil).AnyTimes() |
| 5263 | check.Args(arg).Asserts(rbac.ResourceWebpushSubscription.WithOwner(user.ID.String()), policy.ActionCreate) |
| 5264 | })) |
| 5265 | s.Run("DeleteWebpushSubscriptions", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 5266 | user := testutil.Fake(s.T(), faker, database.User{}) |
| 5267 | push := testutil.Fake(s.T(), faker, database.WebpushSubscription{UserID: user.ID}) |
| 5268 | dbm.EXPECT().DeleteWebpushSubscriptions(gomock.Any(), []uuid.UUID{push.ID}).Return(nil).AnyTimes() |
| 5269 | check.Args([]uuid.UUID{push.ID}).Asserts(rbac.ResourceSystem, policy.ActionDelete) |
| 5270 | })) |
| 5271 | s.Run("DeleteWebpushSubscriptionByUserIDAndEndpoint", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) { |
| 5272 | user := testutil.Fake(s.T(), faker, database.User{}) |
| 5273 | push := testutil.Fake(s.T(), faker, database.WebpushSubscription{UserID: user.ID}) |
| 5274 | arg := database.DeleteWebpushSubscriptionByUserIDAndEndpointParams{UserID: user.ID, Endpoint: push.Endpoint} |
nothing calls this directly
no test coverage detected