Merge pull request #14825 from marcusmoore/chore/test-organization

Re-organized test suite
This commit is contained in:
snipe 2024-06-05 09:46:08 +01:00 committed by GitHub
commit 697ac83040
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 117 additions and 131 deletions

View file

@ -1,84 +0,0 @@
<?php
namespace Tests\Feature\Api\Users;
use App\Models\Company;
use App\Models\Department;
use App\Models\Group;
use App\Models\Location;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
class UsersUpdateTest extends TestCase
{
public function testCanUpdateUserViaPatch()
{
$admin = User::factory()->superuser()->create();
$manager = User::factory()->create();
$company = Company::factory()->create();
$department = Department::factory()->create();
$location = Location::factory()->create();
[$groupA, $groupB] = Group::factory()->count(2)->create();
$user = User::factory()->create([
'activated' => false,
'remote' => false,
'vip' => false,
]);
$this->actingAsForApi($admin)
->patchJson(route('api.users.update', $user), [
'first_name' => 'Mabel',
'last_name' => 'Mora',
'username' => 'mabel',
'password' => 'super-secret',
'email' => 'mabel@onlymurderspod.com',
'permissions' => '{"a.new.permission":"1"}',
'activated' => true,
'phone' => '619-555-5555',
'jobtitle' => 'Host',
'manager_id' => $manager->id,
'employee_num' => '1111',
'notes' => 'Pretty good artist',
'company_id' => $company->id,
'department_id' => $department->id,
'location_id' => $location->id,
'remote' => true,
'groups' => $groupA->id,
'vip' => true,
'start_date' => '2021-08-01',
'end_date' => '2025-12-31',
])
->assertOk();
$user->refresh();
$this->assertEquals('Mabel', $user->first_name, 'First name was not updated');
$this->assertEquals('Mora', $user->last_name, 'Last name was not updated');
$this->assertEquals('mabel', $user->username, 'Username was not updated');
$this->assertTrue(Hash::check('super-secret', $user->password), 'Password was not updated');
$this->assertEquals('mabel@onlymurderspod.com', $user->email, 'Email was not updated');
$this->assertArrayHasKey('a.new.permission', $user->decodePermissions(), 'Permissions were not updated');
$this->assertTrue((bool)$user->activated, 'User not marked as activated');
$this->assertEquals('619-555-5555', $user->phone, 'Phone was not updated');
$this->assertEquals('Host', $user->jobtitle, 'Job title was not updated');
$this->assertTrue($user->manager->is($manager), 'Manager was not updated');
$this->assertEquals('1111', $user->employee_num, 'Employee number was not updated');
$this->assertEquals('Pretty good artist', $user->notes, 'Notes was not updated');
$this->assertTrue($user->company->is($company), 'Company was not updated');
$this->assertTrue($user->department->is($department), 'Department was not updated');
$this->assertTrue($user->location->is($location), 'Location was not updated');
$this->assertEquals(1, $user->remote, 'Remote was not updated');
$this->assertTrue($user->groups->contains($groupA), 'Groups were not updated');
$this->assertEquals(1, $user->vip, 'VIP was not updated');
$this->assertEquals('2021-08-01', $user->start_date, 'Start date was not updated');
$this->assertEquals('2025-12-31', $user->end_date, 'End date was not updated');
// `groups` can be an id or array or ids
$this->patch(route('api.users.update', $user), ['groups' => [$groupA->id, $groupB->id]]);
$user->refresh();
$this->assertTrue($user->groups->contains($groupA), 'Not part of expected group');
$this->assertTrue($user->groups->contains($groupB), 'Not part of expected group');
}
}

View file

