From 384b41366936fc452a5fd47e23489ad4cac13ab2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 4 May 2026 08:42:22 +0300 Subject: task e: add unit test verifying GetNote access check rejects non-owner --- internal/service/note_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/internal/service/note_test.go b/internal/service/note_test.go index 98fb250..ae985b7 100644 --- a/internal/service/note_test.go +++ b/internal/service/note_test.go @@ -10,6 +10,37 @@ import ( "codeberg.org/snonux/player/internal/repository" ) +func TestNoteService_GetNote_AccessCheck(t *testing.T) { + ctx := context.Background() + store := &repository.MockStore{ + MediaRepo: repository.MockMediaRepo{ + GetMediaByIDFunc: func(ctx context.Context, id int64) (*model.Media, error) { + return &model.Media{ID: 1, SetID: 1}, nil + }, + }, + UserRepo: repository.MockUserRepo{ + GetUserByIDFunc: func(ctx context.Context, id int64) (*model.User, error) { + return &model.User{ID: id, IsAdmin: false}, nil + }, + }, + SetRepo: repository.MockSetRepo{ + GetSetByIDFunc: func(ctx context.Context, id int64) (*model.Set, error) { + return &model.Set{ID: id}, nil + }, + }, + SetPermissionRepo: repository.MockSetPermissionRepo{ + GetPermissionFunc: func(ctx context.Context, setID, userID int64) (*model.SetPermission, error) { + return nil, nil + }, + }, + } + svc := NewNoteService(store, clock.RealClock{}, &accessHelper{store: store}) + _, err := svc.GetNote(ctx, 1, 2) + if !errors.Is(err, ErrForbidden) { + t.Fatalf("expected ErrForbidden, got %v", err) + } +} + func TestNoteService_SetNote(t *testing.T) { ctx := context.Background() -- cgit v1.2.3