230 lines
9.3 KiB
Swift
230 lines
9.3 KiB
Swift
//
|
|
// MockJellyfinAPI.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 LuminateAPI
|
|
import LuminateServices
|
|
import Testing
|
|
|
|
/// A ``JellyfinAPI`` double that answers with pre-baked generated outputs.
|
|
///
|
|
/// Only the operations a test actually stubs are usable; every other call fails the test with a
|
|
/// clear message rather than returning a fabricated success. Outputs are plain `Sendable` values,
|
|
/// so the whole double is a `Sendable` struct with no isolation escape hatches.
|
|
struct MockJellyfinAPI: JellyfinAPI {
|
|
/// The output returned by ``authenticateUserByName(_:)``.
|
|
var authenticateUserByNameOutput: Operations.AuthenticateUserByName.Output?
|
|
|
|
/// The output returned by ``authenticateWithQuickConnect(_:)``.
|
|
var authenticateWithQuickConnectOutput: Operations.AuthenticateWithQuickConnect.Output?
|
|
|
|
/// The output returned by ``getPublicUsers(_:)``.
|
|
var getPublicUsersOutput: Operations.GetPublicUsers.Output?
|
|
|
|
/// The output returned by ``getPublicSystemInfo(_:)``.
|
|
var getPublicSystemInfoOutput: Operations.GetPublicSystemInfo.Output?
|
|
|
|
/// The output returned by ``getSystemInfo(_:)``.
|
|
var getSystemInfoOutput: Operations.GetSystemInfo.Output?
|
|
|
|
/// The output returned by ``getQuickConnectEnabled(_:)``.
|
|
var getQuickConnectEnabledOutput: Operations.GetQuickConnectEnabled.Output?
|
|
|
|
/// The output returned by ``initiateQuickConnect(_:)``.
|
|
var initiateQuickConnectOutput: Operations.InitiateQuickConnect.Output?
|
|
|
|
/// The output returned by ``getQuickConnectState(_:)``.
|
|
var getQuickConnectStateOutput: Operations.GetQuickConnectState.Output?
|
|
|
|
/// The output returned by ``updateUserPassword(_:)``.
|
|
var updateUserPasswordOutput: Operations.UpdateUserPassword.Output?
|
|
|
|
/// The output returned by ``getUserViews(_:)``.
|
|
var getUserViewsOutput: Operations.GetUserViews.Output?
|
|
|
|
/// The output returned by ``getItems(_:)``.
|
|
var getItemsOutput: Operations.GetItems.Output?
|
|
|
|
/// The output returned by ``getItem(_:)``.
|
|
var getItemOutput: Operations.GetItem.Output?
|
|
|
|
/// The output returned by ``getResumeItems(_:)``.
|
|
var getResumeItemsOutput: Operations.GetResumeItems.Output?
|
|
|
|
/// The output returned by ``getNextUp(_:)``.
|
|
var getNextUpOutput: Operations.GetNextUp.Output?
|
|
|
|
/// The output returned by ``getLatestMedia(_:)``.
|
|
var getLatestMediaOutput: Operations.GetLatestMedia.Output?
|
|
|
|
/// The output returned by ``getSeasons(_:)``.
|
|
var getSeasonsOutput: Operations.GetSeasons.Output?
|
|
|
|
/// The output returned by ``getEpisodes(_:)``.
|
|
var getEpisodesOutput: Operations.GetEpisodes.Output?
|
|
|
|
/// The output returned by ``getSearchHints(_:)``.
|
|
var getSearchHintsOutput: Operations.GetSearchHints.Output?
|
|
|
|
/// The output returned by ``getItemImage(_:)``.
|
|
var getItemImageOutput: Operations.GetItemImage.Output?
|
|
|
|
/// The output returned by ``getItemImageByIndex(_:)``.
|
|
var getItemImageByIndexOutput: Operations.GetItemImageByIndex.Output?
|
|
|
|
/// The output returned by ``markPlayedItem(_:)``.
|
|
var markPlayedItemOutput: Operations.MarkPlayedItem.Output?
|
|
|
|
/// The output returned by ``markUnplayedItem(_:)``.
|
|
var markUnplayedItemOutput: Operations.MarkUnplayedItem.Output?
|
|
|
|
/// The output returned by ``markFavoriteItem(_:)``.
|
|
var markFavoriteItemOutput: Operations.MarkFavoriteItem.Output?
|
|
|
|
/// The output returned by ``unmarkFavoriteItem(_:)``.
|
|
var unmarkFavoriteItemOutput: Operations.UnmarkFavoriteItem.Output?
|
|
|
|
/// Returns a stubbed output, or fails the test naming the unstubbed operation.
|
|
///
|
|
/// - Parameters:
|
|
/// - output: The stubbed output for the operation, if the test supplied one.
|
|
/// - operation: The operation identifier, used in the failure message.
|
|
/// - Returns: The stubbed output.
|
|
/// - Throws: An error that fails the test when the operation was not stubbed.
|
|
private func unwrap<Output>(_ output: Output?, _ operation: String) throws -> Output {
|
|
try #require(output, "MockJellyfinAPI received an unstubbed call to \(operation)")
|
|
}
|
|
|
|
func authenticateUserByName(_ input: Operations.AuthenticateUserByName.Input) async throws
|
|
-> Operations.AuthenticateUserByName.Output
|
|
{
|
|
try unwrap(authenticateUserByNameOutput, "AuthenticateUserByName")
|
|
}
|
|
|
|
func authenticateWithQuickConnect(_ input: Operations.AuthenticateWithQuickConnect.Input) async throws
|
|
-> Operations.AuthenticateWithQuickConnect.Output
|
|
{
|
|
try unwrap(authenticateWithQuickConnectOutput, "AuthenticateWithQuickConnect")
|
|
}
|
|
|
|
func getPublicUsers(_ input: Operations.GetPublicUsers.Input) async throws -> Operations.GetPublicUsers.Output {
|
|
try unwrap(getPublicUsersOutput, "GetPublicUsers")
|
|
}
|
|
|
|
func getPublicSystemInfo(_ input: Operations.GetPublicSystemInfo.Input) async throws
|
|
-> Operations.GetPublicSystemInfo.Output
|
|
{
|
|
try unwrap(getPublicSystemInfoOutput, "GetPublicSystemInfo")
|
|
}
|
|
|
|
func getSystemInfo(_ input: Operations.GetSystemInfo.Input) async throws -> Operations.GetSystemInfo.Output {
|
|
try unwrap(getSystemInfoOutput, "GetSystemInfo")
|
|
}
|
|
|
|
func getQuickConnectEnabled(_ input: Operations.GetQuickConnectEnabled.Input) async throws
|
|
-> Operations.GetQuickConnectEnabled.Output
|
|
{
|
|
try unwrap(getQuickConnectEnabledOutput, "GetQuickConnectEnabled")
|
|
}
|
|
|
|
func initiateQuickConnect(_ input: Operations.InitiateQuickConnect.Input) async throws
|
|
-> Operations.InitiateQuickConnect.Output
|
|
{
|
|
try unwrap(initiateQuickConnectOutput, "InitiateQuickConnect")
|
|
}
|
|
|
|
func getQuickConnectState(_ input: Operations.GetQuickConnectState.Input) async throws
|
|
-> Operations.GetQuickConnectState.Output
|
|
{
|
|
try unwrap(getQuickConnectStateOutput, "GetQuickConnectState")
|
|
}
|
|
|
|
func updateUserPassword(_ input: Operations.UpdateUserPassword.Input) async throws
|
|
-> Operations.UpdateUserPassword.Output
|
|
{
|
|
try unwrap(updateUserPasswordOutput, "UpdateUserPassword")
|
|
}
|
|
|
|
func getUserViews(_ input: Operations.GetUserViews.Input) async throws -> Operations.GetUserViews.Output {
|
|
try unwrap(getUserViewsOutput, "GetUserViews")
|
|
}
|
|
|
|
func getItems(_ input: Operations.GetItems.Input) async throws -> Operations.GetItems.Output {
|
|
try unwrap(getItemsOutput, "GetItems")
|
|
}
|
|
|
|
func getItem(_ input: Operations.GetItem.Input) async throws -> Operations.GetItem.Output {
|
|
try unwrap(getItemOutput, "GetItem")
|
|
}
|
|
|
|
func getResumeItems(_ input: Operations.GetResumeItems.Input) async throws -> Operations.GetResumeItems.Output {
|
|
try unwrap(getResumeItemsOutput, "GetResumeItems")
|
|
}
|
|
|
|
func getNextUp(_ input: Operations.GetNextUp.Input) async throws -> Operations.GetNextUp.Output {
|
|
try unwrap(getNextUpOutput, "GetNextUp")
|
|
}
|
|
|
|
func getLatestMedia(_ input: Operations.GetLatestMedia.Input) async throws -> Operations.GetLatestMedia.Output {
|
|
try unwrap(getLatestMediaOutput, "GetLatestMedia")
|
|
}
|
|
|
|
func getSeasons(_ input: Operations.GetSeasons.Input) async throws -> Operations.GetSeasons.Output {
|
|
try unwrap(getSeasonsOutput, "GetSeasons")
|
|
}
|
|
|
|
func getEpisodes(_ input: Operations.GetEpisodes.Input) async throws -> Operations.GetEpisodes.Output {
|
|
try unwrap(getEpisodesOutput, "GetEpisodes")
|
|
}
|
|
|
|
func getSearchHints(_ input: Operations.GetSearchHints.Input) async throws -> Operations.GetSearchHints.Output {
|
|
try unwrap(getSearchHintsOutput, "GetSearchHints")
|
|
}
|
|
|
|
func getItemImage(_ input: Operations.GetItemImage.Input) async throws -> Operations.GetItemImage.Output {
|
|
try unwrap(getItemImageOutput, "GetItemImage")
|
|
}
|
|
|
|
func getItemImageByIndex(_ input: Operations.GetItemImageByIndex.Input) async throws
|
|
-> Operations.GetItemImageByIndex.Output
|
|
{
|
|
try unwrap(getItemImageByIndexOutput, "GetItemImageByIndex")
|
|
}
|
|
|
|
func markPlayedItem(_ input: Operations.MarkPlayedItem.Input) async throws -> Operations.MarkPlayedItem.Output {
|
|
try unwrap(markPlayedItemOutput, "MarkPlayedItem")
|
|
}
|
|
|
|
func markUnplayedItem(_ input: Operations.MarkUnplayedItem.Input) async throws -> Operations.MarkUnplayedItem.Output
|
|
{
|
|
try unwrap(markUnplayedItemOutput, "MarkUnplayedItem")
|
|
}
|
|
|
|
func markFavoriteItem(_ input: Operations.MarkFavoriteItem.Input) async throws -> Operations.MarkFavoriteItem.Output
|
|
{
|
|
try unwrap(markFavoriteItemOutput, "MarkFavoriteItem")
|
|
}
|
|
|
|
func unmarkFavoriteItem(_ input: Operations.UnmarkFavoriteItem.Input) async throws
|
|
-> Operations.UnmarkFavoriteItem.Output
|
|
{
|
|
try unwrap(unmarkFavoriteItemOutput, "UnmarkFavoriteItem")
|
|
}
|
|
}
|