Mohammad Khazaee
2 years ago
10 changed files with 231 additions and 12 deletions
-
1app/Console/Commands/TestGenerator.php
-
9app/Http/Controllers/CollectionController.php
-
2app/Http/Kernel.php
-
2app/Models/Collection.php
-
42database/factories/CollectionFactory.php
-
2routes/api.php
-
56tests/Feature/Collection/CollectionDeleteTest.php
-
34tests/Feature/Collection/CollectionShowTest.php
-
40tests/Feature/Collection/CollectionStoreTest.php
-
55tests/Feature/Collection/CollectionUpdateTest.php
@ -0,0 +1,56 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Collection; |
||||
|
|
||||
|
use App\Models\Collection; |
||||
|
use Tests\Bootstrap; |
||||
|
|
||||
|
class CollectionDeleteTest extends Bootstrap |
||||
|
{ |
||||
|
public function test_collection_delete_success() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.delete']) |
||||
|
->loginAs(['collections.delete']) |
||||
|
->deleteJson(route("api.collections.destroy", $collection = $this->one(Collection::class))) |
||||
|
->assertOk(); |
||||
|
|
||||
|
$this->loginAsAdmin() |
||||
|
->getJson(route("api.collections.show", $collection)) |
||||
|
->assertNotFound(); |
||||
|
} |
||||
|
|
||||
|
public function test_collection_restore_success() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.restore']) |
||||
|
->loginAsUser(['collections.restore']) |
||||
|
->deleteJson(route("api.collections.destroy", $collection = $this->trashed(Collection::class))) |
||||
|
->assertOk(); |
||||
|
|
||||
|
$this->loginAsAdmin() |
||||
|
->getJson(route("api.collections.show", $collection)) |
||||
|
->assertOk(); |
||||
|
} |
||||
|
|
||||
|
public function test_collection_delete_forbidden() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.delete']) |
||||
|
->loginAs(['wrong.permission']) |
||||
|
->deleteJson(route("api.collections.destroy", $collection = $this->one(Collection::class))) |
||||
|
->assertForbidden(); |
||||
|
} |
||||
|
|
||||
|
public function test_collection_restore_forbidden() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.restore']) |
||||
|
->loginAs(['wrong.permission']) |
||||
|
->deleteJson(route("api.collections.destroy", $collection = $this->trashed(Collection::class))) |
||||
|
->assertForbidden(); |
||||
|
} |
||||
|
|
||||
|
public function test_collection_delete_notFound() |
||||
|
{ |
||||
|
$this->loginAsAdmin() |
||||
|
->deleteJson(route("api.collections.destroy", 0)) |
||||
|
->assertNotFound(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,34 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Collection; |
||||
|
|
||||
|
use App\Models\Collection; |
||||
|
use Tests\Bootstrap; |
||||
|
use App\Models\User; |
||||
|
|
||||
|
class CollectionShowTest extends Bootstrap |
||||
|
{ |
||||
|
public function test_collection_show_success() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.show']) |
||||
|
->loginAs(['collections.show']) |
||||
|
->getJson(route("api.collections.show", $collection = $this->one(Collection::class))) |
||||
|
->assertOk(); |
||||
|
} |
||||
|
|
||||
|
public function test_collection_show_not_found() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.show']) |
||||
|
->loginAs(['collections.show']) |
||||
|
->getJson(route("api.collections.show", 0)) |
||||
|
->assertNotFound(); |
||||
|
} |
||||
|
|
||||
|
public function test_collection_show_forbidden() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.show']) |
||||
|
->loginAs(['wrong.permission']) |
||||
|
->getJson(route("api.collections.show", $collection = $this->one(Collection::class)), []) |
||||
|
->assertForbidden(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Collection; |
||||
|
|
||||
|
use App\Models\Collection; |
||||
|
use App\Documents\UserDocument; |
||||
|
use Tests\Bootstrap; |
||||
|
use Illuminate\Support\Arr; |
||||
|
|
||||
|
class CollectionStoreTest extends Bootstrap |
||||
|
{ |
||||
|
public function test_collection_store_success() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.store']) |
||||
|
->loginAs(['collections.store']) |
||||
|
->postJson(route('api.collections.store'), $collection = $this->make(Collection::class)) |
||||
|
->assertCreated(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @testWith |
||||
|
* ["name:gt"] |
||||
|
*/ |
||||
|
public function test_collection_store_unprocessable($field) |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.store']) |
||||
|
->loginAsAdmin() |
||||
|
->postJson(route("api.collections.store"), $collection = $this->make(collection::class, smash: $field, withDependency: true)) |
||||
|
->assertUnprocessable(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function test_collection_store_forbidden() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.store']) |
||||
|
->loginAs(['wrong.permission']) |
||||
|
->postJson(route("api.collections.store"), []) |
||||
|
->assertForbidden(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Collection; |
||||
|
|
||||
|
use App\Models\Collection; |
||||
|
use Tests\Bootstrap; |
||||
|
use App\Models\User; |
||||
|
use Illuminate\Support\Arr; |
||||
|
|
||||
|
|
||||
|
class CollectionUpdateTest extends Bootstrap |
||||
|
{ |
||||
|
public function test_collection_update_success() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.update']) |
||||
|
->loginAs(['collections.update']) |
||||
|
->putJson( |
||||
|
route("api.collections.update", $collection = $this->one(Collection::class)), |
||||
|
$update = $this->make(Collection::class, withDependency: true) |
||||
|
) |
||||
|
->assertOk(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @testWith |
||||
|
* ["name:gt"] |
||||
|
*/ |
||||
|
public function test_collection_update_unprocessable($field) |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.update']) |
||||
|
->loginAs(['collections.update'])->putJson( |
||||
|
route("api.collections.update", $collection = $this->one(Collection::class)), |
||||
|
$update = $this->make(collection::class, smash: $field, withDependency: true) |
||||
|
) |
||||
|
->assertUnprocessable(); |
||||
|
} |
||||
|
|
||||
|
public function test_collection_update_forbidden() |
||||
|
{ |
||||
|
$this->modelWithPolicy('collections', ['permission:collections.update']) |
||||
|
->loginAs(['wrong.permission']) |
||||
|
->putJson( |
||||
|
route("api.collections.update", $collection = $this->one(Collection::class)), |
||||
|
[] |
||||
|
) |
||||
|
->assertForbidden(); |
||||
|
} |
||||
|
|
||||
|
public function test_collection_update_not_found() |
||||
|
{ |
||||
|
$this->loginAsUser(['collections.update']) |
||||
|
->putJson(route("api.collections.update", 0), []) |
||||
|
->assertNotFound(); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue