2024-05-31 15:10:59 -07:00
|
|
|
<?php
|
|
|
|
|
2024-06-12 04:12:15 -07:00
|
|
|
namespace Feature\Users\Ui;
|
2024-05-31 15:10:59 -07:00
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Notifications\CurrentInventory;
|
2024-06-12 04:12:15 -07:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
use Tests\TestCase;
|
2024-05-31 15:10:59 -07:00
|
|
|
|
|
|
|
class ViewUserTest extends TestCase
|
|
|
|
{
|
2024-06-12 04:03:33 -07:00
|
|
|
public function testPermissionsForUserDetailPage()
|
2024-05-31 15:10:59 -07:00
|
|
|
{
|
|
|
|
$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()->editUsers()->for($companyA)->create())
|
|
|
|
->get(route('users.show', ['user' => $user->id]))
|
|
|
|
->assertStatus(403);
|
|
|
|
|
|
|
|
$this->actingAs($superuser)
|
|
|
|
->get(route('users.show', ['user' => $user->id]))
|
|
|
|
->assertOk()
|
|
|
|
->assertStatus(200);
|
|
|
|
}
|
|
|
|
|
2024-06-12 04:03:33 -07:00
|
|
|
public function testPermissionsForPrintAllInventoryPage()
|
2024-05-31 15:10:59 -07:00
|
|
|
{
|
|
|
|
$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(403);
|
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2024-05-31 15:13:27 -07:00
|
|
|
public function testUserWithoutCompanyPermissionsCannotSendInventory()
|
2024-05-31 15:10:59 -07:00
|
|
|
{
|
2024-06-12 03:57:50 -07:00
|
|
|
|
2024-05-31 15:10:59 -07:00
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|