<?php

namespace Tests\Unit\Modules\Stock;

use App\Modules\Stock\Motors;
use Mockery;
use Mtc\ContentManager\Contracts\Media;
use Tests\TestCase;

class MotorsTest extends TestCase
{
    public function testExternalMediaUrlPrependsPrefixToPartialPath(): void
    {
        $motors = new Motors();

        $media = Mockery::mock(Media::class)->makePartial();
        $media->src = '/path/to/image.jpg';

        $url = $motors->url($media, 'large');
        $this->assertEquals('https://origin-resizer.images.autoexposure.co.uk/path/to/image.jpg', $url);
    }

    public function testExternalMediaUrlReturnsFullUrlUnchanged(): void
    {
        $motors = new Motors();

        $media = Mockery::mock(Media::class)->makePartial();
        $media->src = 'https://cdn.images.autoexposure.co.uk/AETA30284/AETV22215210_9.jpg?t=20141023044610';

        $url = $motors->url($media, 'large');
        $this->assertEquals($media->src, $url);
    }

    public function testExternalMediaUrlDoesNotPrependPrefixToHttpUrl(): void
    {
        $motors = new Motors();

        $media = Mockery::mock(Media::class)->makePartial();
        $media->src = 'http://cdn.images.autoexposure.co.uk/AETA30284/AETV22215210_9.jpg';

        $url = $motors->url($media, 'medium');
        $this->assertEquals($media->src, $url);
        $this->assertStringNotContainsString('origin-resizer', $url);
    }
}
