mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: Save profile defaults per device
This commit is contained in:
@@ -82,5 +82,42 @@ void main() {
|
||||
expect(reloaded.activeProfileId, profile.id);
|
||||
},
|
||||
);
|
||||
|
||||
test('stores per-device default profiles independently', () async {
|
||||
final manager = ProfileManager();
|
||||
await manager.initialize();
|
||||
await manager.setProfilesEnabled(true);
|
||||
|
||||
final profile = ConfigProfile(
|
||||
id: 'profile-alpha',
|
||||
name: 'Alpha',
|
||||
createdAt: DateTime.parse('2026-03-16T12:00:00Z'),
|
||||
updatedAt: DateTime.parse('2026-03-16T12:00:00Z'),
|
||||
sections: const ConfigProfileSections(),
|
||||
);
|
||||
|
||||
await manager.upsertProfile(profile);
|
||||
await manager.setActiveProfileIdForDevice(
|
||||
profile.id,
|
||||
deviceKey: 'pk:device-a',
|
||||
);
|
||||
await manager.setActiveProfileIdForDevice(
|
||||
ConfigProfile.defaultProfileId,
|
||||
deviceKey: 'pk:device-b',
|
||||
);
|
||||
|
||||
final reloaded = ProfileManager();
|
||||
await reloaded.initialize();
|
||||
|
||||
expect(reloaded.profileIdForDevice('pk:device-a'), profile.id);
|
||||
expect(
|
||||
reloaded.profileIdForDevice('pk:device-b'),
|
||||
ConfigProfile.defaultProfileId,
|
||||
);
|
||||
expect(
|
||||
reloaded.profileIdForDevice('pk:device-c'),
|
||||
ConfigProfile.defaultProfileId,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -184,6 +184,39 @@ void main() {
|
||||
expect(manager.activeProfileId, target.id);
|
||||
},
|
||||
);
|
||||
|
||||
test('syncActiveProfileForCurrentDevice uses per-device default', () async {
|
||||
final manager = ProfileManager();
|
||||
await manager.initialize();
|
||||
await manager.setProfilesEnabled(true);
|
||||
|
||||
final alpha = ConfigProfile(
|
||||
id: 'profile-alpha',
|
||||
name: 'Alpha',
|
||||
createdAt: DateTime.parse('2026-03-16T12:00:00Z'),
|
||||
updatedAt: DateTime.parse('2026-03-16T12:00:00Z'),
|
||||
sections: const ConfigProfileSections(),
|
||||
);
|
||||
await manager.upsertProfile(alpha);
|
||||
await manager.setActiveProfileIdForDevice(
|
||||
alpha.id,
|
||||
deviceKey: 'pk:01020304',
|
||||
);
|
||||
await manager.setActiveProfileId(ConfigProfile.defaultProfileId);
|
||||
|
||||
final connectionProvider = _FakeConnectionProvider(
|
||||
deviceInfo: DeviceInfo(publicKey: Uint8List.fromList([1, 2, 3, 4])),
|
||||
);
|
||||
final coordinator = _buildCoordinator(
|
||||
profileManager: manager,
|
||||
connectionProvider: connectionProvider,
|
||||
);
|
||||
|
||||
await coordinator.syncActiveProfileForCurrentDevice();
|
||||
|
||||
expect(manager.activeProfileId, alpha.id);
|
||||
expect(connectionProvider.disconnectCallCount, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -265,10 +298,18 @@ class _FakeDeviceConfigApplicator extends DeviceConfigApplicator {
|
||||
}
|
||||
|
||||
class _FakeConnectionProvider implements ConnectionProvider {
|
||||
_FakeConnectionProvider({
|
||||
DeviceInfo? deviceInfo,
|
||||
this.connectionMode = ConnectionMode.ble,
|
||||
}) : deviceInfo = deviceInfo ?? DeviceInfo();
|
||||
|
||||
int disconnectCallCount = 0;
|
||||
|
||||
@override
|
||||
DeviceInfo get deviceInfo => DeviceInfo();
|
||||
final DeviceInfo deviceInfo;
|
||||
|
||||
@override
|
||||
final ConnectionMode connectionMode;
|
||||
|
||||
@override
|
||||
Future<void> disconnect() async {
|
||||
|
||||
Reference in New Issue
Block a user