kra-new/internal/service/system/media_import_test.go

31 lines
814 B
Go

package system
import (
"context"
"testing"
bizsystem "kra/internal/biz/system"
"kra/internal/service/dto"
)
type mediaImportRepo struct {
bizsystem.MediaRepo
items []*bizsystem.MediaFile
}
func (r *mediaImportRepo) CreateMediaBatch(_ context.Context, items []*bizsystem.MediaFile) error {
r.items = items
return nil
}
func TestImportURLRequestsUsesAuthenticatedUser(t *testing.T) {
repo := &mediaImportRepo{}
service := NewMediaService(bizsystem.NewMediaUsecase(repo, nil, nil), nil)
if err := service.ImportURLRequests(context.Background(), 42, []dto.ImportMediaRequest{{Name: "image", URL: "https://example.test/image.png"}}); err != nil {
t.Fatal(err)
}
if len(repo.items) != 1 || repo.items[0].UserID != 42 {
t.Fatalf("imported media = %#v, want authenticated user 42", repo.items)
}
}