Add duplicate profile merge and share deep-link routing
This commit is contained in:
@@ -254,6 +254,125 @@ void main() {
|
||||
expect(after.sharedMessages.first.resolvedAutomatically, isFalse);
|
||||
});
|
||||
|
||||
test(
|
||||
'mergePersonProfiles rebinds related records to target profile',
|
||||
() async {
|
||||
final ProviderContainer container = _createContainer();
|
||||
addTearDown(container.dispose);
|
||||
|
||||
await container.read(localRepositoryProvider.future);
|
||||
await container
|
||||
.read(localRepositoryProvider.notifier)
|
||||
.addPerson(
|
||||
name: 'Ava Hart',
|
||||
relationship: 'Partner',
|
||||
notes: 'Primary notes',
|
||||
tags: const <String>['coffee'],
|
||||
location: 'Austin',
|
||||
);
|
||||
await container
|
||||
.read(localRepositoryProvider.notifier)
|
||||
.addPerson(
|
||||
name: 'Ava H.',
|
||||
relationship: 'Friend',
|
||||
notes: 'Secondary notes',
|
||||
tags: const <String>['books'],
|
||||
);
|
||||
|
||||
LocalDataState state = await container.read(
|
||||
localRepositoryProvider.future,
|
||||
);
|
||||
final String targetId = state.people
|
||||
.firstWhere((PersonProfile person) => person.name == 'Ava Hart')
|
||||
.id;
|
||||
final String sourceId = state.people
|
||||
.firstWhere((PersonProfile person) => person.name == 'Ava H.')
|
||||
.id;
|
||||
|
||||
await container
|
||||
.read(localRepositoryProvider.notifier)
|
||||
.addMoment(personId: sourceId, summary: 'Source profile moment');
|
||||
await container
|
||||
.read(localRepositoryProvider.notifier)
|
||||
.addIdea(
|
||||
type: IdeaType.gift,
|
||||
title: 'Source profile idea',
|
||||
details: 'idea',
|
||||
personId: sourceId,
|
||||
);
|
||||
await container
|
||||
.read(localRepositoryProvider.notifier)
|
||||
.addReminder(
|
||||
title: 'Source profile reminder',
|
||||
cadence: ReminderCadence.weekly,
|
||||
nextAt: DateTime.now().add(const Duration(days: 2)),
|
||||
personId: sourceId,
|
||||
);
|
||||
await container
|
||||
.read(localRepositoryProvider.notifier)
|
||||
.ingestSharedMessage(
|
||||
const SharedMessageIngestInput(
|
||||
sourceApp: 'whatsapp',
|
||||
sourceDisplayName: 'Ava H.',
|
||||
sourceUserId: 'wa:ava_h',
|
||||
messageText: 'Source-linked shared message',
|
||||
),
|
||||
);
|
||||
|
||||
await container
|
||||
.read(localRepositoryProvider.notifier)
|
||||
.mergePersonProfiles(
|
||||
sourcePersonId: sourceId,
|
||||
targetPersonId: targetId,
|
||||
);
|
||||
|
||||
state = await container.read(localRepositoryProvider.future);
|
||||
expect(
|
||||
state.people.any((PersonProfile person) => person.id == sourceId),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
final PersonProfile merged = state.people.firstWhere(
|
||||
(PersonProfile person) => person.id == targetId,
|
||||
);
|
||||
expect(merged.tags, containsAll(<String>['coffee', 'books']));
|
||||
expect(merged.notes, contains('Primary notes'));
|
||||
expect(merged.notes, contains('Secondary notes'));
|
||||
expect(merged.location, 'Austin');
|
||||
|
||||
expect(
|
||||
state.moments.any(
|
||||
(RelationshipMoment moment) => moment.personId == sourceId,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
state.ideas.any((RelationshipIdea idea) => idea.personId == sourceId),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
state.reminders.any(
|
||||
(ReminderRule reminder) => reminder.personId == sourceId,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
state.sourceLinks.any(
|
||||
(SourceProfileLink link) =>
|
||||
link.sourceUserId == 'wa:ava_h' && link.profileId == targetId,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
state.sharedMessages.any(
|
||||
(SharedMessageEntry entry) =>
|
||||
entry.sourceUserId == 'wa:ava_h' && entry.profileId == targetId,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('adds, archives, edits, and deletes ideas', () async {
|
||||
final ProviderContainer container = _createContainer();
|
||||
addTearDown(container.dispose);
|
||||
|
||||
Reference in New Issue
Block a user