<?php

use App\Http\Resources\RoleResource;
use App\Models\Role;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Tests\TestCase;

uses(TestCase::class, RefreshDatabase::class);

test('role resource returns wrapped data', function () {
    $role = Role::factory()->create();

    $response = (new RoleResource($role))->toResponse(Request::create('/'));
    $payload = $response->getData(true);

    expect($payload)->toHaveKey('data');
    expect($payload['data']['id'])->toBe($role->id);
});

test('role resource collection keeps data wrapper', function () {
    $roles = Role::factory()->count(2)->create();

    $response = RoleResource::collection($roles)->toResponse(Request::create('/'));
    $payload = $response->getData(true);

    expect($payload['data'])->toHaveCount(2);
});
