RezinaLMS-BackEnd/internal/services/notification/service_delete_test.go
Yared Yemane 10babe06f6 feat: add in-app notification delete APIs and fix FAQ RBAC access
- Add DELETE /notifications/:id and POST /notifications/delete-in-app for owned in-app rows

- Seed FAQ permissions for ADMIN/INSTRUCTOR, migration 000084, and improve RBAC sync

- Document FAQ admin panel integration

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-14 02:15:00 -07:00

67 lines
1.5 KiB
Go

package notificationservice
import (
"context"
"errors"
"testing"
"Yimaru-Backend/internal/ports"
)
type deleteInAppStoreStub struct {
ports.NotificationStore
singleRows int64
singleErr error
bulkRows int64
bulkErr error
}
func (s *deleteInAppStoreStub) DeleteUserInAppNotification(_ context.Context, _, _ int64) (int64, error) {
if s.singleErr != nil {
return 0, s.singleErr
}
return s.singleRows, nil
}
func (s *deleteInAppStoreStub) DeleteUserInAppNotificationsByIDs(_ context.Context, _ int64, _ []int64) (int64, error) {
if s.bulkErr != nil {
return 0, s.bulkErr
}
return s.bulkRows, nil
}
func TestDeleteUserInAppNotification_success(t *testing.T) {
svc := &Service{
store: &deleteInAppStoreStub{singleRows: 1},
}
if err := svc.DeleteUserInAppNotification(context.Background(), 10, 42); err != nil {
t.Fatalf("expected nil error, got %v", err)
}
}
func TestDeleteUserInAppNotification_notFound(t *testing.T) {
svc := &Service{
store: &deleteInAppStoreStub{singleRows: 0},
}
err := svc.DeleteUserInAppNotification(context.Background(), 10, 42)
if !errors.Is(err, ErrNotificationNotFound) {
t.Fatalf("expected ErrNotificationNotFound, got %v", err)
}
}
func TestDeleteUserInAppNotifications_success(t *testing.T) {
svc := &Service{
store: &deleteInAppStoreStub{bulkRows: 2},
}
got, err := svc.DeleteUserInAppNotifications(context.Background(), 42, []int64{1, 2, 3})
if err != nil {
t.Fatalf("expected nil error, got %v", err)
}
if got != 2 {
t.Fatalf("expected deleted count 2, got %d", got)
}
}