|
14 | 14 | Notification::fake();
|
15 | 15 | });
|
16 | 16 |
|
17 |
| -it('return redirect to unauthenticated user', function (): void { |
18 |
| - Livewire::test(ThreadForm::class) |
19 |
| - ->assertStatus(302); |
20 |
| -})->group('thread'); |
21 |
| - |
22 |
| -it('render the component when authenticated user', function (): void { |
23 |
| - $this->login(); |
24 |
| - |
25 |
| - Livewire::test(ThreadForm::class) |
26 |
| - ->assertStatus(200); |
27 |
| -})->group('thread'); |
28 |
| - |
29 |
| -it('validate forms input', function (): void { |
30 |
| - $this->login(); |
31 |
| - |
32 |
| - Livewire::test(ThreadForm::class) |
33 |
| - ->fillForm([ |
34 |
| - 'title' => '', |
35 |
| - 'body' => '', |
36 |
| - 'channels' => [], |
37 |
| - ]) |
38 |
| - ->call('save') |
39 |
| - ->assertHasFormErrors([ |
40 |
| - 'title' => ['required'], |
41 |
| - 'body' => ['required'], |
42 |
| - ]); |
43 |
| -})->group('thread'); |
44 |
| - |
45 |
| -it('validate channels can extends 3 when create a thread', function (): void { |
46 |
| - $this->login(); |
47 |
| - |
48 |
| - Livewire::test(ThreadForm::class) |
49 |
| - ->fillForm([ |
50 |
| - 'title' => 'I have a question about laravel Cameroun', |
51 |
| - 'body' => 'this is my kind body', |
52 |
| - 'channels' => ['laravel', 'php', 'tailwind', 'gaming'], |
53 |
| - ]) |
54 |
| - ->call('save') |
55 |
| - ->assertHasFormErrors([ |
56 |
| - 'channels' => ['max'], |
57 |
| - ]); |
58 |
| -})->group('thread'); |
59 |
| - |
60 |
| -it('user can create a new thread', function (): void { |
61 |
| - $user = $this->login(); |
62 |
| - $channels = Channel::factory()->count(3)->create(); |
63 |
| - |
64 |
| - Livewire::test(ThreadForm::class) |
65 |
| - ->fillForm([ |
66 |
| - 'title' => 'I have a question about laravel Cameroun', |
67 |
| - 'body' => 'this is my kind body', |
68 |
| - 'channels' => $channels->pluck('id')->toArray(), |
69 |
| - ]) |
70 |
| - ->call('save') |
71 |
| - ->assertHasNoFormErrors(); |
72 |
| - |
73 |
| - $thread = Thread::query()->first(); |
74 |
| - |
75 |
| - expect($thread?->user)->toBeInstanceOf(User::class) |
76 |
| - ->and($thread?->user->is($user)) |
77 |
| - ->toBeTrue(); |
78 |
| -})->group('thread'); |
79 |
| - |
80 |
| -it('user cannot create thread with and unverified email address', function (): void { |
81 |
| - $user = $this->createUser(['email_verified_at' => null]); |
82 |
| - $channels = Channel::factory()->count(2)->create(); |
83 |
| - |
84 |
| - $this->actingAs($user); |
85 |
| - |
86 |
| - Livewire::test(ThreadForm::class) |
87 |
| - ->fillForm([ |
88 |
| - 'title' => 'I have a question about laravel Cameroun', |
89 |
| - 'body' => 'this is my kind body', |
90 |
| - 'channels' => $channels->pluck('id')->toArray(), |
91 |
| - ]) |
92 |
| - ->call('save'); |
93 |
| - |
94 |
| - expect(Thread::query()->first()) |
95 |
| - ->toBeNull(); |
96 |
| -}) |
97 |
| - ->group('thread') |
98 |
| - ->expectException(UnverifiedUserException::class); |
99 |
| - |
100 |
| -it('user cannot updated a thread that is not author', function (): void { |
101 |
| - $this->login(); |
102 |
| - |
103 |
| - $author = User::factory()->create(); |
104 |
| - $thread = Thread::factory()->create(['user_id' => $author->id]); |
105 |
| - $channels = Channel::factory()->count(3)->create(); |
106 |
| - |
107 |
| - $thread->channels()->attach($channels->modelKeys()); |
108 |
| - |
109 |
| - Livewire::test(ThreadForm::class, ['threadId' => $thread->id]) |
110 |
| - ->fillForm([ |
111 |
| - 'title' => 'Updated thread question', |
112 |
| - 'body' => 'this is my kind body updated', |
113 |
| - ]) |
114 |
| - ->call('save') |
115 |
| - ->assertStatus(403); |
| 17 | +/** |
| 18 | + * @var \Tests\TestCase $this |
| 19 | + */ |
| 20 | +describe(ThreadForm::class, function (): void { |
| 21 | + it('return redirect to unauthenticated user', function (): void { |
| 22 | + Livewire::test(ThreadForm::class) |
| 23 | + ->assertStatus(302); |
| 24 | + }); |
| 25 | + |
| 26 | + it('render the component when authenticated user', function (): void { |
| 27 | + $this->login(); |
| 28 | + |
| 29 | + Livewire::test(ThreadForm::class) |
| 30 | + ->assertSuccessful(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('validate forms input', function (): void { |
| 34 | + $this->login(); |
| 35 | + |
| 36 | + Livewire::test(ThreadForm::class) |
| 37 | + ->fillForm([ |
| 38 | + 'title' => '', |
| 39 | + 'body' => '', |
| 40 | + 'channels' => [], |
| 41 | + ]) |
| 42 | + ->call('save') |
| 43 | + ->assertHasFormErrors([ |
| 44 | + 'title' => ['required'], |
| 45 | + 'body' => ['required'], |
| 46 | + ]); |
| 47 | + }); |
| 48 | + |
| 49 | + it('validate channels can extends 3 when create a thread', function (): void { |
| 50 | + $this->login(); |
| 51 | + |
| 52 | + Livewire::test(ThreadForm::class) |
| 53 | + ->fillForm([ |
| 54 | + 'title' => 'I have a question about laravel Cameroun', |
| 55 | + 'body' => 'this is my kind body', |
| 56 | + 'channels' => ['laravel', 'php', 'tailwind', 'gaming'], |
| 57 | + ]) |
| 58 | + ->call('save') |
| 59 | + ->assertHasFormErrors([ |
| 60 | + 'channels' => ['max'], |
| 61 | + ]); |
| 62 | + }); |
| 63 | + |
| 64 | + it('user can create a new thread', function (): void { |
| 65 | + $user = $this->login(); |
| 66 | + $channels = Channel::factory()->count(3)->create(); |
| 67 | + |
| 68 | + Livewire::test(ThreadForm::class) |
| 69 | + ->fillForm([ |
| 70 | + 'title' => 'I have a question about laravel Cameroun', |
| 71 | + 'body' => 'this is my kind body', |
| 72 | + 'channels' => $channels->pluck('id')->toArray(), |
| 73 | + ]) |
| 74 | + ->call('save') |
| 75 | + ->assertHasNoFormErrors(); |
| 76 | + |
| 77 | + $thread = Thread::query()->first(); |
| 78 | + |
| 79 | + expect($thread?->user)->toBeInstanceOf(User::class) |
| 80 | + ->and($thread?->user->is($user)) |
| 81 | + ->toBeTrue(); |
| 82 | + }); |
| 83 | + |
| 84 | + it('user cannot create thread with and unverified email address', function (): void { |
| 85 | + $user = $this->createUser(['email_verified_at' => null]); |
| 86 | + $channels = Channel::factory()->count(2)->create(); |
| 87 | + |
| 88 | + $this->actingAs($user); |
| 89 | + |
| 90 | + Livewire::test(ThreadForm::class) |
| 91 | + ->fillForm([ |
| 92 | + 'title' => 'I have a question about laravel Cameroun', |
| 93 | + 'body' => 'this is my kind body', |
| 94 | + 'channels' => $channels->pluck('id')->toArray(), |
| 95 | + ]) |
| 96 | + ->call('save'); |
| 97 | + |
| 98 | + expect(Thread::query()->first()) |
| 99 | + ->toBeNull(); |
| 100 | + })->expectException(UnverifiedUserException::class); |
| 101 | + |
| 102 | + it('user cannot updated a thread that is not author', function (): void { |
| 103 | + $this->login(); |
| 104 | + |
| 105 | + $author = User::factory()->create(); |
| 106 | + $thread = Thread::factory()->create(['user_id' => $author->id]); |
| 107 | + $channels = Channel::factory()->count(3)->create(); |
| 108 | + |
| 109 | + $thread->channels()->attach($channels->modelKeys()); |
| 110 | + |
| 111 | + Livewire::test(ThreadForm::class, ['threadId' => $thread->id]) |
| 112 | + ->fillForm([ |
| 113 | + 'title' => 'Updated thread question', |
| 114 | + 'body' => 'this is my kind body updated', |
| 115 | + ]) |
| 116 | + ->call('save') |
| 117 | + ->assertStatus(403); |
| 118 | + }); |
116 | 119 | })->group('thread');
|
0 commit comments