Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Importer/CategoryImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function handle($row)

// Boolean flags. Present-empty maps to 0; present-with-value uses
// fetchHumanBoolean; absent leaves the DB value alone on update.
foreach (['use_default_eula', 'require_acceptance', 'checkin_email'] as $flag) {
foreach (['use_default_eula', 'require_acceptance', 'checkin_email', 'alert_on_response'] as $flag) {
if ($this->csvRowHas($row, $flag)) {
$raw = $this->findCsvMatch($row, $flag);
$this->item[$flag] = ($this->fetchHumanBoolean($raw) == 1) ? 1 : 0;
Expand Down
51 changes: 51 additions & 0 deletions tests/Feature/Importing/Api/ImportCategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,57 @@ public function update_mode_clears_field_when_csv_column_is_present_but_empty():
$this->assertNull($category->eula_text);
}

#[Test]
public function import_sets_alert_on_response_flag(): void
{
$this->actingAsForApi(User::factory()->superuser()->create());

$importFileBuilder = new ImportFileBuilder([[
'name' => 'Alerting Laptops',
'category_type' => 'asset',
'alert_on_response' => 1,
]]);
$import = Import::factory()->categories()->create([
'file_path' => $importFileBuilder->saveToImportsDirectory(),
]);

$this->importFileResponse(['import' => $import->id])->assertOk();

$newCategory = Category::query()->where('name', 'Alerting Laptops')->sole();

$this->assertEquals(1, $newCategory->alert_on_response);
}

#[Test]
public function update_mode_updates_alert_on_response_flag(): void
{
$this->actingAsForApi(User::factory()->superuser()->create());

$category = Category::factory()->assetLaptopCategory()->create([
'alert_on_response' => 1,
])->refresh();

$this->assertEquals(1, $category->alert_on_response);

$importFileBuilder = new ImportFileBuilder([[
'name' => $category->name,
'category_type' => $category->category_type,
'alert_on_response' => 0,
]]);
$import = Import::factory()->categories()->create([
'file_path' => $importFileBuilder->saveToImportsDirectory(),
]);

$this->importFileResponse([
'import' => $import->id,
'import-update' => true,
])->assertOk();

$category->refresh();

$this->assertEquals(0, $category->alert_on_response);
}

#[Test]
public function update_mode_preserves_fields_when_csv_column_is_absent(): void
{
Expand Down
Loading