-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ModuleNotesViewHelperTest.php
94 lines (80 loc) · 2.79 KB
/
ModuleNotesViewHelperTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Tests\Unit\Domains\Contact\ManageNotes\Web\ViewHelpers;
use App\Domains\Contact\ManageNotes\Web\ViewHelpers\ModuleNotesViewHelper;
use App\Models\Contact;
use App\Models\Emotion;
use App\Models\Note;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use function env;
class ModuleNotesViewHelperTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_gets_the_data_needed_for_the_view(): void
{
$contact = Contact::factory()->create();
$user = User::factory()->create();
Note::factory()->create([
'contact_id' => $contact->id,
]);
$emotion = Emotion::factory()->create([
'account_id' => $contact->vault->account_id,
]);
$array = ModuleNotesViewHelper::data($contact, $user);
$this->assertEquals(
3,
count($array)
);
$this->assertArrayHasKey('notes', $array);
$this->assertArrayHasKey('emotions', $array);
$this->assertArrayHasKey('url', $array);
$this->assertEquals(
[
0 => [
'id' => $emotion->id,
'name' => $emotion->name,
'type' => $emotion->type,
],
],
$array['emotions']->toArray()
);
$this->assertEquals(
[
'store' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/notes',
'index' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/notes',
],
$array['url']
);
}
/** @test */
public function it_gets_the_data_transfer_object(): void
{
Carbon::setTestNow(Carbon::create(2018, 1, 1));
$contact = Contact::factory()->create();
$user = User::factory()->create();
$note = Note::factory()->create([
'contact_id' => $contact->id,
]);
$collection = ModuleNotesViewHelper::dto($contact, $note, $user);
$this->assertEquals(
[
'id' => $note->id,
'body' => $note->body,
'body_excerpt' => null,
'show_full_content' => false,
'title' => $note->title,
'emotion' => null,
'author' => null,
'written_at' => 'Jan 01, 2018',
'url' => [
'update' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/notes/'.$note->id,
'destroy' => env('APP_URL').'/vaults/'.$contact->vault->id.'/contacts/'.$contact->id.'/notes/'.$note->id,
],
],
$collection
);
}
}