diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 7644488a89..645e2624b2 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -121,7 +121,6 @@ class AcceptanceController extends Controller $pdf_filename = 'accepted-eula-'.date('Y-m-d-h-i-s').'.pdf'; $sig_filename=''; - if ($request->input('asset_acceptance') == 'accepted') { /** @@ -153,7 +152,6 @@ class AcceptanceController extends Controller } } - // this is horrible switch($acceptance->checkoutable_type){ case 'App\Models\Asset': @@ -170,7 +168,7 @@ class AcceptanceController extends Controller $pdf_view_route ='account.accept.accept-accessory-eula'; $accessory = Accessory::find($item->id); $display_model = $accessory->name; - $assigned_to = User::find($item->assignedTo); + $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; case 'App\Models\LicenseSeat': @@ -253,11 +251,15 @@ class AcceptanceController extends Controller // This is the most horriblest switch($acceptance->checkoutable_type){ case 'App\Models\Asset': + $asset_model = AssetModel::find($item->model_id); + $display_model = $asset_model->name; $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; case 'App\Models\Accessory': - $assigned_to = User::find($item->assignedTo); + $accessory = Accessory::find($item->id); + $display_model = $accessory->name; + $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; case 'App\Models\LicenseSeat': @@ -269,6 +271,8 @@ class AcceptanceController extends Controller break; case 'App\Models\Consumable': + $consumable = Consumable::find($item->id); + $display_model = $consumable->name; $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; } @@ -292,4 +296,4 @@ class AcceptanceController extends Controller return redirect()->to('account/accept')->with('success', $return_msg); } -} \ No newline at end of file +} diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php index c3c34b0571..4a4360c40a 100644 --- a/app/Models/CheckoutAcceptance.php +++ b/app/Models/CheckoutAcceptance.php @@ -3,13 +3,14 @@ namespace App\Models; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Notifications\Notifiable; class CheckoutAcceptance extends Model { - use SoftDeletes, Notifiable; + use HasFactory, SoftDeletes, Notifiable; protected $casts = [ 'accepted_at' => 'datetime', diff --git a/database/factories/CheckoutAcceptanceFactory.php b/database/factories/CheckoutAcceptanceFactory.php new file mode 100644 index 0000000000..b5744527f8 --- /dev/null +++ b/database/factories/CheckoutAcceptanceFactory.php @@ -0,0 +1,41 @@ + Asset::class, + 'checkoutable_id' => Asset::factory(), + 'assigned_to_id' => User::factory(), + ]; + } + + public function forAccessory() + { + return $this->state([ + 'checkoutable_type' => Accessory::class, + 'checkoutable_id' => Accessory::factory(), + ]); + } + + public function pending() + { + return $this->state([ + 'accepted_at' => null, + 'declined_at' => null, + ]); + } +} diff --git a/resources/views/notifications/markdown/asset-acceptance.blade.php b/resources/views/notifications/markdown/asset-acceptance.blade.php index 5616525b13..50191d4a37 100644 --- a/resources/views/notifications/markdown/asset-acceptance.blade.php +++ b/resources/views/notifications/markdown/asset-acceptance.blade.php @@ -11,7 +11,7 @@ | **{{ ucfirst(trans('general.accepted')) }}** | {{ $accepted_date }} | @endif @if (isset($declined_date)) -| **{{ trans('general.declined') }}** | {{ $declined_date }} | +| **{{ ucfirst(trans('general.declined')) }}** | {{ $declined_date }} | @endif @if ((isset($item_tag)) && ($item_tag!='')) | **{{ trans('mail.asset_tag') }}** | {{ $item_tag }} | diff --git a/routes/web.php b/routes/web.php index 4644f41ffb..39c66d35d8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -291,7 +291,8 @@ Route::group(['prefix' => 'account', 'middleware' => ['auth']], function () { Route::get('accept/{id}', [Account\AcceptanceController::class, 'create']) ->name('account.accept.item'); - Route::post('accept/{id}', [Account\AcceptanceController::class, 'store']); + Route::post('accept/{id}', [Account\AcceptanceController::class, 'store']) + ->name('account.store-acceptance'); Route::get( 'print', diff --git a/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php new file mode 100644 index 0000000000..a49b1167cb --- /dev/null +++ b/tests/Feature/CheckoutAcceptances/AccessoryAcceptanceTest.php @@ -0,0 +1,82 @@ +settings->enableAlertEmail(); + + $acceptance = CheckoutAcceptance::factory() + ->pending() + ->for(Accessory::factory()->appleMouse(), 'checkoutable') + ->create(); + + $this->actingAs($acceptance->assignedTo) + ->post(route('account.store-acceptance', $acceptance), ['asset_acceptance' => 'accepted']) + ->assertSessionHasNoErrors(); + + $this->assertNotNull($acceptance->fresh()->accepted_at); + + Notification::assertSentTo( + $acceptance, + function (AcceptanceAssetAcceptedNotification $notification) use ($acceptance) { + $this->assertStringContainsString( + $acceptance->assignedTo->present()->fullName, + $notification->toMail()->render() + ); + + return true; + } + ); + } + + /** + * This can be absorbed into a bigger test + */ + public function testUsersNameIsIncludedInAccessoryDeclinedNotification() + { + Notification::fake(); + + $this->settings->enableAlertEmail(); + + $acceptance = CheckoutAcceptance::factory() + ->pending() + ->for(Accessory::factory()->appleMouse(), 'checkoutable') + ->create(); + + $this->actingAs($acceptance->assignedTo) + ->post(route('account.store-acceptance', $acceptance), ['asset_acceptance' => 'declined']) + ->assertSessionHasNoErrors(); + + $this->assertNotNull($acceptance->fresh()->declined_at); + + Notification::assertSentTo( + $acceptance, + function (AcceptanceAssetDeclinedNotification $notification) use ($acceptance) { + $this->assertStringContainsString( + $acceptance->assignedTo->present()->fullName, + $notification->toMail($acceptance)->render() + ); + + return true; + } + ); + } +} diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index 9d4209da79..70022e53c3 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -18,6 +18,16 @@ class Settings return new self(); } + public function enableAlertEmail(string $email = 'notifications@afcrichmond.com'): Settings + { + return $this->update(['alert_email' => $email]); + } + + public function disableAlertEmail(): Settings + { + return $this->update(['alert_email' => null]); + } + public function enableMultipleFullCompanySupport(): Settings { return $this->update(['full_multiple_companies_support' => 1]);