@@ -59,6 +59,65 @@ void main() {
|
||||
expect(await service.getOnDeckFromAllServers(), isEmpty);
|
||||
});
|
||||
|
||||
test('searchAcrossServers overfetches and ranks before trimming across backends', () async {
|
||||
final plexRequests = <Uri>[];
|
||||
final jellyfinRequests = <Uri>[];
|
||||
|
||||
final plexClient = PlexClient.forTesting(
|
||||
config: PlexConfig(
|
||||
baseUrl: 'https://plex.example.com',
|
||||
token: 'token',
|
||||
clientIdentifier: 'client-id',
|
||||
product: 'Plezy',
|
||||
version: 'test',
|
||||
),
|
||||
serverId: 'plex-1',
|
||||
serverName: 'Plex',
|
||||
httpClient: MockClient((req) async {
|
||||
plexRequests.add(req.url);
|
||||
if (req.url.path == '/library/search') {
|
||||
return _json({
|
||||
'MediaContainer': {
|
||||
'SearchResult': [
|
||||
{
|
||||
'score': 100,
|
||||
'Metadata': {'ratingKey': 'plex-movie', 'type': 'movie', 'title': 'The Boys in the Boat'},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
return http.Response('unexpected request', 500);
|
||||
}),
|
||||
);
|
||||
addTearDown(plexClient.close);
|
||||
manager.debugRegisterClientForTesting(plexClient);
|
||||
|
||||
final jellyfinClient = JellyfinClient.forTesting(
|
||||
connection: _conn(),
|
||||
httpClient: MockClient((req) async {
|
||||
jellyfinRequests.add(req.url);
|
||||
if (req.url.path == '/Items') {
|
||||
return _json({
|
||||
'Items': [
|
||||
{'Id': 'jf-show', 'Type': 'Series', 'Name': 'The Boys'},
|
||||
],
|
||||
});
|
||||
}
|
||||
return http.Response('unexpected request', 500);
|
||||
}),
|
||||
);
|
||||
addTearDown(jellyfinClient.close);
|
||||
manager.debugRegisterJellyfinClientForTesting(jellyfinClient);
|
||||
|
||||
final results = await service.searchAcrossServers('The Boys', limit: 1);
|
||||
|
||||
expect(results.map((item) => item.id), ['jf-show']);
|
||||
expect(plexRequests.single.queryParameters['limit'], '100');
|
||||
expect(plexRequests.single.queryParameters['searchTypes'], 'movies,tv');
|
||||
expect(jellyfinRequests.single.queryParameters['Limit'], '100');
|
||||
});
|
||||
|
||||
test('getOnDeckFromAllServers forwards preview limit to clients', () async {
|
||||
final captured = <Uri>[];
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:plezy/database/app_database.dart';
|
||||
import 'package:plezy/models/plex/plex_config.dart';
|
||||
import 'package:plezy/services/plex_api_cache.dart';
|
||||
import 'package:plezy/services/plex_client.dart';
|
||||
|
||||
http.Response _json(Object body) => http.Response(jsonEncode(body), 200, headers: {'content-type': 'application/json'});
|
||||
|
||||
void main() {
|
||||
late AppDatabase db;
|
||||
|
||||
setUp(() {
|
||||
db = AppDatabase.forTesting(NativeDatabase.memory());
|
||||
PlexApiCache.initialize(db);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
PlexClient makeClient(Future<http.Response> Function(http.Request request) handler) {
|
||||
return PlexClient.forTesting(
|
||||
config: PlexConfig(
|
||||
baseUrl: 'https://plex.example.com',
|
||||
token: 'token',
|
||||
clientIdentifier: 'client-id',
|
||||
product: 'Plezy',
|
||||
version: 'test',
|
||||
),
|
||||
serverId: 'plex-1',
|
||||
serverName: 'Plex',
|
||||
httpClient: MockClient(handler),
|
||||
);
|
||||
}
|
||||
|
||||
test('search defaults to 100 movie and TV candidates', () async {
|
||||
final captured = <Uri>[];
|
||||
final client = makeClient((request) async {
|
||||
captured.add(request.url);
|
||||
if (request.url.path == '/library/search') {
|
||||
return _json({
|
||||
'MediaContainer': {
|
||||
'SearchResult': [
|
||||
{
|
||||
'score': 90,
|
||||
'Metadata': {'ratingKey': 'movie-1', 'type': 'movie', 'title': 'The Movie'},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
return http.Response('unexpected request', 500);
|
||||
});
|
||||
addTearDown(client.close);
|
||||
|
||||
final results = await client.searchItems('the');
|
||||
|
||||
expect(results.map((item) => item.id), ['movie-1']);
|
||||
expect(captured, hasLength(1));
|
||||
expect(captured.single.path, '/library/search');
|
||||
expect(captured.single.queryParameters['limit'], '100');
|
||||
expect(captured.single.queryParameters['X-Plex-Container-Size'], '100');
|
||||
expect(captured.single.queryParameters['searchTypes'], 'movies,tv');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user