@ -1,13 +1,14 @@
<?php
namespace Tests\Feature\Api\Assets;
namespace Tests\Feature\Assets\Api;
use App\Models\Asset;
use App\Models\Company;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
use Carbon\Carbon;
class AssetIndexTest extends TestCase
{
public function testAssetApiIndexReturnsExpectedAssets()

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Assets;
namespace Tests\Feature\Assets\Api;
use App\Models\Asset;
use App\Models\Company;

View file

@ -1,13 +1,13 @@
<?php
namespace Tests\Feature\Api\Assets;
namespace Tests\Feature\Assets\Api;
use App\Models\Asset;
use App\Models\Company;
use App\Models\User;
use Tests\TestCase;
class RequestableAssetsTest extends TestCase
class RequestableAssetTest extends TestCase
{
public function testViewingRequestableAssetsRequiresCorrectPermission()
{

View file

@ -1,8 +1,7 @@
<?php
namespace Tests\Feature\Api\Assets;
namespace Tests\Feature\Assets\Api;
use App\Helpers\Helper;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Company;
@ -13,10 +12,9 @@ use App\Models\Supplier;
use App\Models\User;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Testing\Fluent\AssertableJson;
use Illuminate\Testing\TestResponse;
use Tests\TestCase;
class AssetStoreTest extends TestCase
class StoreAssetTest extends TestCase
{
public function testRequiresPermissionToCreateAsset()
{

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Assets;
namespace Tests\Feature\Assets\Api;
use App\Models\Asset;
use App\Models\CustomField;
@ -8,7 +8,7 @@ use App\Models\User;
use Illuminate\Support\Facades\Crypt;
use Tests\TestCase;
class AssetUpdateTest extends TestCase
class UpdateAssetTest extends TestCase
{
public function testEncryptedCustomFieldCanBeUpdated()
{

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Assets;
namespace Tests\Feature\Assets\Ui;
use App\Models\Asset;
use App\Models\AssetModel;
@ -12,7 +12,7 @@ use App\Models\User;
use Illuminate\Support\Facades\Crypt;
use Tests\TestCase;
class AssetsBulkEditTest extends TestCase
class BulkEditAssetsTest extends TestCase
{
public function testUserWithPermissionsCanAccessPage()
{

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Assets;
namespace Tests\Feature\Checkins\Api;
use App\Events\CheckoutableCheckedIn;
use App\Models\Asset;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Checkins;
namespace Tests\Feature\Checkins\Ui;
use App\Events\CheckoutableCheckedIn;
use App\Models\Accessory;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Checkins;
namespace Tests\Feature\Checkins\Ui;
use App\Events\CheckoutableCheckedIn;
use App\Models\Asset;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\CheckoutAcceptances;
namespace Tests\Feature\CheckoutAcceptances\Ui;
use App\Models\Accessory;
use App\Models\CheckoutAcceptance;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Accessories;
namespace Tests\Feature\Checkouts\Api;
use App\Models\Accessory;
use App\Models\Actionlog;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Assets;
namespace Tests\Feature\Checkouts\Api;
use App\Events\CheckoutableCheckedOut;
use App\Models\Asset;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Consumables;
namespace Tests\Feature\Checkouts\Api;
use App\Models\Actionlog;
use App\Models\Consumable;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Checkouts;
namespace Tests\Feature\Checkouts\Ui;
use App\Models\Accessory;
use App\Models\Actionlog;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Checkouts;
namespace Tests\Feature\Checkouts\Ui;
use App\Events\CheckoutableCheckedOut;
use App\Models\Asset;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Checkouts;
namespace Tests\Feature\Checkouts\Ui;
use App\Models\Actionlog;
use App\Models\Consumable;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Checkouts;
namespace Tests\Feature\Checkouts\Ui;
use App\Models\Asset;
use App\Models\License;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Components;
namespace Tests\Feature\Components\Api;
use App\Models\Company;
use App\Models\Component;

View file

@ -1,13 +1,13 @@
<?php
namespace Tests\Feature\Api\Consumables;
namespace Tests\Feature\Consumables\Api;
use App\Models\Company;
use App\Models\Consumable;
use App\Models\User;
use Tests\TestCase;
class ConsumablesIndexTest extends TestCase
class ConsumableIndexTest extends TestCase
{
public function testConsumableIndexAdheresToCompanyScoping()
{

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Departments;
namespace Tests\Feature\Departments\Api;
use App\Models\Company;
use App\Models\Department;

View file

@ -1,13 +1,13 @@
<?php
namespace Tests\Feature\Api\Groups;
namespace Tests\Feature\Groups\Api;
use App\Helpers\Helper;
use App\Models\Group;
use App\Models\User;
use Tests\TestCase;
class GroupStoreTest extends TestCase
class StoreGroupTest extends TestCase
{
public function testStoringGroupRequiresSuperAdminPermission()
{

View file

@ -1,13 +1,13 @@
<?php
namespace Tests\Feature\Api\Licenses;
namespace Tests\Feature\Licenses\Api;
use App\Models\Company;
use App\Models\License;
use App\Models\User;
use Tests\TestCase;
class LicensesIndexTest extends TestCase
class LicenseIndexTest extends TestCase
{
public function testLicensesIndexAdheresToCompanyScoping()
{

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Locations;
namespace Tests\Feature\Locations\Api;
use App\Models\Location;
use App\Models\User;

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Reports;
namespace Tests\Feature\Reporting;
use App\Models\Asset;
use App\Models\Company;

View file

@ -1,15 +1,14 @@
<?php
namespace Tests\Feature\Api\Users;
namespace Tests\Feature\Users\Api;
use App\Models\Asset;
use App\Models\Company;
use App\Models\LicenseSeat;
use App\Models\Location;
use App\Models\User;
use App\Models\LicenseSeat;
use Tests\TestCase;
class DeleteUsersTest extends TestCase
class DeleteUserTest extends TestCase
{

View file

@ -1,14 +1,87 @@
<?php
namespace Tests\Feature\Api\Users;
namespace Tests\Feature\Users\Api;
use App\Models\Company;
use App\Models\Department;
use App\Models\Group;
use App\Models\Location;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
class UpdateUserApiTest extends TestCase
class UpdateUserTest extends TestCase
{
public function testCanUpdateUserViaPatch()
{
$admin = User::factory()->superuser()->create();
$manager = User::factory()->create();
$company = Company::factory()->create();
$department = Department::factory()->create();
$location = Location::factory()->create();
[$groupA, $groupB] = Group::factory()->count(2)->create();
$user = User::factory()->create([
'activated' => false,
'remote' => false,
'vip' => false,
]);
$this->actingAsForApi($admin)
->patchJson(route('api.users.update', $user), [
'first_name' => 'Mabel',
'last_name' => 'Mora',
'username' => 'mabel',
'password' => 'super-secret',
'email' => 'mabel@onlymurderspod.com',
'permissions' => '{"a.new.permission":"1"}',
'activated' => true,
'phone' => '619-555-5555',
'jobtitle' => 'Host',
'manager_id' => $manager->id,
'employee_num' => '1111',
'notes' => 'Pretty good artist',
'company_id' => $company->id,
'department_id' => $department->id,
'location_id' => $location->id,
'remote' => true,
'groups' => $groupA->id,
'vip' => true,
'start_date' => '2021-08-01',
'end_date' => '2025-12-31',
])
->assertOk();
$user->refresh();
$this->assertEquals('Mabel', $user->first_name, 'First name was not updated');
$this->assertEquals('Mora', $user->last_name, 'Last name was not updated');
$this->assertEquals('mabel', $user->username, 'Username was not updated');
$this->assertTrue(Hash::check('super-secret', $user->password), 'Password was not updated');
$this->assertEquals('mabel@onlymurderspod.com', $user->email, 'Email was not updated');
$this->assertArrayHasKey('a.new.permission', $user->decodePermissions(), 'Permissions were not updated');
$this->assertTrue((bool) $user->activated, 'User not marked as activated');
$this->assertEquals('619-555-5555', $user->phone, 'Phone was not updated');
$this->assertEquals('Host', $user->jobtitle, 'Job title was not updated');
$this->assertTrue($user->manager->is($manager), 'Manager was not updated');
$this->assertEquals('1111', $user->employee_num, 'Employee number was not updated');
$this->assertEquals('Pretty good artist', $user->notes, 'Notes was not updated');
$this->assertTrue($user->company->is($company), 'Company was not updated');
$this->assertTrue($user->department->is($department), 'Department was not updated');
$this->assertTrue($user->location->is($location), 'Location was not updated');
$this->assertEquals(1, $user->remote, 'Remote was not updated');
$this->assertTrue($user->groups->contains($groupA), 'Groups were not updated');
$this->assertEquals(1, $user->vip, 'VIP was not updated');
$this->assertEquals('2021-08-01', $user->start_date, 'Start date was not updated');
$this->assertEquals('2025-12-31', $user->end_date, 'End date was not updated');
// `groups` can be an id or array or ids
$this->patch(route('api.users.update', $user), ['groups' => [$groupA->id, $groupB->id]]);
$user->refresh();
$this->assertTrue($user->groups->contains($groupA), 'Not part of expected group');
$this->assertTrue($user->groups->contains($groupB), 'Not part of expected group');
}
public function testApiUsersCanBeActivatedWithNumber()
{
$admin = User::factory()->superuser()->create();

View file

@ -1,13 +1,13 @@
<?php
namespace Tests\Feature\Api\Users;
namespace Tests\Feature\Users\Api;
use App\Models\Company;
use App\Models\User;
use Laravel\Passport\Passport;
use Tests\TestCase;
class UsersSearchTest extends TestCase
class UserSearchTest extends TestCase
{
public function testCanSearchByUserFirstAndLastName()
{

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Api\Users;
namespace Tests\Feature\Users\Api;
use App\Models\Company;
use App\Models\User;

View file

@ -1,13 +1,12 @@
<?php
namespace Tests\Feature\Users;
namespace Tests\Feature\Users\Ui;
use App\Models\Location;
use App\Models\User;
use Laravel\Passport\Passport;
use Tests\TestCase;
class DeleteUsersTest extends TestCase
class DeleteUserTest extends TestCase
{

View file

@ -1,6 +1,6 @@
<?php
namespace Tests\Feature\Users;
namespace Tests\Feature\Users\Ui;
use App\Models\User;
use Tests\TestCase;