diff --git a/app/app/Mail/ImportCompletedNotification.php b/app/app/Mail/ImportCompletedNotification.php new file mode 100644 index 00000000..ddf02eb7 --- /dev/null +++ b/app/app/Mail/ImportCompletedNotification.php @@ -0,0 +1,49 @@ +outcome === 'done' + ? 'Импорт данных завершён — Лидерра' + : 'Импорт данных не удался — Лидерра'; + + return new Envelope(subject: $subject); + } + + public function content(): Content + { + return new Content( + markdown: 'mail.import-completed', + with: [ + 'log' => $this->log, + 'outcome' => $this->outcome, + ], + ); + } +} diff --git a/app/phpstan-baseline.neon b/app/phpstan-baseline.neon index b286ba31..79ddea59 100644 --- a/app/phpstan-baseline.neon +++ b/app/phpstan-baseline.neon @@ -1026,6 +1026,18 @@ parameters: count: 18 path: tests/Feature/Import/HistoricalImportServiceTest.php + - + message: '#^Access to an undefined property Pest\\PendingCalls\\TestCall\:\:\$tenant\.$#' + identifier: property.notFound + count: 3 + path: tests/Feature/Import/ImportCompletedNotificationTest.php + + - + message: '#^Access to an undefined property Pest\\PendingCalls\\TestCall\:\:\$user\.$#' + identifier: property.notFound + count: 3 + path: tests/Feature/Import/ImportCompletedNotificationTest.php + - message: '#^Access to an undefined property Pest\\PendingCalls\\TestCall\:\:\$tenant\.$#' identifier: property.notFound diff --git a/app/resources/views/mail/import-completed.blade.php b/app/resources/views/mail/import-completed.blade.php new file mode 100644 index 00000000..8f9a484f --- /dev/null +++ b/app/resources/views/mail/import-completed.blade.php @@ -0,0 +1,33 @@ + +@if ($outcome === 'done') +# Импорт завершён + +Импорт файла **{{ $log->filename }}** успешно завершён. + +| Показатель | Значение | +|:-----------|---------:| +| Добавлено сделок | {{ $log->rows_added }} | +| Обновлено сделок | {{ $log->rows_updated }} | +| Пропущено строк | {{ $log->rows_skipped }} | +| Неизвестных статусов | {{ $log->unknown_statuses_count }} | + +@if ($log->unknown_statuses_count > 0) +Обнаружены неизвестные статусы воронки — замапьте их вручную на экране «Импорт данных». +@endif +@else +# Импорт не удался + +Импорт файла **{{ $log->filename }}** завершился ошибкой: + +> {{ $log->error_message }} + +Проверьте формат файла и повторите загрузку на экране «Импорт данных». +@endif + + +Открыть «Импорт данных» + + +С уважением,
+Лидерра +
diff --git a/app/tests/Feature/Import/ImportCompletedNotificationTest.php b/app/tests/Feature/Import/ImportCompletedNotificationTest.php new file mode 100644 index 00000000..c251c4b1 --- /dev/null +++ b/app/tests/Feature/Import/ImportCompletedNotificationTest.php @@ -0,0 +1,49 @@ +tenant = Tenant::factory()->create(); + $this->user = User::factory()->for($this->tenant)->create(); + DB::statement('SET app.current_tenant_id = '.$this->tenant->id); +}); + +test('письмо об успешном импорте содержит счётчики', function (): void { + $log = ImportLog::factory()->create([ + 'tenant_id' => $this->tenant->id, + 'user_id' => $this->user->id, + 'status' => 'done', + 'rows_added' => 120, + 'rows_updated' => 8, + 'rows_skipped' => 2, + ]); + + $rendered = (new ImportCompletedNotification($log, 'done'))->render(); + + expect($rendered)->toContain('120') + ->and($rendered)->toContain('Импорт завершён'); +}); + +test('письмо о неуспешном импорте сообщает об ошибке', function (): void { + $log = ImportLog::factory()->create([ + 'tenant_id' => $this->tenant->id, + 'user_id' => $this->user->id, + 'status' => 'failed', + 'error_message' => 'Файл повреждён', + ]); + + $mailable = new ImportCompletedNotification($log, 'failed'); + $rendered = $mailable->render(); + + expect($rendered)->toContain('Файл повреждён') + ->and($mailable->envelope()->subject)->toContain('не удался'); +});