settings->enableScopedLocationsWithFullMultipleCompanySupport(); $company = Company::factory()->create(); $location = Location::factory()->create(['company_id' => $company->id]); $importFileBuilder = ImportFileBuilder::new([ 'companyName' => $company->name, 'location' => $location->name, ]); $row = $importFileBuilder->firstRow(); $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $this->assertTrue(User::where('username', $row['username'])->exists(), 'User should be created when location matches company'); } public function test_user_and_location_in_different_companies_is_rejected() { $this->settings->enableScopedLocationsWithFullMultipleCompanySupport(); [$companyA, $companyB] = Company::factory()->count(2)->create(); $location = Location::factory()->create(['company_id' => $companyB->id]); $importFileBuilder = ImportFileBuilder::new([ 'companyName' => $companyA->name, 'location' => $location->name, ]); $row = $importFileBuilder->firstRow(); $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertInternalServerError(); $this->assertFalse(User::where('username', $row['username'])->exists(), 'User should not be created when location is in a different company'); } public function test_null_company_location_with_floater_on_is_imported() { $this->settings->enableScopedLocationsWithFullMultipleCompanySupport(); $this->settings->enableFloaterMode(); $company = Company::factory()->create(); $location = Location::factory()->create(['company_id' => null]); $importFileBuilder = ImportFileBuilder::new([ 'companyName' => $company->name, 'location' => $location->name, ]); $row = $importFileBuilder->firstRow(); $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $this->assertTrue(User::where('username', $row['username'])->exists(), 'User should be created when location has no company and floater is on'); } public function test_null_company_location_with_floater_off_is_rejected() { $this->settings->enableScopedLocationsWithFullMultipleCompanySupport(); $this->settings->disableFloaterMode(); $company = Company::factory()->create(); $location = Location::factory()->create(['company_id' => null]); $importFileBuilder = ImportFileBuilder::new([ 'companyName' => $company->name, 'location' => $location->name, ]); $row = $importFileBuilder->firstRow(); $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertInternalServerError(); $this->assertFalse(User::where('username', $row['username'])->exists(), 'User should not be created when location has no company and floater is off'); } }