55 lines
2.6 KiB
Swift
55 lines
2.6 KiB
Swift
import XCTest
|
|
@testable import MusicBridge
|
|
|
|
@MainActor
|
|
final class LiveActivityCommandTests: XCTestCase {
|
|
private func client(_ token: String) throws -> BridgeClient {
|
|
let url = try XCTUnwrap(Bundle(for: Self.self).url(forResource: "tls-fixture", withExtension: "json"))
|
|
let fixtures = try JSONDecoder().decode([String: [String: String]].self, from: Data(contentsOf: url))
|
|
let f = try XCTUnwrap(fixtures["valid"])
|
|
return BridgeClient(try Connection(endpoint: XCTUnwrap(f["endpoint"]), fingerprint: XCTUnwrap(f["fingerprint"]), token: token))
|
|
}
|
|
|
|
func testNextUsesOneCommandAndReturnsUpdatedTrack() async throws {
|
|
let client = try client("live-next"); defer { client.close() }
|
|
let result = try await LiveActivityCommands.execute(.next, client: client)
|
|
XCTAssertEqual(result.title, "Track 1")
|
|
}
|
|
|
|
func testRefreshDoesNotSendCommand() async throws {
|
|
let client = try client("live-refresh"); defer { client.close() }
|
|
let result = try await LiveActivityCommands.execute(.refresh, client: client)
|
|
XCTAssertEqual(result.title, "Track 0")
|
|
}
|
|
|
|
func testClosedActivityDoesNotSendCommand() async throws {
|
|
let client = try client("live-closed"); defer { client.close() }
|
|
do { _ = try await LiveActivityCommands.execute(.next, client: client, stillValid: { false }); XCTFail("Must reject") }
|
|
catch { }
|
|
let state = try await client.state()
|
|
XCTAssertEqual(state.title, "Track 0")
|
|
}
|
|
|
|
func testUnsupportedCommandIsNotSent() async throws {
|
|
let client = try client("live-unsupported"); defer { client.close() }
|
|
do { _ = try await LiveActivityCommands.execute(.next, client: client); XCTFail("Must reject") }
|
|
catch { }
|
|
let state = try await client.state()
|
|
XCTAssertEqual(state.title, "Track 0")
|
|
}
|
|
|
|
func testRejectedCommandIsNotRetried() async throws {
|
|
let client = try client("live-reject"); defer { client.close() }
|
|
do { _ = try await LiveActivityCommands.execute(.next, client: client); XCTFail("Must reject") }
|
|
catch { }
|
|
let state = try await client.state()
|
|
XCTAssertEqual(state.title, "Track 1")
|
|
}
|
|
|
|
func testFailedReadAfterSuccessReportsCommandCompleted() async throws {
|
|
let client = try client("live-refresh-fail"); defer { client.close() }
|
|
do { _ = try await LiveActivityCommands.execute(.next, client: client); XCTFail("Must report refresh failure") }
|
|
catch { XCTAssertTrue(error.localizedDescription.contains("Команда выполнена")) }
|
|
}
|
|
}
|