From 4bad2d42cf6f28bde25b456a14f8344c2bae9635 Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 26 Mar 2025 14:15:58 -0400 Subject: [PATCH] Add tests for deleting contacts in address book functionality --- tests/Socialbox/AddressBookTest.php | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Socialbox/AddressBookTest.php b/tests/Socialbox/AddressBookTest.php index 18d18e8..1f8c606 100644 --- a/tests/Socialbox/AddressBookTest.php +++ b/tests/Socialbox/AddressBookTest.php @@ -576,4 +576,44 @@ $this->assertEquals('John', $johnResolved->getInformationField(InformationFieldName::FIRST_NAME)->getValue()); $this->assertEquals('Doe', $johnResolved->getInformationField(InformationFieldName::LAST_NAME)->getValue()); } + + /** + * @throws DatabaseOperationException + * @throws ResolutionException + * @throws CryptographyException + * @throws RpcException + */ + public function testDeleteExistingContact(): void + { + $johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnAddressBookTest'); + $this->assertTrue($johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe', PrivacyState::PUBLIC)); + $this->assertTrue($johnClient->settingsSetPassword('SecretTestingPassword123')); + $this->assertTrue($johnClient->getSessionState()->isAuthenticated()); + + $aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceAddressBookTest'); + $this->assertTrue($aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith', PrivacyState::PUBLIC)); + $this->assertTrue($aliceClient->settingsSetPassword('SecretTestingPassword123')); + $this->assertTrue($aliceClient->getSessionState()->isAuthenticated()); + + $this->assertTrue($johnClient->addressBookAddContact($aliceClient->getIdentifiedAs())); + $this->assertTrue($johnClient->addressBookContactExists($aliceClient->getIdentifiedAs())); + + $this->assertTrue($johnClient->addressBookDeleteContact($aliceClient->getIdentifiedAs())); + $this->assertFalse($johnClient->addressBookContactExists($aliceClient->getIdentifiedAs())); + } + + /** + * @throws RpcException + * @throws ResolutionException + * @throws CryptographyException + * @throws DatabaseOperationException + */ + public function testDeleteNonExistentContact(): void + { + $johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnAddressBookTest'); + $this->assertTrue($johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe', PrivacyState::PUBLIC)); + $this->assertTrue($johnClient->settingsSetPassword('SecretTestingPassword123')); + + $this->assertFalse($johnClient->addressBookDeleteContact(Helper::generateRandomPeer($johnClient->getIdentifiedAs()->getDomain()))); + } } \ No newline at end of file