Skip to content

Commit

Permalink
added more unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Nov 27, 2018
1 parent 2379491 commit 8a0d645
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 28 deletions.
11 changes: 11 additions & 0 deletions database/factories/CategoryFactory.php
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),
];
});
7 changes: 5 additions & 2 deletions resources/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/user.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

return [


'admin-user-list' => 'Admin User List',
'admin-user-create' => 'Create Admin User',
'admin-user-update' => 'Update Admin User',
Expand Down
4 changes: 2 additions & 2 deletions resources/views/user/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="card">

<div class="card-header bg-primary text-white">
{{ __('avored-framework::lang.admin-login-card-title') }}
{{ __('avored-framework::lang.user.login-card-title') }}
</div>
<div class="card-body" >

Expand All @@ -39,7 +39,7 @@

<avored-form-input
field-name="email"
label="{{ __('avored-framework::lang.admin-email-label') }}"
label="{{ __('avored-framework::lang.user.email-label') }}"
error-text="{!! $errors->first('email') !!}"
v-on:change="changeModelValue"
autofocus="autofocus"
Expand Down
1 change: 0 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Route::get('v1/category/{category}', 'CategoryController@show');
Route::put('v1/category/{category}', 'CategoryController@update');
Route::delete('v1/category/{category}', 'CategoryController@destroy');


Route::get('v1/property', 'PropertyController@index');
Route::post('v1/property', 'PropertyController@store');
Expand Down
77 changes: 77 additions & 0 deletions tests/Api/CategoryTest.php
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]
);
}
}
8 changes: 5 additions & 3 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
29 changes: 9 additions & 20 deletions tests/Controller/UserGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@
*/
class UserGroupTest extends BaseTestCase
{
/**
* Test the Customer Group Index Route
* @test
*/
/*** @test */
public function test_user_group_index_route()
{
$user = $this->_getAdminUser();
$response = $this->actingAs($user, 'admin')->get(route('admin.user-group.index'));

$response->assertStatus(200);
}
/**
* Test the Customer Group Create Route
* @test
*/

/*** @test */
public function test_user_group_create_route()
{
$user = $this->_getAdminUser();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 8a0d645

Please sign in to comment.