Merge pull request #16553 from marcusmoore/tests/user-show
Added tests around emailing and printing assigned assets
This commit is contained in:
commit
d44553c6dd
3 changed files with 106 additions and 67 deletions
40
tests/Feature/Users/Ui/EmailAssignedToUserTest.php
Normal file
40
tests/Feature/Users/Ui/EmailAssignedToUserTest.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Users\Ui;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Notifications\CurrentInventory;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class EmailAssignedToUserTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testUserWithoutCompanyPermissionsCannotSendInventory()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$superuser = User::factory()->superuser()->create();
|
||||||
|
$user = User::factory()->for($companyB)->create();
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->viewUsers()->for($companyA)->create())
|
||||||
|
->post(route('users.email', ['userId' => $user->id]))
|
||||||
|
->assertStatus(403);
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->viewUsers()->for($companyB)->create())
|
||||||
|
->post(route('users.email', ['userId' => $user->id]))
|
||||||
|
->assertStatus(302);
|
||||||
|
|
||||||
|
$this->actingAs($superuser)
|
||||||
|
->post(route('users.email', ['userId' => $user->id]))
|
||||||
|
->assertStatus(302);
|
||||||
|
|
||||||
|
Notification::assertSentTo(
|
||||||
|
[$user], CurrentInventory::class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
41
tests/Feature/Users/Ui/PrintUserInventoryTest.php
Normal file
41
tests/Feature/Users/Ui/PrintUserInventoryTest.php
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Users\Ui;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class PrintUserInventoryTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testPermissionRequiredToPrintUserInventory()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->create())
|
||||||
|
->get(route('users.print', User::factory()->create()))
|
||||||
|
->assertStatus(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanPrintUserInventory()
|
||||||
|
{
|
||||||
|
$actor = User::factory()->viewUsers()->create();
|
||||||
|
|
||||||
|
$this->actingAs($actor)
|
||||||
|
->get(route('users.print', User::factory()->create()))
|
||||||
|
->assertOk()
|
||||||
|
->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotPrintUserInventoryFromAnotherCompany()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$actor = User::factory()->for($companyA)->viewUsers()->create();
|
||||||
|
$user = User::factory()->for($companyB)->create();
|
||||||
|
|
||||||
|
$this->actingAs($actor)
|
||||||
|
->get(route('users.print', $user))
|
||||||
|
->assertStatus(302);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,80 +4,38 @@ namespace Tests\Feature\Users\Ui;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\CurrentInventory;
|
|
||||||
use Illuminate\Support\Facades\Notification;
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class ViewUserTest extends TestCase
|
class ViewUserTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testPermissionsForUserDetailPage()
|
public function testRequiresPermissionToViewUser()
|
||||||
{
|
{
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
$this->actingAs(User::factory()->create())
|
||||||
|
->get(route('users.show', User::factory()->create()))
|
||||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
|
||||||
|
|
||||||
$superuser = User::factory()->superuser()->create();
|
|
||||||
$user = User::factory()->for($companyB)->create();
|
|
||||||
|
|
||||||
$this->actingAs(User::factory()->editUsers()->for($companyA)->create())
|
|
||||||
->get(route('users.show', $user))
|
|
||||||
->assertStatus(302);
|
|
||||||
|
|
||||||
$this->actingAs($superuser)
|
|
||||||
->get(route('users.show', $user))
|
|
||||||
->assertOk()
|
|
||||||
->assertStatus(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPermissionsForPrintAllInventoryPage()
|
|
||||||
{
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
|
||||||
|
|
||||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
|
||||||
|
|
||||||
$superuser = User::factory()->superuser()->create();
|
|
||||||
$user = User::factory()->for($companyB)->create();
|
|
||||||
|
|
||||||
$this->actingAs(User::factory()->viewUsers()->for($companyA)->create())
|
|
||||||
->get(route('users.print', ['userId' => $user->id]))
|
|
||||||
->assertStatus(302);
|
|
||||||
|
|
||||||
$this->actingAs(User::factory()->viewUsers()->for($companyB)->create())
|
|
||||||
->get(route('users.print', ['userId' => $user->id]))
|
|
||||||
->assertStatus(200);
|
|
||||||
|
|
||||||
$this->actingAs($superuser)
|
|
||||||
->get(route('users.print', ['userId' => $user->id]))
|
|
||||||
->assertOk()
|
|
||||||
->assertStatus(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUserWithoutCompanyPermissionsCannotSendInventory()
|
|
||||||
{
|
|
||||||
|
|
||||||
Notification::fake();
|
|
||||||
|
|
||||||
$this->settings->enableMultipleFullCompanySupport();
|
|
||||||
|
|
||||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
|
||||||
|
|
||||||
$superuser = User::factory()->superuser()->create();
|
|
||||||
$user = User::factory()->for($companyB)->create();
|
|
||||||
|
|
||||||
$this->actingAs(User::factory()->viewUsers()->for($companyA)->create())
|
|
||||||
->post(route('users.email', ['userId' => $user->id]))
|
|
||||||
->assertStatus(403);
|
->assertStatus(403);
|
||||||
|
}
|
||||||
|
|
||||||
$this->actingAs(User::factory()->viewUsers()->for($companyB)->create())
|
public function testCanViewUser()
|
||||||
->post(route('users.email', ['userId' => $user->id]))
|
{
|
||||||
|
$actor = User::factory()->viewUsers()->create();
|
||||||
|
|
||||||
|
$this->actingAs($actor)
|
||||||
|
->get(route('users.show', User::factory()->create()))
|
||||||
|
->assertOk()
|
||||||
|
->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotViewUserFromAnotherCompany()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||||
|
|
||||||
|
$actor = User::factory()->for($companyA)->viewUsers()->create();
|
||||||
|
$user = User::factory()->for($companyB)->create();
|
||||||
|
|
||||||
|
$this->actingAs($actor)
|
||||||
|
->get(route('users.show', $user))
|
||||||
->assertStatus(302);
|
->assertStatus(302);
|
||||||
|
|
||||||
$this->actingAs($superuser)
|
|
||||||
->post(route('users.email', ['userId' => $user->id]))
|
|
||||||
->assertStatus(302);
|
|
||||||
|
|
||||||
Notification::assertSentTo(
|
|
||||||
[$user], CurrentInventory::class
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue