luminate/Tests/LuminateServicesTests/JellyfinClientSystemTests.swift

79 lines
2.7 KiB
Swift

//
// JellyfinClientSystemTests.swift
//
// Copyright 2026 Brendan Szymanski <hello@bscubed.dev>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
import Foundation
import LuminateAPI
import LuminateCore
import Testing
@testable import LuminateServices
/// Covers the authenticated server-identification call and its DTO-to-domain mapping.
///
/// `publicServerInfo()` is exercised elsewhere; this suite is only `serverInfo()`.
@Suite struct JellyfinClientSystemTests {
/// Builds a client wired to a double.
///
/// - Parameter api: The stubbed API.
/// - Returns: A client that routes every call to `api`.
private func makeClient(_ api: MockJellyfinAPI) -> JellyfinClient {
JellyfinClient(
configuration: JellyfinClientConfiguration(serverURL: URL(string: "http://localhost")!),
api: api
)
}
@Test("Maps the signed-in server's system information")
func mapsServerInfo() async throws {
var api = MockJellyfinAPI()
api.getSystemInfoOutput = .ok(
.init(
body: .json(
Components.Schemas.SystemInfo(
serverName: "Echo's Server",
version: "10.11.10",
productName: "Jellyfin Server",
id: "srv-1"
)
)
)
)
let client = makeClient(api)
let info = try await client.serverInfo()
#expect(info.serverName == "Echo's Server")
#expect(info.version == "10.11.10")
#expect(info.id == "srv-1")
#expect(info.productName == "Jellyfin Server")
}
@Test("A forbidden response throws before returning any information")
func forbiddenThrows() async {
var api = MockJellyfinAPI()
api.getSystemInfoOutput = .forbidden(.init(body: .json(Components.Schemas.ProblemDetails())))
let client = makeClient(api)
await #expect(throws: JellyfinClientError.forbidden) {
_ = try await client.serverInfo()
}
}
}