优化结构
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user