|
4 | 4 |
|
5 | 5 | use App\Mail\CheckoutAssetMail; |
6 | 6 | use App\Models\Asset; |
| 7 | +use App\Models\Company; |
7 | 8 | use App\Models\Location; |
8 | 9 | use App\Models\User; |
9 | 10 | use Illuminate\Support\Facades\Mail; |
@@ -122,6 +123,42 @@ function () { |
122 | 123 | ]; |
123 | 124 | } |
124 | 125 |
|
| 126 | + #[DataProvider('checkoutTargets')] |
| 127 | + public function test_adheres_to_full_multiple_company_support($data) |
| 128 | + { |
| 129 | + ['type' => $type, 'target' => $target] = $data(); |
| 130 | + |
| 131 | + $this->settings->enableMultipleFullCompanySupport(); |
| 132 | + |
| 133 | + // create two companies |
| 134 | + [$companyA, $companyB] = Company::factory()->count(2)->create(); |
| 135 | + |
| 136 | + // create an asset for each company |
| 137 | + $assetForCompanyA = Asset::factory()->for($companyA)->create(); |
| 138 | + $assetForCompanyB = Asset::factory()->for($companyB)->create(); |
| 139 | + |
| 140 | + $this->assertNull($assetForCompanyA->assigned_to, 'Asset should not be assigned before attempting this test case.'); |
| 141 | + $this->assertNull($assetForCompanyB->assigned_to, 'Asset should not be assigned before attempting this test case.'); |
| 142 | + |
| 143 | + // attempt to bulk checkout both items to the target |
| 144 | + $response = $this->actingAs(User::factory()->superuser()->create()) |
| 145 | + ->post(route('hardware.bulkcheckout.store'), [ |
| 146 | + 'selected_assets' => [ |
| 147 | + $assetForCompanyA->id, |
| 148 | + $assetForCompanyB->id, |
| 149 | + ], |
| 150 | + 'checkout_to_type' => $type, |
| 151 | + "assigned_$type" => $target->id, |
| 152 | + ]); |
| 153 | + |
| 154 | + // ensure bulk checkout is blocked |
| 155 | + $this->assertNull($assetForCompanyA->fresh()->assigned_to, 'Asset was checked out across companies.'); |
| 156 | + $this->assertNull($assetForCompanyB->fresh()->assigned_to, 'Asset was checked out across companies.'); |
| 157 | + |
| 158 | + // ensure redirected back |
| 159 | + $response->assertRedirectToRoute('hardware.bulkcheckout.show'); |
| 160 | + } |
| 161 | + |
125 | 162 | #[DataProvider('checkoutTargets')] |
126 | 163 | public function test_prevents_checkouts_of_checked_out_items($data) |
127 | 164 | { |
|
0 commit comments