-
Notifications
You must be signed in to change notification settings - Fork 45
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
2379491
commit 8a0d645
Showing
8 changed files
with
111 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(AvoRed\Framework\Models\Database\Category::class, function (Faker $faker) { | ||
$name = $faker->text(5); | ||
return [ | ||
'name' => $name, | ||
'slug' => str_slug($name), | ||
]; | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace AvoRed\Framework\Tests\Api; | ||
|
||
use AvoRed\Framework\Tests\BaseTestCase; | ||
use AvoRed\Framework\Models\Database\Category; | ||
|
||
class CategoryTest extends BaseTestCase | ||
{ | ||
/** @test */ | ||
public function test_category_api_list_route() | ||
{ | ||
$user = $this->_getAdminUser(); | ||
$response = $this->actingAs($user, 'api')->get('api/v1/category'); | ||
$response->assertStatus(200); | ||
} | ||
|
||
/** @test */ | ||
public function test_category_api_store_route() | ||
{ | ||
$user = $this->_getAdminUser(); | ||
$response = $this->actingAs($user, 'api') | ||
->post('api/v1/category', [ | ||
'name' => 'test name', | ||
'slug' => 'test-name' | ||
]); | ||
$response->assertStatus(201); | ||
|
||
$this->assertDatabaseHas( | ||
'categories', | ||
['name' => 'test name'] | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function test_category_api_show_route() | ||
{ | ||
$category = factory(Category::class)->create(); | ||
$user = $this->_getAdminUser(); | ||
$response = $this->actingAs($user, 'api')->get('api/v1/category/' . $category->id); | ||
$data = json_decode($response->content()); | ||
|
||
$response->assertStatus(200); | ||
$this->assertEquals($category->name ,$data->data->name); | ||
} | ||
|
||
/** @test */ | ||
public function test_category_api_update_route() | ||
{ | ||
$category = factory(Category::class)->create(); | ||
$category->name = 'new name'; | ||
$user = $this->_getAdminUser(); | ||
$response = $this->actingAs($user, 'api')->put('api/v1/category/' . $category->id, $category->toArray()); | ||
$data = json_decode($response->content()); | ||
|
||
$response->assertStatus(200); | ||
$this->assertEquals('new name', $data->data->name); | ||
$this->assertDatabaseHas( | ||
'categories', | ||
['name' => 'new name'] | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function test_category_api_delete_route() | ||
{ | ||
$category = factory(Category::class)->create(); | ||
$user = $this->_getAdminUser(); | ||
$response = $this->actingAs($user, 'api')->delete('api/v1/category/' . $category->id); | ||
|
||
$response->assertStatus(204); | ||
$this->assertDatabaseMissing( | ||
'categories', | ||
['id' => $category->id] | ||
); | ||
} | ||
} |
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