fix(trackers): preserve Plex library context
This commit is contained in:
@@ -23,8 +23,15 @@ void main() {
|
||||
});
|
||||
|
||||
// Helper: minimal Plex MediaContainer payload that PlexCacheParser can parse.
|
||||
Map<String, dynamic> mediaContainer({String ratingKey = '42', String title = 'Item'}) => {
|
||||
Map<String, dynamic> mediaContainer({
|
||||
String ratingKey = '42',
|
||||
String title = 'Item',
|
||||
Object? librarySectionID,
|
||||
String? librarySectionTitle,
|
||||
}) => {
|
||||
'MediaContainer': {
|
||||
'librarySectionID': ?librarySectionID,
|
||||
'librarySectionTitle': ?librarySectionTitle,
|
||||
'Metadata': [
|
||||
{'ratingKey': ratingKey, 'title': title, 'type': 'movie'},
|
||||
],
|
||||
@@ -260,6 +267,20 @@ void main() {
|
||||
expect(meta.serverId, 'srv');
|
||||
});
|
||||
|
||||
test('getMetadata preserves hoisted MediaContainer library fields', () async {
|
||||
await cache.put(
|
||||
'srv',
|
||||
'/library/metadata/42',
|
||||
mediaContainer(ratingKey: '42', title: 'Hello', librarySectionID: '7', librarySectionTitle: 'Movies'),
|
||||
);
|
||||
|
||||
final meta = await cache.getMetadata('srv', '42');
|
||||
|
||||
expect(meta, isNotNull);
|
||||
expect(meta!.libraryId, '7');
|
||||
expect(meta.libraryTitle, 'Movies');
|
||||
});
|
||||
|
||||
test('getAllPinnedMetadata returns an empty map when nothing is pinned', () async {
|
||||
await cache.put('srv', '/library/metadata/1', mediaContainer(ratingKey: '1'));
|
||||
// No pin yet.
|
||||
@@ -285,6 +306,20 @@ void main() {
|
||||
expect(result['srv-b:9']!.serverId, 'srv-b');
|
||||
});
|
||||
|
||||
test('getAllPinnedMetadata preserves hoisted MediaContainer library fields', () async {
|
||||
await cache.put(
|
||||
'srv',
|
||||
'/library/metadata/42',
|
||||
mediaContainer(ratingKey: '42', title: 'Hello', librarySectionID: 7, librarySectionTitle: 'Movies'),
|
||||
);
|
||||
await cache.pinForOffline('srv', '42');
|
||||
|
||||
final result = await cache.getAllPinnedMetadata();
|
||||
|
||||
expect(result['srv:42']!.libraryId, '7');
|
||||
expect(result['srv:42']!.libraryTitle, 'Movies');
|
||||
});
|
||||
|
||||
test('getAllPinnedMetadata skips rows whose key is not a metadata endpoint', () async {
|
||||
// Insert a pinned row at a non-metadata endpoint via raw insert.
|
||||
await db
|
||||
|
||||
Reference in New Issue
Block a user