A free open source IT asset/license management system
Improve output
Marcus Moore472d50cc29d8
diff --git a/app/Console/Commands/RegenerateAcceptances.php b/app/Console/Commands/RegenerateAcceptances.phpindex b6b1414c4c..c695b5c7c2 100644--- a/app/Console/Commands/RegenerateAcceptances.php+++ b/app/Console/Commands/RegenerateAcceptances.php@@ -329,6 +329,12 @@ class RegenerateAcceptances extends Command* nobody emailed immediately before asking whether to email. A standalone* `--dry-run` has no question coming and keeps its footer.*+ * A run that created rows without `--notify` closes by naming+ * `snipeit:acceptance-reminder`, because the rows it just wrote are silent until+ * somebody emails them. The pointer says that command's scope is every pending+ * request rather than this run's, since a `--category`-scoped run does not narrow it.+ * `created` is only incremented off a dry run, so it carries the dry-run case too.+ ** @param bool $awaitingConfirmation whether the operator is about to be asked to go ahead*/private function printReport(RegenerateAcceptancesResult $result, bool $awaitingConfirmation = false): int@@ -343,7 +349,13 @@ class RegenerateAcceptances extends Commandif ($result->sendCountsByType !== []) {$this->info('Total by type:');- $this->table(array_keys($result->sendCountsByType), [array_values($result->sendCountsByType)]);+ $this->table(+ collect($result->sendCountsByType)+ ->keys()+ ->map(fn ($string) => Str::of($string)->headline()->plural())+ ->toArray(),+ [array_values($result->sendCountsByType)]+ );}if ($result->reportRows !== []) {@@ -385,6 +397,8 @@ class RegenerateAcceptances extends Command$this->info('The following users do not have an email address:');$this->table(['ID', 'Name'], $result->holdersWithoutEmail);}+ } elseif ($result->created > 0) {+ $this->line('Nobody was emailed. Run snipeit:acceptance-reminder to email them.');}return self::SUCCESS;diff --git a/tests/Feature/Console/RegenerateAcceptancesTest.php b/tests/Feature/Console/RegenerateAcceptancesTest.phpindex 8a78668358..bb97256a3a 100644--- a/tests/Feature/Console/RegenerateAcceptancesTest.php+++ b/tests/Feature/Console/RegenerateAcceptancesTest.php@@ -1049,11 +1049,39 @@ class RegenerateAcceptancesTest extends TestCase$this->artisan('snipeit:regenerate-acceptances', ['--no-interaction' => true])->expectsOutput('Created: 1.')->doesntExpectOutput('Notified: 1.')+ ->expectsOutputToContain('snipeit:acceptance-reminder')->assertExitCode(0);Mail::assertNothingSent();}+ /**+ * The rows a run without `--notify` writes are silent until somebody emails them, so+ * the footer names the command that does. It is not offered when the run emailed the+ * holders itself, nor when it wrote nothing for anyone to be reminded about — and a+ * dry run falls under the latter, since `created` only counts real rows.+ */+ public function test_the_reminder_command_is_only_named_when_rows_were_created_without_notify(): void+ {+ Mail::fake();+ $holder = User::factory()->create(['email' => '[email protected]']);+ $this->assetIn($this->acceptanceCategory('asset'), [+ 'assigned_to' => $holder->id,+ 'assigned_type' => User::class,+ ]);++ $this->artisan('snipeit:regenerate-acceptances', ['--no-interaction' => true, '--dry-run' => true])+ ->expectsOutput('Total acceptances to regenerate: 1.')+ ->expectsOutput('Nothing was created.')+ ->doesntExpectOutputToContain('snipeit:acceptance-reminder')+ ->assertExitCode(0);++ $this->artisan('snipeit:regenerate-acceptances', ['--no-interaction' => true, '--notify' => true])+ ->expectsOutput('Notified: 1.')+ ->doesntExpectOutputToContain('snipeit:acceptance-reminder')+ ->assertExitCode(0);+ }+public function test_dry_run_with_notify_emails_nobody(): void{Mail::fake();@@ -1386,7 +1414,7 @@ class RegenerateAcceptancesTest extends TestCase$this->artisan('snipeit:regenerate-acceptances', ['--no-interaction' => true])->expectsOutput('Total acceptances to regenerate: 8.')- ->expectsTable(['Asset', 'LicenseSeat', 'Accessory', 'Consumable', 'Component'], [[3, 1, 2, 1, 1]])+ ->expectsTable(['Assets', 'License Seats', 'Accessories', 'Consumables', 'Components'], [[3, 1, 2, 1, 1]])->expectsOutput('Includes 1 previously declined, being asked to accept again.')->expectsOutput('Already covered by a pending request: 1.')->expectsOutput('Created: 8.')