-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f31807
commit 9060a44
Showing
5 changed files
with
155 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
tests/Unit/Domains/Contact/ManageAvatar/Services/SuggestAvatarTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Domains\Contact\ManageAvatar\Services; | ||
|
||
use App\Domains\Contact\ManageAvatar\Services\SuggestAvatar; | ||
use App\Models\Contact; | ||
use App\Models\Vault; | ||
use Exception; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Http; | ||
use Tests\TestCase; | ||
|
||
class SuggestAvatarTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
private array $suggestions = [ | ||
'https://encrypted-tbn0.gstatic.com/images?q=tbn:A1nnWw7Tai5mXqXIS_NN3jA0&s', | ||
'https://encrypted-tbn0.gstatic.com/images?q=tbn:A2nnWw7Tai5mXqXIS_NN3jA0&s', | ||
'https://www.google.com/logos/doodles/2023/seasonal-holidays-2023-6753651837110165.2-s.png', | ||
]; | ||
|
||
/** | ||
* @test | ||
* | ||
* @group suggest-avatar | ||
* @group it_suggests_list_based_on_contact_name | ||
* | ||
* @throws Exception | ||
*/ | ||
public function it_suggests_list_based_on_contact_name(): void | ||
{ | ||
$this->fakeHttpResponse(); | ||
$request = $this->requestParams(); | ||
|
||
$suggestAvatar = new SuggestAvatar(); | ||
$suggestions = $suggestAvatar->execute($request); | ||
|
||
$this->assertCount(2, $suggestions); | ||
$this->assertEquals( | ||
$suggestions, | ||
array_slice($this->suggestions, 0, 2) | ||
); | ||
|
||
$contact = Contact::find($request['contact_id']); | ||
|
||
$this->assertSame($suggestAvatar->getSearchTerm(), $contact->name); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @group suggest-avatar | ||
* @group it_suggests_list_based_on_search_term | ||
* | ||
* @throws Exception | ||
*/ | ||
public function it_suggests_list_based_on_search_term(): void | ||
{ | ||
$this->fakeHttpResponse(); | ||
$request = $this->requestParams(); | ||
$request['search_term'] = 'John Doe'; | ||
|
||
$suggestAvatar = new SuggestAvatar(); | ||
$suggestions = $suggestAvatar->execute($request); | ||
|
||
$this->assertCount(2, $suggestions); | ||
$this->assertEquals( | ||
$suggestions, | ||
array_slice($this->suggestions, 0, 2) | ||
); | ||
|
||
$this->assertSame($suggestAvatar->getSearchTerm(), $request['search_term']); | ||
} | ||
|
||
private function requestParams(): array | ||
{ | ||
$author = $this->createUser(); | ||
$vault = $this->createVault($author->account); | ||
$vault = $this->setPermissionInVault($author, Vault::PERMISSION_EDIT, $vault); | ||
$contact = Contact::factory()->create(['vault_id' => $vault->id]); | ||
|
||
return [ | ||
'account_id' => $author->account->id, | ||
'vault_id' => $vault->id, | ||
'author_id' => $author->id, | ||
'contact_id' => $contact->id, | ||
]; | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
private function fakeHttpResponse(): void | ||
{ | ||
Http::fake(function () { | ||
return Http::response(' | ||
<html lang="en" dir="ltr" itemscope itemtype="http://schema.org/SearchResultsPage"> | ||
<body> | ||
<img src="'.$this->suggestions[0].'" alt=""> | ||
<img src="'.$this->suggestions[1].'" alt=""> | ||
<img src="'.$this->suggestions[2].'" alt=""> | ||
</body> | ||
</html>'); | ||
}); | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
tests/Unit/Domains/Contact/ManageContact/Services/SuggestAvatarTest.php
This file was deleted.
Oops, something went wrong.