migrating tests (Metrics, NotificationChannels, PHP, Profile and Projects)

This commit is contained in:
Saeed Vaziry
2024-10-10 23:24:07 +02:00
parent 93cee92568
commit 7086e84c3c
16 changed files with 292 additions and 212 deletions

View File

@ -3,15 +3,11 @@
namespace App\Actions\Monitoring;
use App\Models\Server;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
class UpdateMetricSettings
{
public function update(Server $server, array $input): void
{
$this->validate($input);
$service = $server->monitoring();
$data = $service->handler()->data();
@ -20,13 +16,14 @@ public function update(Server $server, array $input): void
$service->save();
}
private function validate(array $input): void
public static function rules(): array
{
Validator::make($input, [
return [
'data_retention' => [
'required',
Rule::in(config('core.metrics_data_retention')),
'numeric',
'min:1',
],
])->validate();
];
}
}

View File

@ -4,6 +4,7 @@
use App\Models\NotificationChannel;
use App\Models\User;
use Exception;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
@ -11,6 +12,7 @@ class AddChannel
{
/**
* @throws ValidationException
* @throws Exception
*/
public function add(User $user, array $input): void
{
@ -23,18 +25,24 @@ public function add(User $user, array $input): void
$channel->data = $channel->provider()->createData($input);
$channel->save();
if (! $channel->provider()->connect()) {
$channel->delete();
try {
if (! $channel->provider()->connect()) {
$channel->delete();
if ($channel->provider === \App\Enums\NotificationChannel::EMAIL) {
throw ValidationException::withMessages([
'email' => __('Could not connect! Make sure you configured `.env` file correctly.'),
]);
}
if ($channel->provider === \App\Enums\NotificationChannel::EMAIL) {
throw ValidationException::withMessages([
'email' => __('Could not connect! Make sure you configured `.env` file correctly.'),
'provider' => __('Could not connect'),
]);
}
} catch (Exception $e) {
$channel->delete();
throw ValidationException::withMessages([
'provider' => __('Could not connect'),
]);
throw $e;
}
$channel->connected = true;