|
2 | 2 |
|
3 | 3 | namespace Tests\Feature\API;
|
4 | 4 |
|
5 |
| -use Illuminate\Foundation\Testing\RefreshDatabase; |
6 |
| -use Illuminate\Foundation\Testing\WithFaker; |
7 | 5 | use Tests\TestCase;
|
| 6 | +use App\Models\User; |
| 7 | +use App\Models\Product; |
| 8 | +use Illuminate\Http\Response; |
8 | 9 |
|
9 | 10 | class ProductControllerTest extends TestCase
|
10 | 11 | {
|
11 |
| - // TODO |
| 12 | + /** |
| 13 | + * @return void |
| 14 | + */ |
| 15 | + public function test_index(): void |
| 16 | + { |
| 17 | + $user = User::factory()->create(); |
| 18 | + |
| 19 | + $response = $this->actingAs($user)->get('api/product'); |
| 20 | + |
| 21 | + $response->assertStatus(Response::HTTP_OK); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * @return void |
| 26 | + */ |
| 27 | + public function test_store(): void |
| 28 | + { |
| 29 | + $user = User::factory()->create(); |
| 30 | + |
| 31 | + $response = $this->actingAs($user)->postJson('api/product', Product::factory()->raw()); |
| 32 | + |
| 33 | + $response->assertStatus(Response::HTTP_OK); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @return void |
| 38 | + */ |
| 39 | + public function test_show(): void |
| 40 | + { |
| 41 | + $user = User::factory()->create(); |
| 42 | + |
| 43 | + $product = $user->products()->create(Product::factory()->make()->toArray()); |
| 44 | + |
| 45 | + $response = $this->actingAs($user)->get('api/product/' . $product->id); |
| 46 | + |
| 47 | + $response->assertStatus(Response::HTTP_OK); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @return void |
| 52 | + */ |
| 53 | + public function test_update(): void |
| 54 | + { |
| 55 | + $user = User::factory()->create(); |
| 56 | + |
| 57 | + $product = $user->products()->create(Product::factory()->make()->toArray()); |
| 58 | + |
| 59 | + $response = $this->actingAs($user)->patchJson('api/product/' . $product->id, [ |
| 60 | + 'name' => fake()->name(), |
| 61 | + 'price' => fake()->numberBetween(1, 100), |
| 62 | + ]); |
| 63 | + |
| 64 | + $response->assertStatus(Response::HTTP_OK); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @return void |
| 69 | + */ |
| 70 | + public function test_destroy(): void |
| 71 | + { |
| 72 | + $user = User::factory()->create(); |
| 73 | + |
| 74 | + $product = $user->products()->create(Product::factory()->make()->toArray()); |
| 75 | + |
| 76 | + $response = $this->actingAs($user)->delete('api/product/' . $product->id); |
| 77 | + |
| 78 | + $response->assertStatus(Response::HTTP_OK); |
| 79 | + } |
12 | 80 | }
|
0 commit comments