-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
4bd6c21
commit d763feb
Showing
4 changed files
with
215 additions
and
1 deletion.
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
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,59 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Consumables\Ui; | ||
|
||
use App\Models\Category; | ||
use App\Models\Company; | ||
use App\Models\Location; | ||
use App\Models\Manufacturer; | ||
use App\Models\Supplier; | ||
use App\Models\User; | ||
use Tests\Concerns\TestsPermissionsRequirement; | ||
use Tests\TestCase; | ||
|
||
class CreateConsumableTest extends TestCase implements TestsPermissionsRequirement | ||
{ | ||
public function testRequiresPermission() | ||
{ | ||
$this->actingAs(User::factory()->create()) | ||
->get(route('consumables.create')) | ||
->assertForbidden(); | ||
} | ||
|
||
public function testCanRenderCreateConsumablePage() | ||
{ | ||
$this->actingAs(User::factory()->createConsumables()->create()) | ||
->get(route('consumables.create')) | ||
->assertOk() | ||
->assertViewIs('consumables.edit'); | ||
} | ||
|
||
public function testCanCreateConsumable() | ||
{ | ||
$data = [ | ||
'company_id' => Company::factory()->create()->id, | ||
'name' => 'My Consumable', | ||
'category_id' => Category::factory()->consumableInkCategory()->create()->id, | ||
'supplier_id' => Supplier::factory()->create()->id, | ||
'manufacturer_id' => Manufacturer::factory()->create()->id, | ||
'location_id' => Location::factory()->create()->id, | ||
'model_number' => '1234', | ||
'item_no' => '5678', | ||
'order_number' => '908', | ||
'purchase_date' => '2024-12-05', | ||
'purchase_cost' => '89.45', | ||
'qty' => '10', | ||
'min_amt' => '1', | ||
'notes' => 'Some Notes', | ||
]; | ||
|
||
$this->actingAs(User::factory()->createConsumables()->create()) | ||
->post(route('consumables.store'), $data + [ | ||
'redirect_option' => 'index', | ||
'category_type' => 'consumable', | ||
]) | ||
->assertRedirect(route('consumables.index')); | ||
|
||
$this->assertDatabaseHas('consumables', $data); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Consumables\Ui; | ||
|
||
use App\Models\Company; | ||
use App\Models\Consumable; | ||
use App\Models\User; | ||
use Tests\TestCase; | ||
|
||
class DeleteConsumableTest extends TestCase | ||
{ | ||
public function testRequiresPermissionToDeleteConsumable() | ||
{ | ||
$this->actingAs(User::factory()->create()) | ||
->delete(route('consumables.destroy', Consumable::factory()->create()->id)) | ||
->assertForbidden(); | ||
} | ||
|
||
public function testCannotDeleteConsumableFromAnotherCompany() | ||
{ | ||
$this->settings->enableMultipleFullCompanySupport(); | ||
|
||
[$companyA, $companyB] = Company::factory()->count(2)->create(); | ||
|
||
$consumableForCompanyA = Consumable::factory()->for($companyA)->create(); | ||
$userForCompanyB = User::factory()->deleteConsumables()->for($companyB)->create(); | ||
|
||
$this->actingAs($userForCompanyB) | ||
->delete(route('consumables.destroy', $consumableForCompanyA->id)) | ||
->assertRedirect(route('consumables.index')); | ||
|
||
$this->assertNotSoftDeleted($consumableForCompanyA); | ||
} | ||
|
||
public function testCanDeleteConsumable() | ||
{ | ||
$consumable = Consumable::factory()->create(); | ||
|
||
$this->actingAs(User::factory()->deleteConsumables()->create()) | ||
->delete(route('consumables.destroy', $consumable->id)) | ||
->assertRedirect(route('consumables.index')); | ||
|
||
$this->assertSoftDeleted($consumable); | ||
} | ||
} |
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,110 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Consumables\Ui; | ||
|
||
use App\Models\Category; | ||
use App\Models\Company; | ||
use App\Models\Consumable; | ||
use App\Models\Location; | ||
use App\Models\Manufacturer; | ||
use App\Models\Supplier; | ||
use App\Models\User; | ||
use Tests\TestCase; | ||
|
||
class UpdateConsumableTest extends TestCase | ||
{ | ||
public function testRequiresPermissionToSeeEditConsumablePage() | ||
{ | ||
$this->actingAs(User::factory()->create()) | ||
->get(route('consumables.edit', Consumable::factory()->create())) | ||
->assertForbidden(); | ||
} | ||
|
||
public function testDoesNotShowEditConsumablePageFromAnotherCompany() | ||
{ | ||
$this->settings->enableMultipleFullCompanySupport(); | ||
|
||
[$companyA, $companyB] = Company::factory()->count(2)->create(); | ||
$consumableForCompanyA = Consumable::factory()->for($companyA)->create(); | ||
$userForCompanyB = User::factory()->editConsumables()->for($companyB)->create(); | ||
|
||
$this->actingAs($userForCompanyB) | ||
->get(route('consumables.edit', $consumableForCompanyA->id)) | ||
->assertRedirect(route('consumables.index')); | ||
} | ||
|
||
public function testEditConsumablePageRenders() | ||
{ | ||
$this->actingAs(User::factory()->editConsumables()->create()) | ||
->get(route('consumables.edit', Consumable::factory()->create())) | ||
->assertOk() | ||
->assertViewIs('consumables.edit'); | ||
} | ||
|
||
public function testCannotUpdateConsumableBelongingToAnotherCompany() | ||
{ | ||
$this->settings->enableMultipleFullCompanySupport(); | ||
|
||
[$companyA, $companyB] = Company::factory()->count(2)->create(); | ||
|
||
$consumableForCompanyA = Consumable::factory()->for($companyA)->create(); | ||
$userForCompanyB = User::factory()->editConsumables()->for($companyB)->create(); | ||
|
||
$this->actingAs($userForCompanyB) | ||
->put(route('consumables.update', $consumableForCompanyA->id), [ | ||
// | ||
]) | ||
->assertForbidden(); | ||
} | ||
|
||
public function testCannotSetQuantityToAmountLowerThanWhatIsCheckedOut() | ||
{ | ||
$user = User::factory()->createConsumables()->editConsumables()->create(); | ||
$consumable = Consumable::factory()->create(['qty' => 2]); | ||
|
||
$consumable->users()->attach($consumable->id, ['consumable_id' => $consumable->id, 'assigned_to' => $user->id]); | ||
$consumable->users()->attach($consumable->id, ['consumable_id' => $consumable->id, 'assigned_to' => $user->id]); | ||
|
||
$this->assertEquals(2, $consumable->numCheckedOut()); | ||
|
||
$this->actingAs($user) | ||
->put(route('consumables.update', $consumable->id), [ | ||
'qty' => 1, | ||
'redirect_option' => 'index', | ||
'category_type' => 'consumable', | ||
]) | ||
->assertSessionHasErrors('qty'); | ||
|
||
} | ||
|
||
public function testCanUpdateConsumable() | ||
{ | ||
$consumable = Consumable::factory()->create(); | ||
|
||
$data = [ | ||
'company_id' => Company::factory()->create()->id, | ||
'name' => 'My Consumable', | ||
'category_id' => Category::factory()->consumableInkCategory()->create()->id, | ||
'supplier_id' => Supplier::factory()->create()->id, | ||
'manufacturer_id' => Manufacturer::factory()->create()->id, | ||
'location_id' => Location::factory()->create()->id, | ||
'model_number' => '8765', | ||
'item_no' => '5678', | ||
'order_number' => '908', | ||
'purchase_date' => '2024-12-05', | ||
'purchase_cost' => '89.45', | ||
'qty' => '9', | ||
'min_amt' => '7', | ||
'notes' => 'Some Notes', | ||
]; | ||
|
||
$this->actingAs(User::factory()->createConsumables()->editConsumables()->create()) | ||
->put(route('consumables.update', $consumable->id), $data + [ | ||
'redirect_option' => 'index', | ||
'category_type' => 'consumable', | ||
]) | ||
->assertRedirect(route('consumables.index')); | ||
|
||
$this->assertDatabaseHas('consumables', $data); | ||
} | ||
} |