package dl import ( "testing" "uptodownBot/internal/domain" ) func TestFilterFormatsByType(t *testing.T) { formats := []domain.Format{ {ID: "1", HasVideo: true, HasAudio: false, IsVideoOnly: true, IsAudioOnly: false}, {ID: "2", HasVideo: false, HasAudio: true, IsVideoOnly: false, IsAudioOnly: true}, {ID: "3", HasVideo: true, HasAudio: true, IsVideoOnly: false, IsAudioOnly: false}, {ID: "4", HasVideo: true, HasAudio: false, IsVideoOnly: true, IsAudioOnly: false}, {ID: "5", HasVideo: false, HasAudio: true, IsVideoOnly: false, IsAudioOnly: true}, } tests := []struct { mediaType domain.MediaType wantIDs []string }{ {domain.MediaTypeAudio, []string{"2", "5"}}, {domain.MediaTypeVideo, []string{"1", "4"}}, {domain.MediaTypeVideoAudio, []string{"3"}}, } for _, tt := range tests { got := FilterFormatsByType(formats, tt.mediaType) if len(got) != len(tt.wantIDs) { t.Errorf("FilterFormatsByType(%v) = %d results, want %d", tt.mediaType, len(got), len(tt.wantIDs)) continue } for i, f := range got { if f.ID != tt.wantIDs[i] { t.Errorf("FilterFormatsByType(%v)[%d].ID = %s, want %s", tt.mediaType, i, f.ID, tt.wantIDs[i]) } } } } func TestDeduplicateResolutions(t *testing.T) { formats := []domain.Format{ {ID: "1", Resolution: "1920x1080", Height: 1080, IsVideoOnly: true}, {ID: "2", Resolution: "1920x1080", Height: 1080, IsVideoOnly: true}, {ID: "3", Resolution: "1280x720", Height: 720, IsVideoOnly: true}, {ID: "4", Bitrate: "128k", IsAudioOnly: true}, {ID: "5", Bitrate: "128k", IsAudioOnly: true}, } got := DeduplicateResolutions(formats) if len(got) != 3 { t.Errorf("DeduplicateResolutions = %d results, want 3", len(got)) } } func TestFormatLabel(t *testing.T) { tests := []struct { f domain.Format want string }{ {domain.Format{IsAudioOnly: true, Bitrate: "128k"}, "128k"}, {domain.Format{ID: "140", Extension: "m4a", IsAudioOnly: true}, "140 (m4a)"}, {domain.Format{ID: "251", IsAudioOnly: true}, "251"}, {domain.Format{Resolution: "1920x1080", Height: 1080}, "1920x1080"}, {domain.Format{Height: 720}, "720p"}, {domain.Format{ID: "137"}, "137"}, } for _, tt := range tests { got := formatLabel(tt.f) if got != tt.want { t.Errorf("formatLabel(%+v) = %q, want %q", tt.f, got, tt.want) } } }