~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/hydraulophone

An unofficial YouTube Music app for iPhone, iPad, and Mac.

0
0
main
30 lines · 1.2 KB Raw History
import Foundation
import HydraulophoneCore
import XCTest

@testable import Hydraulophone

final class OfflineLibraryTracksTests: XCTestCase {
  func testMergesDownloadedAndCachedSongsAndPrefersDownloadMetadata() {
    let cached = Song(
      id: "same-track", title: "Cached title", artist: "Cached artist",
      thumbnailURL: URL(string: "https://example.com/cached.jpg"))
    let cachedOnly = Song(id: "cached-only", title: "Cached only", artist: "Artist")
    let downloaded = Song(
      id: "same-track", title: "Downloaded title", artist: "Downloaded artist",
      thumbnailURL: URL(fileURLWithPath: "/tmp/local-art.jpg"))
    let downloadOnly = Song(id: "download-only", title: "Download only", artist: "Artist")
    let recent = Date()

    let result = OfflineLibraryTracks.songs(
      cached: [
        CachedTrack(song: cached, lastAccessed: recent),
        CachedTrack(song: cachedOnly, lastAccessed: recent.addingTimeInterval(-1)),
      ],
      downloaded: [downloaded, downloadOnly])

    XCTAssertEqual(result.map(\.id), ["same-track", "cached-only", "download-only"])
    XCTAssertEqual(result.first?.title, "Downloaded title")
    XCTAssertEqual(result.first?.thumbnailURL, downloaded.thumbnailURL)
  }
}