diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php new file mode 100644 index 000000000..0bc0c9d2c --- /dev/null +++ b/database/factories/CategoryFactory.php @@ -0,0 +1,11 @@ +define(AvoRed\Framework\Models\Database\Category::class, function (Faker $faker) { + $name = $faker->text(5); + return [ + 'name' => $name, + 'slug' => str_slug($name), + ]; +}); diff --git a/resources/lang/en/lang.php b/resources/lang/en/lang.php index ab4fb49a6..2e3c300eb 100644 --- a/resources/lang/en/lang.php +++ b/resources/lang/en/lang.php @@ -21,13 +21,16 @@ 'token' => 'This password reset token is invalid.', 'user' => "We can't find a user with that e-mail address.", - 'admin-login-card-title' => 'AvoRed Admin Login', + 'user' => [ + 'login-card-title' => 'AvoRed Admin Login', + 'email-label' => 'Email Address', + ], + 'admin-login-forget-password-link' => 'Forgot your Password?', 'admin-login-button-title' => 'Login', 'admin-reset-button-title' => 'Send Password Reset Link', 'admin-password-label' => 'Password', 'admin-confirm-password-label' => 'Confirm Password', - 'admin-email-label' => 'Email Address', 'admin-dashboard-monthly-revenue-title' => 'Monthly Revenue', 'admin-dashboard-total-user-title' => 'Total User', diff --git a/resources/lang/en/user.php b/resources/lang/en/user.php index 8b9659a22..fb905736b 100644 --- a/resources/lang/en/user.php +++ b/resources/lang/en/user.php @@ -1,6 +1,8 @@ 'Admin User List', 'admin-user-create' => 'Create Admin User', 'admin-user-update' => 'Update Admin User', diff --git a/resources/views/user/auth/login.blade.php b/resources/views/user/auth/login.blade.php index 15994c696..7c5b81b3c 100644 --- a/resources/views/user/auth/login.blade.php +++ b/resources/views/user/auth/login.blade.php @@ -30,7 +30,7 @@
- {{ __('avored-framework::lang.admin-login-card-title') }} + {{ __('avored-framework::lang.user.login-card-title') }}
@@ -39,7 +39,7 @@ _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] + ); + } +} diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index ecfa6627c..827fc28e2 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -10,15 +10,17 @@ abstract class BaseTestCase extends OrchestraTestCase { - - + /** + * Admin User + * @var \AvoRed\Framework\Models\Database\AdminUser $user + */ protected $user; public function setUp() { parent::setUp(); $this->app['config']->set('app.key', 'base64:UTyp33UhGolgzCK5CJmT+hNHcA+dJyp3+oINtX+VoPI='); - + $this->app->singleton(EloquentFactory::class, function ($app) { $faker = $app->make(FakerGenerator::class); return EloquentFactory::construct($faker, __DIR__.('/../database/factories')); diff --git a/tests/Controller/UserGroupTest.php b/tests/Controller/UserGroupTest.php index 202bba6c3..747c05bce 100644 --- a/tests/Controller/UserGroupTest.php +++ b/tests/Controller/UserGroupTest.php @@ -11,10 +11,7 @@ */ class UserGroupTest extends BaseTestCase { - /** - * Test the Customer Group Index Route - * @test - */ + /*** @test */ public function test_user_group_index_route() { $user = $this->_getAdminUser(); @@ -22,10 +19,8 @@ public function test_user_group_index_route() $response->assertStatus(200); } - /** - * Test the Customer Group Create Route - * @test - */ + + /*** @test */ public function test_user_group_create_route() { $user = $this->_getAdminUser(); @@ -53,10 +48,8 @@ public function test_user_group_store_route() 'name' => 'test group name' ]); } - /** - * Test the Customer Group Store Route - * @test - */ + + /*** @test */ public function test_user_group_edit_route() { $userGroup = factory(UserGroup::class)->create(); @@ -68,10 +61,8 @@ public function test_user_group_edit_route() $response->assertStatus(200) ->assertSee($userGroup->name); } - /** - * Test the Customer Group Store Route - * @test - */ + + /*** @test */ public function test_user_group_update_route() { $userGroup = factory(UserGroup::class)->create(); @@ -87,10 +78,8 @@ public function test_user_group_update_route() 'name' => 'test new name' ]); } - /** - * Test the Customer Group Store Route - * @test - */ + + /*** @test */ public function test_user_group_destroy_route() { $userGroup = factory(UserGroup::class)->create();