diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-05-31 10:10:42 +0300 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-05-31 15:14:31 +0300 |
commit | c7c61e374968ffe4202ef76a40f134314453daa2 (patch) | |
tree | e06679297ea012701d8b4d2682eefba8ad14aeee /tests | |
parent | 3de5d1b00014ae124ec18548e42fcbd207c225ae (diff) |
Fix collecting addresses in the background
Nextcloud can inject the userId but only for web processes. Now that
messages are sent also in the background and not just from a web request,
the user ID can be null and make the address collection log an
exception.
Following the pattern that user ID should only be injected into a
controller, the user ID is now passed as argument of the collector,
making it suitable for background jobs too.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
4 files changed, 30 insertions, 18 deletions
diff --git a/tests/Unit/Controller/AutoCompleteControllerTest.php b/tests/Unit/Controller/AutoCompleteControllerTest.php index 6991f8edc..d2d31c4ec 100644 --- a/tests/Unit/Controller/AutoCompleteControllerTest.php +++ b/tests/Unit/Controller/AutoCompleteControllerTest.php @@ -37,8 +37,12 @@ class AutoCompleteControllerTest extends TestCase { $this->service = $this->getMockBuilder('OCA\Mail\Service\AutoCompletion\AutoCompleteService') ->disableOriginalConstructor() ->getMock(); - $this->controller = new AutoCompleteController('mail', $this->request, - $this->service); + $this->controller = new AutoCompleteController( + 'mail', + $this->request, + $this->service, + 'testuser' + ); } public function testAutoComplete() { @@ -51,8 +55,11 @@ class AutoCompleteControllerTest extends TestCase { $this->service->expects($this->once()) ->method('findMatches') - ->with($this->equalTo($term)) - ->will($this->returnValue($result)); + ->with( + 'testuser', + $this->equalTo($term) + ) + ->willReturn($result); $response = $this->controller->index($term); diff --git a/tests/Unit/Listener/AddressCollectionListenerTest.php b/tests/Unit/Listener/AddressCollectionListenerTest.php index 3b2e8539d..cf9d46fd5 100644 --- a/tests/Unit/Listener/AddressCollectionListenerTest.php +++ b/tests/Unit/Listener/AddressCollectionListenerTest.php @@ -134,11 +134,14 @@ class AddressCollectionListenerTest extends TestCase { ->willReturn(new AddressList([Address::fromRaw('bcc', 'bcc@email')])); $this->addressCollector->expects($this->once()) ->method('addAddresses') - ->with($this->equalTo(new AddressList([ - Address::fromRaw('to', 'to@email'), - Address::fromRaw('cc', 'cc@email'), - Address::fromRaw('bcc', 'bcc@email'), - ]))); + ->with( + 'test', + $this->equalTo(new AddressList([ + Address::fromRaw('to', 'to@email'), + Address::fromRaw('cc', 'cc@email'), + Address::fromRaw('bcc', 'bcc@email'), + ])) + ); $this->logger->expects($this->never())->method($this->anything()); $this->listener->handle($event); diff --git a/tests/Unit/Service/Autocompletion/AddressCollectorTest.php b/tests/Unit/Service/Autocompletion/AddressCollectorTest.php index 3b4c8b317..033cab0fd 100644 --- a/tests/Unit/Service/Autocompletion/AddressCollectorTest.php +++ b/tests/Unit/Service/Autocompletion/AddressCollectorTest.php @@ -44,7 +44,6 @@ class AddressCollectorTest extends TestCase { $this->collector = new AddressCollector( $this->mapper, - $this->userId, $this->logger ); } @@ -81,7 +80,7 @@ class AddressCollectorTest extends TestCase { [$address2] ); - $this->collector->addAddresses($addressList); + $this->collector->addAddresses($this->userId, $addressList); } public function testAddDuplicateAddresses() { @@ -97,7 +96,7 @@ class AddressCollectorTest extends TestCase { $this->mapper->expects($this->never()) ->method('insert'); - $this->collector->addAddresses($addressList); + $this->collector->addAddresses($this->userId, $addressList); } public function testSearchAddress() { @@ -109,7 +108,7 @@ class AddressCollectorTest extends TestCase { ->with($this->userId, $term) ->will($this->returnValue($mapperResult)); - $result = $this->collector->searchAddress($term); + $result = $this->collector->searchAddress($this->userId, $term); $this->assertequals($mapperResult, $result); } diff --git a/tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php b/tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php index dd431a295..054a807cd 100644 --- a/tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php +++ b/tests/Unit/Service/Autocompletion/AutoCompleteServiceTest.php @@ -70,17 +70,20 @@ class AutoCompleteServiceTest extends TestCase { $this->contactsIntegration->expects($this->once()) ->method('getMatchingRecipient') ->with($term) - ->will($this->returnValue($contactsResult)); + ->willReturn($contactsResult); $this->groupsIntegration->expects($this->once()) ->method('getMatchingGroups') ->with($term) - ->will($this->returnValue($groupsResult)); + ->willReturn($groupsResult); $this->addressCollector->expects($this->once()) ->method('searchAddress') - ->with($term) - ->will($this->returnValue($collectedResult)); + ->with( + 'testuser', + $term + ) + ->willReturn($collectedResult); - $response = $this->service->findMatches($term); + $response = $this->service->findMatches('testuser', $term); $expected = [ ['id' => 12, 'label' => '"john doe" <john@doe.cz>', 'email' => 'john@doe.cz'], |