6d6bfe6 added Enclosure.path, which the tests' enclosures lacked, so the
test target no longer built. They now have one, and a test checks that a
picture and a file not yet fetched are passed over.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
2.6 KiB
Swift
50 lines
2.6 KiB
Swift
import XCTest
|
|
@testable import iPX
|
|
|
|
final class CarTests: XCTestCase {
|
|
private func episode(_ json: String) throws -> CarEpisode {
|
|
try JSONDecoder().decode(CarEpisode.self, from: Data(json.utf8))
|
|
}
|
|
|
|
func testAnItemReadsAsTheAPISendsIt() throws {
|
|
let e = try episode("""
|
|
{"guid":"g","feed_id":"f","title":null,"link":null,"image":null,"duration":1800,"position":600,
|
|
"read":false,"flagged":false,"enclosures":[
|
|
{"id":7,"feed_id":"f","guid":"g","url":"https://x/v.mp4","mime":"video/mp4","path":"/d/v.mp4","state":"done"},
|
|
{"id":8,"feed_id":"f","guid":"g","url":"https://x/Show%20Ep%201.mp3","mime":"audio/mpeg","path":"/d/e.mp3","state":"done"}]}
|
|
""")
|
|
XCTAssertEqual(e.audio?.id, 8, "a video is passed over for the sound")
|
|
XCTAssertEqual(e.name, "Show Ep 1", "untitled is named by its file")
|
|
XCTAssertEqual(e.left, "20 min left")
|
|
}
|
|
|
|
func testNothingToPlayIsNotListed() throws {
|
|
let e = try episode(#"{"guid":"g","feed_id":"f","title":"A post","position":0,"enclosures":[]}"#)
|
|
XCTAssertNil(e.audio)
|
|
XCTAssertNil(e.left, "not started")
|
|
XCTAssertNil(e.item(feedTitle: "F", feedImage: nil, kept: []))
|
|
}
|
|
|
|
func testTheFileIsTheOneThePageWouldPlay() {
|
|
let plain = CarEpisode.Enclosure(id: 4, url: "u", mime: nil, deadair: nil, path: "/d/a")
|
|
let trimmed = CarEpisode.Enclosure(id: 5, url: "u", mime: nil, deadair: 90, path: "/d/b")
|
|
XCTAssertEqual(CarEpisode.path(of: plain, kept: []), "/media/4")
|
|
XCTAssertEqual(CarEpisode.path(of: trimmed, kept: []), "/media/5/deadair.m3u8")
|
|
XCTAssertEqual(CarEpisode.path(of: trimmed, kept: ["/media/5/deadair"]), "/media/5/deadair",
|
|
"the copy on the phone, connection or not")
|
|
}
|
|
|
|
/// #443: only what ipx has downloaded, and only sound.
|
|
func testOnlyADownloadedSoundIsPlayable() throws {
|
|
let e = try episode("""
|
|
{"guid":"g","feed_id":"f","title":"T","position":0,"enclosures":[
|
|
{"id":1,"url":"https://x/cover.jpg","mime":"image/jpeg","path":"/d/c.jpg"},
|
|
{"id":2,"url":"https://x/later.mp3","mime":"audio/mpeg","path":null},
|
|
{"id":3,"url":"https://x/now.mp3","mime":null,"path":"/d/n.mp3"}]}
|
|
""")
|
|
XCTAssertEqual(e.audio?.id, 3, "a picture and a file not yet fetched are passed over; no type, an .mp3 name")
|
|
let blog = try episode(#"{"guid":"g","feed_id":"f","title":"T","position":0,"enclosures":[{"id":1,"url":"https://x/a.png","mime":"image/png","path":"/d/a.png"}]}"#)
|
|
XCTAssertNil(blog.audio)
|
|
}
|
|
}
|