summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-04 08:42:22 +0300
committerPaul Buetow <paul@buetow.org>2026-05-04 08:42:22 +0300
commit384b41366936fc452a5fd47e23489ad4cac13ab2 (patch)
tree7fe9e67d22b849f141082f1fe712d3a3cdabe63e
parentf1319f3d422f4df0844fd48442a665639e749c39 (diff)
task e: add unit test verifying GetNote access check rejects non-owner
-rw-r--r--internal/service/note_test.go31
1 files changed, 31 insertions, 0 deletions
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()