@@ -1329,3 +1329,65 @@ func TestNotificationService_GetNotificationUnreadCount(t *testing.T) {
13291329 })
13301330 }
13311331}
1332+
1333+ func TestNotificationService_MarkAllNotificationsAsRead (t * testing.T ) {
1334+ t .Parallel ()
1335+ mockController := gomock .NewController (t )
1336+ defer mockController .Finish ()
1337+
1338+ viewerCtx := metadata .NewIncomingContext (
1339+ createContextWithToken (t , false ),
1340+ metadata.MD {"accept-language" : []string {"en" }},
1341+ )
1342+
1343+ patterns := []struct {
1344+ desc string
1345+ ctx context.Context
1346+ setup func (* NotificationService )
1347+ expectedErr error
1348+ }{
1349+ {
1350+ desc : "err: unauthenticated" ,
1351+ ctx : context .TODO (),
1352+ expectedErr : statusUnauthenticated .Err (),
1353+ },
1354+ {
1355+ desc : "err: internal" ,
1356+ ctx : viewerCtx ,
1357+ setup : func (s * NotificationService ) {
1358+ s .dbClient .(* databasemock.MockClient ).EXPECT ().RunInTransactionV2 (
1359+ gomock .Any (), gomock .Any (),
1360+ ).Return (errors .New ("error" ))
1361+ },
1362+ expectedErr : api .NewGRPCStatus (errors .New ("error" )).Err (),
1363+ },
1364+ {
1365+ desc : "success" ,
1366+ ctx : viewerCtx ,
1367+ setup : func (s * NotificationService ) {
1368+ s .dbClient .(* databasemock.MockClient ).EXPECT ().RunInTransactionV2 (
1369+ gomock .Any (), gomock .Any (),
1370+ ).DoAndReturn (func (ctx context.Context , fn func (ctx context.Context ) error ) error {
1371+ return fn (ctx )
1372+ })
1373+ s .notificationStorage .(* notificationstoragemock.MockNotificationStorage ).EXPECT ().MarkAllNotificationsAsRead (
1374+ gomock .Any (), "email" , gomock .Any (),
1375+ ).Return (nil )
1376+ },
1377+ expectedErr : nil ,
1378+ },
1379+ }
1380+ for _ , p := range patterns {
1381+ t .Run (p .desc , func (t * testing.T ) {
1382+ s := createNotificationService (mockController )
1383+ if p .setup != nil {
1384+ p .setup (s )
1385+ }
1386+ resp , err := s .MarkAllNotificationsAsRead (p .ctx , & proto.MarkAllNotificationsAsReadRequest {})
1387+ assert .Equal (t , p .expectedErr , err )
1388+ if p .expectedErr == nil {
1389+ assert .NotNil (t , resp )
1390+ }
1391+ })
1392+ }
1393+ }
0 commit comments