From 99dece2437d35e9df12c52445b2d5eaba9a7588b Mon Sep 17 00:00:00 2001 From: Lukas Grossberger Date: Sat, 21 Sep 2024 20:44:29 +0200 Subject: [PATCH] fix tests --- lib/ui/contact_details/page.dart | 9 ++++---- test/mocked_providers.dart | 5 +---- test/ui/receive_request_test.dart | 35 +++++++++++++++++-------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/ui/contact_details/page.dart b/lib/ui/contact_details/page.dart index cc4963a..f9ee09a 100644 --- a/lib/ui/contact_details/page.dart +++ b/lib/ui/contact_details/page.dart @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MPL-2.0 import 'dart:convert'; +import 'dart:math'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter/foundation.dart'; @@ -137,10 +138,10 @@ class ContactPage extends StatelessWidget { 'DHT Rcv Key: ${contact.dhtSettingsForReceiving!.key.substring(5, 25)}...'), if (contact.dhtSettingsForReceiving?.psk != null) Text( - 'DHT Rcv Sec: ${contact.dhtSettingsForReceiving!.psk!.substring(0, 20)}...'), + 'DHT Rcv Sec: ${contact.dhtSettingsForReceiving!.psk!.substring(0, min(20, contact.dhtSettingsForReceiving!.psk!.length))}...'), if (contact.dhtSettingsForReceiving?.writer != null) Text( - 'DHT Rcv Wrt: ${contact.dhtSettingsForReceiving!.writer!.substring(0, 20)}...'), + 'DHT Rcv Wrt: ${contact.dhtSettingsForReceiving!.writer!.substring(0, min(20, contact.dhtSettingsForReceiving!.writer!.length))}...'), if (contact.dhtSettingsForSharing?.key != null) const Padding( padding: EdgeInsets.only(left: 16, right: 16), @@ -150,10 +151,10 @@ class ContactPage extends StatelessWidget { 'DHT Shr Key: ${contact.dhtSettingsForSharing!.key.substring(5, 25)}...'), if (contact.dhtSettingsForSharing?.psk != null) Text( - 'DHT Shr Sec: ${contact.dhtSettingsForSharing!.psk!.substring(0, 20)}...'), + 'DHT Shr Sec: ${contact.dhtSettingsForSharing!.psk!.substring(0, min(20, contact.dhtSettingsForSharing!.psk!.length))}...'), if (contact.dhtSettingsForSharing?.writer != null) Text( - 'DHT Shr Wrt: ${contact.dhtSettingsForSharing!.writer!.substring(0, 20)}...'), + 'DHT Shr Wrt: ${contact.dhtSettingsForSharing!.writer!.substring(0, min(20, contact.dhtSettingsForSharing!.writer!.length))}...'), const SizedBox(height: 16), ]), diff --git a/test/mocked_providers.dart b/test/mocked_providers.dart index 38d9c78..a286f1e 100644 --- a/test/mocked_providers.dart +++ b/test/mocked_providers.dart @@ -7,15 +7,12 @@ import 'dart:convert'; import 'package:coagulate/data/models/coag_contact.dart'; import 'package:coagulate/data/models/contact_update.dart'; import 'package:coagulate/data/models/profile_sharing_settings.dart'; -import 'package:coagulate/data/providers/distributed_storage/base.dart'; import 'package:coagulate/data/providers/distributed_storage/dht.dart'; import 'package:coagulate/data/providers/persistent_storage/base.dart'; import 'package:coagulate/data/providers/system_contacts/base.dart'; import 'package:coagulate/data/providers/system_contacts/system_contacts.dart'; -import 'package:coagulate/data/repositories/contacts.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter_contacts/flutter_contacts.dart'; -import 'package:uuid/v4.dart'; class DummyPersistentStorage extends PersistentStorage { DummyPersistentStorage(this.contacts, {this.profileContactId}); @@ -127,7 +124,7 @@ class DummyDistributedStorage extends VeilidDhtStorage { @override Future<(String, String)> createDHTRecord() async { log.add('createDHTRecord'); - return ('key', 'writer'); + return ('VLD0:DUMMYwPaM1X1-d45IYDGLAAKQRpW2bf8cNKCIPNuW0M', 'writer'); } @override diff --git a/test/ui/receive_request_test.dart b/test/ui/receive_request_test.dart index 6c55fa7..34e1311 100644 --- a/test/ui/receive_request_test.dart +++ b/test/ui/receive_request_test.dart @@ -225,10 +225,14 @@ void main() { .dht; expect(dht.length, 2); // The requested sharing key and a key auto generated for receiving - expect(dht.keys.toSet(), {'requestedSharingKey', 'key'}); + expect(dht.keys.toSet(), { + 'requestedSharingKey', + 'VLD0:DUMMYwPaM1X1-d45IYDGLAAKQRpW2bf8cNKCIPNuW0M' + }); expect(c.state.profile?.coagContactId, '1'); - expect(c.state.profile?.dhtSettingsForReceiving?.key, 'key'); + expect(c.state.profile?.dhtSettingsForReceiving?.key, + 'VLD0:DUMMYwPaM1X1-d45IYDGLAAKQRpW2bf8cNKCIPNuW0M'); expect(c.state.profile?.dhtSettingsForSharing?.key, 'requestedSharingKey'); expect( @@ -269,21 +273,20 @@ void main() { act: (c) async => c.contactsRepository .initialize() .then((_) => c.linkExistingContactSharing('1')), - // Expect that contact to contain the dht settings for receiving more - // updates as well as the details from the DHT - expect: () => [ - ReceiveRequestState(ReceiveRequestStatus.success, - profile: CoagContact( - coagContactId: '1', - dhtSettingsForReceiving: const ContactDHTSettings( - key: 'sharingOfferKey', psk: 'psk'), - details: ContactDetails( - displayName: 'From DHT', - name: Name(first: 'From', last: 'DHT')))) - ], - // Verify that this is also reflected in the repository with still only - // one contact verify: (c) { + // Verify that contact to contain the dht settings for receiving more + // updates as well as the details from the DHT + expect(c.state.status, ReceiveRequestStatus.success); + expect(c.state.profile?.coagContactId, '1'); + expect(c.state.profile?.dhtSettingsForReceiving, + const ContactDHTSettings(key: 'sharingOfferKey', psk: 'psk')); + expect( + c.state.profile?.details, + ContactDetails( + displayName: 'From DHT', + name: Name(first: 'From', last: 'DHT'))); + // Verify that this is also reflected in the repository with still only + // one contact expect( (c.contactsRepository.distributedStorage as DummyDistributedStorage)