<?php

namespace Tricks\LaravelTools\Traits;

trait EndpointSnapshotTestTrait
{
    public function endpointSnapshot(string $model, string $endpoint)
    {
        expect(method_exists($model::factory(), 'testingState'))
            ->toBeTrue("The model $model needs to have a factory with a defined state named testingState");

        $model::factory()
            ->testingState()
            ->create();

        $test = $this->getJson($endpoint);
        $test->assertSuccessful();
        $content = $test->content();
        $content = preg_replace(
            '/"http[^"]+"/',
            '"static"',
            $content
        );

        expect($content)->toMatchSnapshot();
    }
}

