Skip to content

Commit 28379e7

Browse files
committed
Added tests for API Controllers
1 parent b1e9fc9 commit 28379e7

6 files changed

+111
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Tests\Feature\API;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use Tests\TestCase;
8+
9+
class CategoryControllerTest extends TestCase
10+
{
11+
// TODO
12+
}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Tests\Feature\Api;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use Tests\TestCase;
8+
use Symfony\Component\HttpFoundation\Response;
9+
use App\Models\User;
10+
11+
class LoginControllerTest extends TestCase
12+
{
13+
use RefreshDatabase;
14+
15+
use WithFaker;
16+
17+
/**
18+
* @return void
19+
*/
20+
public function test_login(): void
21+
{
22+
$user = User::factory()->create();
23+
24+
$response = $this->postJson('api/login', [
25+
'email' => $user->email,
26+
'password' => 'password',
27+
]);
28+
29+
$response->assertStatus(Response::HTTP_OK);
30+
}
31+
32+
/**
33+
* @return void
34+
*/
35+
public function test_logout(): void
36+
{
37+
$user = User::factory()->create();
38+
39+
$response = $this->actingAs($user)->get('api/logout');
40+
41+
$response->assertStatus(Response::HTTP_OK);
42+
}
43+
44+
/**
45+
* @return void
46+
*/
47+
public function test_details(): void
48+
{
49+
$user = User::factory()->create();
50+
51+
$response = $this->actingAs($user)->get('api/user');
52+
53+
$response->assertStatus(Response::HTTP_OK);
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Tests\Feature\API;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use Tests\TestCase;
8+
9+
class ProductControllerTest extends TestCase
10+
{
11+
// TODO
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Tests\Feature\Api;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use Tests\TestCase;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
class RegisterControllerTest extends TestCase
11+
{
12+
use RefreshDatabase;
13+
14+
use WithFaker;
15+
16+
/**
17+
* @return void
18+
*/
19+
public function test_index(): void
20+
{
21+
$password = $this->faker()->password();
22+
23+
$response = $this->postJson('api/register', [
24+
'name' => $this->faker->name(),
25+
'email' => $this->faker->email(),
26+
'password' => $password,
27+
'confirm_password' => $password,
28+
]);
29+
30+
$response->assertStatus(Response::HTTP_OK);
31+
}
32+
}

tests/Feature/ExampleTest.php

-19
This file was deleted.

tests/Unit/ExampleTest.php

-16
This file was deleted.

0 commit comments

Comments
 (0)