feat(profiles): show the first linked connection's user picture

A local profile had no picture of its own and always fell back to
initials. It now borrows the user picture of the connection it was
linked to first — oldest Connection.createdAt, ties broken by
connection id, since the join table carries no creation time.

Jellyfin links resolve to /Users/{id}/Images/Primary, keyed by the
PrimaryImageTag now captured at authentication and refreshed from the
/Users/Me body checkHealth already fetches. That endpoint is anonymous
on every Jellyfin release, so the URL carries no api_key and the access
token stays out of the image cache key. Plex links resolve the Home
user the link points at against PlexHomeService's live cache, so no
account-level lookup is needed and the picture tracks Plex's own
refresh.

The picture is derived per snapshot and never written back onto a
Profile: ProfileDetailScreen upserts the model it holds, so a
persisted URL would go stale and outlive the connection it came from.
Plex Home profiles are untouched, including one whose Plex avatar is
unset — it keeps its initials rather than borrowing a lent connection's
picture.

close #1667
This commit is contained in:
edde746
2026-08-04 02:22:44 +02:00
parent 2b4875d389
commit 860ce1e11a
32 changed files with 1469 additions and 46 deletions
@@ -71,6 +71,7 @@ void main() {
registry: profiles,
plexHome: plexHome,
connections: connections,
profileConnections: profileConnections,
storage: storage,
);
manager = MultiServerManager();
+161 -4
View File
@@ -9,6 +9,7 @@ import 'package:plezy/models/plex/plex_home_user.dart';
import 'package:plezy/profiles/active_profile_provider.dart';
import 'package:plezy/profiles/plex_home_service.dart';
import 'package:plezy/profiles/profile.dart';
import 'package:plezy/profiles/profile_connection.dart';
import 'package:plezy/profiles/profile_connection_registry.dart';
import 'package:plezy/profiles/profile_registry.dart';
import 'package:plezy/services/storage_service.dart';
@@ -78,12 +79,12 @@ final class _RecordingPreferencesPlatform extends SharedPreferencesAsyncPlatform
delegate.getKeys(parameters, options);
}
PlexHomeUser _homeUser(String uuid, {String name = 'Home User'}) {
PlexHomeUser _homeUser(String uuid, {int id = 1, String name = 'Home User', String thumb = ''}) {
return PlexHomeUser(
id: 1,
id: id,
uuid: uuid,
title: name,
thumb: '',
thumb: thumb,
hasPassword: false,
restricted: false,
updatedAt: null,
@@ -103,10 +104,26 @@ PlexAccountConnection _account(String id) {
);
}
JellyfinConnection _jellyfin(String id, {required DateTime createdAt, required String primaryImageTag}) {
return JellyfinConnection(
id: id,
baseUrl: 'https://jellyfin.example',
serverName: 'Jellyfin',
serverMachineId: 'machine-$id',
userId: 'user-$id',
userName: 'User $id',
accessToken: 'token-$id',
deviceId: 'device-$id',
primaryImageTag: primaryImageTag,
createdAt: createdAt,
);
}
void main() {
late AppDatabase db;
late ProfileRegistry registry;
late ConnectionRegistry connections;
late ProfileConnectionRegistry profileConnections;
late PlexHomeService plexHome;
late ActiveProfileProvider provider;
late StorageService storage;
@@ -122,9 +139,10 @@ void main() {
connections = ConnectionRegistry(db);
storage = await StorageService.getInstance();
fetchedHomeUsers = const [];
profileConnections = ProfileConnectionRegistry(db);
plexHome = PlexHomeService(
connections: connections,
profileConnections: ProfileConnectionRegistry(db),
profileConnections: profileConnections,
storage: storage,
plexHomeUserFetcher: (_) async => fetchedHomeUsers,
);
@@ -132,6 +150,7 @@ void main() {
registry: registry,
plexHome: plexHome,
connections: connections,
profileConnections: profileConnections,
storage: storage,
);
});
@@ -219,6 +238,144 @@ void main() {
expect(notifications, 0);
});
group('avatarUrlFor', () {
test('returns the linked Jellyfin user picture after initialize', () async {
final profile = Profile.local(id: 'p1', displayName: 'Owner', createdAt: DateTime(2026, 1, 1));
final connection = _jellyfin('first', createdAt: DateTime(2025, 1, 1), primaryImageTag: 'avatar-tag');
await registry.upsert(profile);
await connections.upsert(connection);
await profileConnections.upsert(
const ProfileConnection(profileId: 'p1', connectionId: 'first', userIdentifier: 'user-first'),
);
await provider.initialize();
expect(
provider.avatarUrlFor(profile.id),
'https://jellyfin.example/Users/user-first/Images/Primary'
'?tag=avatar-tag&maxWidth=240&maxHeight=240',
);
});
test('returns null for profiles without links and unknown profile ids', () async {
await registry.upsert(Profile.local(id: 'unlinked', displayName: 'Owner', createdAt: DateTime(2026, 1, 1)));
await provider.initialize();
expect(provider.avatarUrlFor('unlinked'), isNull);
expect(provider.avatarUrlFor('unknown'), isNull);
});
test('linking an older connection updates the selected picture', () async {
final profile = Profile.local(id: 'p1', displayName: 'Owner', createdAt: DateTime(2026, 1, 1));
final newer = _jellyfin('newer', createdAt: DateTime(2026, 1, 2), primaryImageTag: 'newer-tag');
final older = _jellyfin('older', createdAt: DateTime(2025, 12, 31), primaryImageTag: 'older-tag');
await registry.upsert(profile);
await connections.upsert(newer);
await connections.upsert(older);
await profileConnections.upsert(
const ProfileConnection(profileId: 'p1', connectionId: 'newer', userIdentifier: 'user-newer'),
);
await provider.initialize();
expect(
provider.avatarUrlFor(profile.id),
'https://jellyfin.example/Users/user-newer/Images/Primary'
'?tag=newer-tag&maxWidth=240&maxHeight=240',
);
final changed = Completer<void>();
void listener() {
if (provider.avatarUrlFor(profile.id)?.contains('older-tag') ?? false) {
if (!changed.isCompleted) changed.complete();
}
}
provider.addListener(listener);
addTearDown(() => provider.removeListener(listener));
await profileConnections.upsert(
const ProfileConnection(profileId: 'p1', connectionId: 'older', userIdentifier: 'user-older'),
);
await changed.future.timeout(const Duration(seconds: 2));
expect(
provider.avatarUrlFor(profile.id),
'https://jellyfin.example/Users/user-older/Images/Primary'
'?tag=older-tag&maxWidth=240&maxHeight=240',
);
});
test('token and timestamp churn on a link does not notify listeners', () async {
await registry.upsert(Profile.local(id: 'p1', displayName: 'Owner', createdAt: DateTime(2026, 1, 1)));
await connections.upsert(_jellyfin('jellyfin', createdAt: DateTime(2025, 1, 1), primaryImageTag: 'avatar-tag'));
await profileConnections.upsert(
const ProfileConnection(
profileId: 'p1',
connectionId: 'jellyfin',
userToken: 'initial-token',
userIdentifier: 'user-jellyfin',
),
);
await provider.initialize();
var notifications = 0;
void listener() => notifications++;
provider.addListener(listener);
addTearDown(() => provider.removeListener(listener));
final churnObserved = Completer<void>();
final rowSubscription = profileConnections.watchAll().listen((rows) {
final row = rows.single;
if (row.userToken == 'refreshed-token' && row.tokenAcquiredAt != null && !churnObserved.isCompleted) {
churnObserved.complete();
}
});
addTearDown(rowSubscription.cancel);
await profileConnections.recordToken('p1', 'jellyfin', 'refreshed-token');
await churnObserved.future.timeout(const Duration(seconds: 2));
await Future<void>(() {});
expect(notifications, 0);
});
test('changing a Plex link user changes the picture and notifies listeners', () async {
final profile = Profile.local(id: 'p1', displayName: 'Owner', createdAt: DateTime(2026, 1, 1));
final account = _account('plex.acct');
final firstUser = _homeUser('home-1', thumb: 'https://images.example/first.jpg');
final secondUser = _homeUser('home-2', id: 2, thumb: 'https://images.example/second.jpg');
fetchedHomeUsers = [firstUser, secondUser];
await registry.upsert(profile);
await connections.upsert(account);
await profileConnections.upsert(
const ProfileConnection(profileId: 'p1', connectionId: 'plex.acct', userIdentifier: 'home-1'),
);
expect(await plexHome.refresh(account), isTrue);
await provider.initialize();
expect(provider.avatarUrlFor(profile.id), firstUser.thumb);
var notifications = 0;
final changed = Completer<void>();
void listener() {
notifications++;
if (provider.avatarUrlFor(profile.id) == secondUser.thumb && !changed.isCompleted) {
changed.complete();
}
}
provider.addListener(listener);
addTearDown(() => provider.removeListener(listener));
await profileConnections.upsert(
const ProfileConnection(profileId: 'p1', connectionId: 'plex.acct', userIdentifier: 'home-2'),
);
await changed.future.timeout(const Duration(seconds: 2));
expect(provider.avatarUrlFor(profile.id), secondUser.thumb);
expect(notifications, greaterThan(0));
});
});
test('initialize resolves the stored active profile id', () async {
await registry.upsert(Profile.local(id: 'p1', displayName: 'Owner', createdAt: DateTime(2026, 1, 1)));
await registry.upsert(Profile.local(id: 'p2', displayName: 'Kids', createdAt: DateTime(2026, 1, 2)));
@@ -118,6 +118,7 @@ class _ThrowingActiveProfileProvider extends ActiveProfileProvider {
required super.registry,
required super.plexHome,
required super.connections,
required super.profileConnections,
required super.storage,
super.activeProfileIdWriter,
});
@@ -515,6 +516,7 @@ void main() {
registry: profiles,
plexHome: plexHome,
connections: connections,
profileConnections: profileConnections,
storage: storage,
activeProfileIdWriter: writer,
);
@@ -623,6 +625,7 @@ Future<_Harness> _pumpHarness(
registry: profiles,
plexHome: plexHome,
connections: connections,
profileConnections: profileConnections,
storage: storage,
activeProfileIdWriter: gateOwnerRestoreWrite || failNewerIdentityWrite ? activeProfileIdWriter : null,
);
@@ -0,0 +1,266 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/connection/connection.dart';
import 'package:plezy/models/plex/plex_home_user.dart';
import 'package:plezy/profiles/profile.dart';
import 'package:plezy/profiles/profile_avatar_source.dart';
import 'package:plezy/profiles/profile_connection.dart';
JellyfinConnection _jellyfin(
String id, {
required DateTime createdAt,
String? primaryImageTag,
String userId = 'jf-user',
String baseUrl = 'https://jelly.example',
}) {
return JellyfinConnection(
id: id,
baseUrl: baseUrl,
serverName: 'Jelly',
serverMachineId: 'machine-$id',
userId: userId,
userName: 'Agent',
accessToken: 'secret-token',
deviceId: 'device-1',
primaryImageTag: primaryImageTag,
createdAt: createdAt,
);
}
PlexAccountConnection _plex(String id, {required DateTime createdAt}) {
return PlexAccountConnection(
id: id,
accountToken: 'token-$id',
clientIdentifier: 'client-$id',
accountLabel: 'Plex',
createdAt: createdAt,
);
}
PlexHomeUser _homeUser(String uuid, {String thumb = ''}) {
return PlexHomeUser(
id: 1,
uuid: uuid,
title: 'Home $uuid',
thumb: thumb,
hasPassword: false,
restricted: false,
updatedAt: null,
admin: false,
guest: false,
protected: false,
);
}
ProfileConnection _link(String connectionId, {String profileId = 'local-1', String userIdentifier = 'jf-user'}) {
return ProfileConnection(profileId: profileId, connectionId: connectionId, userIdentifier: userIdentifier);
}
Profile _local([String id = 'local-1']) => Profile.local(id: id, displayName: 'Owner', createdAt: DateTime(2026, 1, 1));
String? _resolve({
required List<Profile> profiles,
required Map<String, List<ProfileConnection>> links,
required Map<String, Connection> connections,
Map<String, List<PlexHomeUser>> plexHome = const {},
String profileId = 'local-1',
}) {
return resolveProfileAvatarUrls(
profiles: profiles,
connectionsByProfile: links,
connectionsById: connections,
plexHomeByConnectionId: plexHome,
)[profileId];
}
void main() {
group('resolveProfileAvatarUrls', () {
test('uses the picture of the oldest linked connection', () {
final older = _jellyfin('jf-older', createdAt: DateTime(2026, 1, 1), primaryImageTag: 'older-tag');
final newer = _jellyfin('jf-newer', createdAt: DateTime(2026, 6, 1), primaryImageTag: 'newer-tag');
final url = _resolve(
profiles: [_local()],
// Deliberately newest-first: the registry stream has no ordering
// guarantee, so resolution must sort rather than take the head.
links: {
'local-1': [_link('jf-newer'), _link('jf-older')],
},
connections: {'jf-older': older, 'jf-newer': newer},
);
expect(url, contains('tag=older-tag'));
});
test('falls back to initials when the first connection has no picture', () {
final first = _jellyfin('jf-first', createdAt: DateTime(2026, 1, 1));
final second = _jellyfin('jf-second', createdAt: DateTime(2026, 6, 1), primaryImageTag: 'second-tag');
final url = _resolve(
profiles: [_local()],
links: {
'local-1': [_link('jf-first'), _link('jf-second')],
},
connections: {'jf-first': first, 'jf-second': second},
);
// "First wins" is literal: we do not skip ahead to a later connection
// that happens to have an image.
expect(url, isNull);
});
test('breaks a createdAt tie on connection id so the choice is stable', () {
final sameInstant = DateTime(2026, 1, 1);
final b = _jellyfin('jf-b', createdAt: sameInstant, primaryImageTag: 'b-tag');
final a = _jellyfin('jf-a', createdAt: sameInstant, primaryImageTag: 'a-tag');
final url = _resolve(
profiles: [_local()],
links: {
'local-1': [_link('jf-b'), _link('jf-a')],
},
connections: {'jf-b': b, 'jf-a': a},
);
expect(url, contains('tag=a-tag'));
});
test('ignores links whose connection is gone, including for ordering', () {
final survivor = _jellyfin('jf-survivor', createdAt: DateTime(2026, 6, 1), primaryImageTag: 'survivor-tag');
final url = _resolve(
profiles: [_local()],
links: {
'local-1': [_link('jf-removed'), _link('jf-survivor')],
},
connections: {'jf-survivor': survivor},
);
expect(url, contains('tag=survivor-tag'));
});
test('resolves a Plex link through the home user the link points at', () {
final plex = _plex('plex-1', createdAt: DateTime(2026, 1, 1));
final url = _resolve(
profiles: [_local()],
links: {
'local-1': [_link('plex-1', userIdentifier: 'home-b')],
},
connections: {'plex-1': plex},
plexHome: {
'plex-1': [
_homeUser('home-a', thumb: 'https://plex.tv/users/home-a/avatar'),
_homeUser('home-b', thumb: 'https://plex.tv/users/home-b/avatar'),
],
},
);
expect(url, 'https://plex.tv/users/home-b/avatar');
});
test('gives no picture for a Plex link with no home user selected', () {
final plex = _plex('plex-1', createdAt: DateTime(2026, 1, 1));
final url = _resolve(
profiles: [_local()],
links: {
'local-1': [_link('plex-1', userIdentifier: '')],
},
connections: {'plex-1': plex},
plexHome: {
'plex-1': [_homeUser('home-a', thumb: 'https://plex.tv/users/home-a/avatar')],
},
);
expect(url, isNull);
});
test('gives no picture when the selected home user has a blank thumb', () {
final plex = _plex('plex-1', createdAt: DateTime(2026, 1, 1));
final url = _resolve(
profiles: [_local()],
links: {
'local-1': [_link('plex-1', userIdentifier: 'home-a')],
},
connections: {'plex-1': plex},
plexHome: {
'plex-1': [_homeUser('home-a')],
},
);
expect(url, isNull);
});
test('mixed Jellyfin and Plex links still resolve by creation order', () {
final plexFirst = _plex('plex-1', createdAt: DateTime(2026, 1, 1));
final jellyfinSecond = _jellyfin('jf-1', createdAt: DateTime(2026, 6, 1), primaryImageTag: 'jf-tag');
final url = _resolve(
profiles: [_local()],
links: {
'local-1': [_link('jf-1'), _link('plex-1', userIdentifier: 'home-a')],
},
connections: {'plex-1': plexFirst, 'jf-1': jellyfinSecond},
plexHome: {
'plex-1': [_homeUser('home-a', thumb: 'https://plex.tv/users/home-a/avatar')],
},
);
expect(url, 'https://plex.tv/users/home-a/avatar');
});
test('leaves a Plex Home profile on its own thumb', () {
final plexHomeProfile = Profile.virtualPlexHome(
connectionId: 'plex-1',
homeUser: _homeUser('home-a', thumb: 'https://plex.tv/users/home-a/avatar'),
);
final borrowed = _jellyfin('jf-1', createdAt: DateTime(2026, 1, 1), primaryImageTag: 'jf-tag');
final url = _resolve(
profiles: [plexHomeProfile],
links: {
plexHomeProfile.id: [_link('jf-1', profileId: plexHomeProfile.id)],
},
connections: {'jf-1': borrowed},
profileId: plexHomeProfile.id,
);
expect(url, 'https://plex.tv/users/home-a/avatar');
});
test('a Plex Home profile with no avatar keeps its initials rather than borrowing one', () {
final plexHomeProfile = Profile.virtualPlexHome(connectionId: 'plex-1', homeUser: _homeUser('home-a'));
final borrowed = _jellyfin('jf-1', createdAt: DateTime(2026, 1, 1), primaryImageTag: 'jf-tag');
final url = _resolve(
profiles: [plexHomeProfile],
links: {
plexHomeProfile.id: [_link('jf-1', profileId: plexHomeProfile.id)],
},
connections: {'jf-1': borrowed},
profileId: plexHomeProfile.id,
);
// Plex owns this identity end to end; "nothing changes" for Plex Home
// profiles means a blank thumb stays blank, not that it picks up the
// picture of a lent connection.
expect(url, isNull);
});
test('gives no picture to a profile with no links', () {
expect(_resolve(profiles: [_local()], links: const {}, connections: const {}), isNull);
});
test('covers every profile so callers can look up by id', () {
final map = resolveProfileAvatarUrls(
profiles: [_local('local-1'), _local('local-2')],
connectionsByProfile: const {},
connectionsById: const {},
plexHomeByConnectionId: const {},
);
expect(map.keys, containsAll(['local-1', 'local-2']));
});
});
}
+132
View File
@@ -0,0 +1,132 @@
import 'package:cached_network_image_ce/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:plezy/profiles/profile.dart';
import 'package:plezy/profiles/profile_avatar.dart';
import 'package:plezy/utils/initials_palette.dart';
void main() {
Future<void> pumpAvatar(
WidgetTester tester, {
required Profile profile,
String? avatarUrl,
double size = 40,
double devicePixelRatio = 1,
}) {
return tester.pumpWidget(
MaterialApp(
theme: ThemeData(),
home: MediaQuery(
data: MediaQueryData(devicePixelRatio: devicePixelRatio),
child: Center(
child: ProfileAvatar(profile: profile, avatarUrl: avatarUrl, size: size),
),
),
),
);
}
Profile localProfile({String? avatarThumbUrl, String? pinHash}) {
return Profile.local(
id: 'local-owner',
displayName: 'Owner',
avatarThumbUrl: avatarThumbUrl,
pinHash: pinHash,
createdAt: DateTime(2026, 1, 1),
);
}
testWidgets('avatarUrl renders the derived network image', (tester) async {
const avatarUrl = 'https://jellyfin.example/Users/user-1/Images/Primary?tag=derived';
await pumpAvatar(tester, profile: localProfile(), avatarUrl: avatarUrl);
final image = tester.widget<CachedNetworkImage>(find.byType(CachedNetworkImage));
expect(image.imageUrl, avatarUrl);
});
testWidgets('avatarUrl takes precedence over the profile thumbnail', (tester) async {
const derivedUrl = 'https://jellyfin.example/Users/user-1/Images/Primary?tag=derived';
const profileThumbUrl = 'https://plex.example/profile-thumb.jpg';
await pumpAvatar(
tester,
profile: localProfile(avatarThumbUrl: profileThumbUrl),
avatarUrl: derivedUrl,
);
final image = tester.widget<CachedNetworkImage>(find.byType(CachedNetworkImage));
expect(image.imageUrl, derivedUrl);
});
testWidgets('a null avatarUrl preserves the profile thumbnail fallback', (tester) async {
const profileThumbUrl = 'https://plex.example/profile-thumb.jpg';
await pumpAvatar(tester, profile: localProfile(avatarThumbUrl: profileThumbUrl));
final image = tester.widget<CachedNetworkImage>(find.byType(CachedNetworkImage));
expect(image.imageUrl, profileThumbUrl);
});
testWidgets('a profile without a picture renders its display-name initial', (tester) async {
final profile = localProfile();
await pumpAvatar(tester, profile: profile);
expect(find.byType(CachedNetworkImage), findsNothing);
expect(find.text(initialOf(profile.displayName)), findsOneWidget);
});
testWidgets('an empty avatarUrl falls through to the profile picture rather than suppressing it', (tester) async {
const plexThumb = 'https://plex.tv/users/abc/avatar';
// An empty override means "nothing derived". Treating it as a value would
// blank out a Plex Home profile that owns a perfectly good thumb.
await pumpAvatar(
tester,
profile: localProfile(avatarThumbUrl: plexThumb),
avatarUrl: '',
);
expect(tester.widget<CachedNetworkImage>(find.byType(CachedNetworkImage)).imageUrl, plexThumb);
});
testWidgets('an empty avatarUrl renders initials instead of requesting an empty URL', (tester) async {
final profile = localProfile();
await pumpAvatar(tester, profile: profile, avatarUrl: '');
expect(find.byType(CachedNetworkImage), findsNothing);
expect(find.text(initialOf(profile.displayName)), findsOneWidget);
});
testWidgets('network image decoding is bounded by the physical avatar size', (tester) async {
const size = 44.0;
const devicePixelRatio = 2.5;
await pumpAvatar(
tester,
profile: localProfile(),
avatarUrl: 'https://jellyfin.example/Users/user-1/Images/Primary?tag=large-original',
size: size,
devicePixelRatio: devicePixelRatio,
);
final image = tester.widget<CachedNetworkImage>(find.byType(CachedNetworkImage));
final expectedDecodeSize = (size * devicePixelRatio).round();
expect(image.memCacheWidth, expectedDecodeSize);
expect(image.memCacheHeight, expectedDecodeSize);
});
testWidgets('a derived avatar keeps the PIN lock badge visible', (tester) async {
await pumpAvatar(
tester,
profile: localProfile(pinHash: 'stored-pin-hash'),
avatarUrl: 'https://jellyfin.example/Users/user-1/Images/Primary?tag=derived',
);
expect(find.byType(CachedNetworkImage), findsOneWidget);
expect(find.byIcon(Symbols.lock_rounded), findsOneWidget);
});
}
+80
View File
@@ -1,8 +1,13 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/connection/connection.dart';
import 'package:plezy/models/plex/plex_home_user.dart';
import 'package:plezy/profiles/profile.dart';
import 'package:plezy/profiles/profile_connection.dart';
import 'package:plezy/profiles/profiles_view.dart';
import '../test_helpers/prefs.dart';
import '../test_helpers/profile_stack.dart';
void main() {
group('visibleProfileConnections', () {
test('keeps all local profile connection rows', () {
@@ -33,4 +38,79 @@ void main() {
expect(visible.single.connectionId, 'jellyfin-1');
});
});
group('avatarUrlByProfile', () {
late ProfileStack stack;
setUp(() async {
resetSharedPreferencesForTest();
stack = await ProfileStack.create(
homeUsers: [
PlexHomeUser(
id: 1,
uuid: 'home-user',
title: 'Home User',
thumb: 'https://images.example/home.jpg',
hasPassword: false,
restricted: false,
updatedAt: null,
admin: true,
guest: false,
protected: false,
),
],
);
});
tearDown(() => stack.dispose());
test('maps linked pictures, unlinked initials, and Plex Home pictures', () async {
final linked = Profile.local(id: 'linked', displayName: 'Linked', createdAt: DateTime(2026, 1, 1));
final unlinked = Profile.local(id: 'unlinked', displayName: 'Unlinked', createdAt: DateTime(2026, 1, 2));
final jellyfin = JellyfinConnection(
id: 'jellyfin',
baseUrl: 'https://jellyfin.example',
serverName: 'Jellyfin',
serverMachineId: 'machine-id',
userId: 'jellyfin-user',
userName: 'Jellyfin User',
accessToken: 'token',
deviceId: 'device-id',
primaryImageTag: 'image-tag',
createdAt: DateTime(2025, 1, 1),
);
final plex = PlexAccountConnection(
id: 'plex',
accountToken: 'account-token',
clientIdentifier: 'client-id',
accountLabel: 'Plex',
createdAt: DateTime(2025, 1, 2),
);
await stack.profiles.upsert(linked);
await stack.profiles.upsert(unlinked);
await stack.connections.upsert(jellyfin);
await stack.connections.upsert(plex);
await stack.profileConnections.upsert(
const ProfileConnection(profileId: 'linked', connectionId: 'jellyfin', userIdentifier: 'jellyfin-user'),
);
expect(await stack.plexHome.refresh(plex), isTrue);
final view = await watchProfilesView(
profiles: stack.profiles,
profileConnections: stack.profileConnections,
connections: stack.connections,
plexHome: stack.plexHome,
storage: stack.storage,
).first.timeout(const Duration(seconds: 2));
final plexHomeId = plexHomeProfileId(accountConnectionId: plex.id, homeUserUuid: 'home-user');
expect(
view.avatarUrlByProfile[linked.id],
'https://jellyfin.example/Users/jellyfin-user/Images/Primary'
'?tag=image-tag&maxWidth=240&maxHeight=240',
);
expect(view.avatarUrlByProfile[unlinked.id], isNull);
expect(view.avatarUrlByProfile[plexHomeId], 'https://images.example/home.jpg');
});
});
}