Skip to content

Commit

Permalink
Fix test case issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-canyon committed Oct 16, 2024
1 parent 827b827 commit ed8d13a
Showing 1 changed file with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@

use AidingApp\ServiceManagement\Models\ServiceRequest;
use AidingApp\ServiceManagement\Models\ServiceRequestType;
use AidingApp\ServiceManagement\Models\ServiceRequestPriority;
use AidingApp\ServiceManagement\Filament\Resources\ServiceRequestResource;
use AidingApp\ServiceManagement\Tests\RequestFactories\CreateServiceRequestRequestFactory;
use AidingApp\ServiceManagement\Filament\Resources\ServiceRequestResource\Pages\CreateServiceRequest;
use AidingApp\ServiceManagement\Models\ServiceRequestPriority;

test('A successful action on the CreateServiceRequest page', function () {
asSuperAdmin()
Expand Down Expand Up @@ -176,7 +176,7 @@
$request = collect(CreateServiceRequestRequestFactory::new()->create([
'priority_id' => ServiceRequestPriority::factory()->create([
'type_id' => $serviceRequestTypesWithManager->getKey(),
])->getKey()
])->getKey(),
]));

livewire(CreateServiceRequest::class)
Expand Down Expand Up @@ -244,7 +244,7 @@

$serviceRequestType = ServiceRequestType::factory()->create();

$serviceRequestType->auditors()->attach($team);
$serviceRequestType->managers()->attach($team);

actingAs($user)
->get(
Expand All @@ -254,7 +254,7 @@
$request = collect(CreateServiceRequestRequestFactory::new()->create([
'priority_id' => ServiceRequestPriority::factory()->create([
'type_id' => $serviceRequestType->getKey(),
])->getKey()
])->getKey(),
]));

livewire(CreateServiceRequest::class)
Expand Down Expand Up @@ -311,7 +311,6 @@
});

test('displays only service request types managed by the current user', function () {

$settings = app(LicenseSettings::class);

$settings->data->addons->serviceManagement = true;
Expand All @@ -332,22 +331,21 @@
actingAs($user);

$serviceRequestTypesWithManagers = ServiceRequestType::factory()
->hasAttached($team,[],'managers')
->create();
->hasAttached($team, [], 'managers')
->create();

$serviceRequestTypesWithoutManagers = ServiceRequestType::factory()->create();

livewire(CreateServiceRequest::class)
->assertFormFieldExists('type_id', function (Select $field) use ($serviceRequestTypesWithManagers, $serviceRequestTypesWithoutManagers): bool {
$options = $field->getOptions();

return in_array($serviceRequestTypesWithManagers->getKey(), array_keys($options)) &&
!in_array($serviceRequestTypesWithoutManagers->getKey(), array_keys($options));
! in_array($serviceRequestTypesWithoutManagers->getKey(), array_keys($options));
});

});

test('create service requests if user is manager of any service request type',function(){

test('create service requests if user is manager of any service request type', function () {
$settings = app(LicenseSettings::class);

$settings->data->addons->serviceManagement = true;
Expand Down Expand Up @@ -376,7 +374,7 @@
$request = collect(CreateServiceRequestRequestFactory::new()->create([
'priority_id' => ServiceRequestPriority::factory()->create([
'type_id' => $serviceRequestTypesWithManager->getKey(),
])->getKey()
])->getKey(),
]));

livewire(CreateServiceRequest::class)
Expand All @@ -394,11 +392,9 @@
$serviceRequest = ServiceRequest::first();

expect($serviceRequest->division->id)->toEqual($request['division_id']);

});

test('validate service requests type if user is manager of any service request type',function(){

test('validate service requests type if user is manager of any service request type', function () {
$settings = app(LicenseSettings::class);

$settings->data->addons->serviceManagement = true;
Expand All @@ -424,7 +420,7 @@

$serviceRequestTypesWithManagers = ServiceRequestType::factory()->count(2)->create();

$serviceRequestTypesWithManagers->each(function($serviceRequest) use($team) {
$serviceRequestTypesWithManagers->each(function ($serviceRequest) use ($team) {
$serviceRequest->managers()->attach($team);
});

Expand All @@ -436,9 +432,8 @@
'respondent_id' => Contact::factory()->create()->getKey(),
'priority_id' => ServiceRequestPriority::factory()->create([
'type_id' => $serviceRequestTypes->first()->getKey(),
])->getKey()
])->getKey(),
])
->call('create')
->assertHasFormErrors(['type_id']);

});
});

0 comments on commit ed8d13a

Please sign in to comment.