<?php

declare(strict_types=1);

use App\Events\Admin\Dump\DumpCreated;
use App\Events\Admin\Dump\DumpDeleted;
use App\Events\Admin\Dump\DumpUpdated;
use App\Models\Admin\Dump;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event;

test('dump created event dispatched', function () {
    Dump::factory()->create();

    Event::assertDispatched(DumpCreated::class);
});

test('dump deleted event dispatched', function () {
    $dump = Dump::factory()->create();

    $dump->delete();

    Event::assertDispatched(DumpDeleted::class);
});

test('dump updated event dispatched', function () {
    $dump = Dump::factory()->createOne();
    $changes = Dump::factory()->makeOne();

    $dump->fill($changes->getAttributes());
    $dump->save();

    Event::assertDispatched(DumpUpdated::class);
});

test('dump updated event embed fields', function () {
    $dump = Dump::factory()->createOne();
    $changes = Dump::factory()->makeOne();

    $dump->fill($changes->getAttributes());
    $dump->save();

    Event::assertDispatched(DumpUpdated::class, function (DumpUpdated $event) {
        $message = $event->getDiscordMessage();

        return ! empty(Arr::get($message->embed, 'fields'));
    });
});
