package usecases import ( "os" "path/filepath" "testing" "audio-catalyst/internal/domain/entities" ) type memRepo struct{ books []entities.AudioBook } func (m *memRepo) ScanDirectory(root string) ([]entities.AudioBook, error) { return m.books, nil } func (m *memRepo) SaveMetadata(p string, _ *entities.AudioBookMetadata) error { return nil } func (m *memRepo) DownloadCover(_, _ string) error { return nil } func (m *memRepo) RenameBookFolder(old, new string) (string, error) { return filepath.Join(filepath.Dir(old), new), nil } func (m *memRepo) OrganizeBookFolder(p, _, target string) (string, error) { return filepath.Join(target, filepath.Base(p)), nil } type fakeRT struct{} func (f *fakeRT) Login() error { return nil } func (f *fakeRT) Search(q string, _ int) ([]entities.Torrent, error) { if q == "skip" { return []entities.Torrent{}, nil } return []entities.Torrent{{ID: "1", Title: "hit"}}, nil } func (f *fakeRT) GetTopicMetadata(_ string) (*entities.RuTrackerResult, error) { return &entities.RuTrackerResult{Title: "Книга", Subtitle: "Автор - Книга", Authors: []string{"Автор Фамилия"}}, nil } func (f *fakeRT) DownloadTorrent(string) ([]byte, error) { return nil, nil } func (f *fakeRT) Close() {} type nopLogger struct{} func (nopLogger) Info(string, ...interface{}) {} func (nopLogger) Debug(string, ...interface{}) {} func (nopLogger) Warning(string, ...interface{}) {} func (nopLogger) Error(string, ...interface{}) {} func (nopLogger) Success(string, ...interface{}) {} func TestProcessSkipsWhenNotFound(t *testing.T) { tmp := t.TempDir() os.MkdirAll(filepath.Join(tmp, "skip"), 0755) repo := &memRepo{books: []entities.AudioBook{{Path: filepath.Join(tmp, "skip"), Title: "skip", MP3Files: []string{}}}} uc := NewProcessAudioBooksUseCase(repo, &fakeRT{}, nopLogger{}) cfg := &entities.Config{} cfg.Scanner.SourceDirectory = tmp if err := uc.Execute(cfg); err != nil { t.Fatal(err) } } func TestProcessHappyPath(t *testing.T) { tmp := t.TempDir() bookDir := filepath.Join(tmp, "book") os.MkdirAll(bookDir, 0755) os.WriteFile(filepath.Join(bookDir, "01.mp3"), []byte("x"), 0644) repo := &memRepo{books: []entities.AudioBook{{Path: bookDir, Title: "book", MP3Files: []string{filepath.Join(bookDir, "01.mp3")}}}} uc := NewProcessAudioBooksUseCase(repo, &fakeRT{}, nopLogger{}) cfg := &entities.Config{} cfg.Scanner.SourceDirectory = tmp if err := uc.Execute(cfg); err != nil { t.Fatal(err) } }