<?php

namespace App\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class ScannerControllerTest extends WebTestCase
{
    public function testScannerPageReturnsSuccess(): void
    {
        $client = static::createClient();
        $client->request('GET', '/scanner/');

        self::assertResponseIsSuccessful();
        self::assertSelectorTextContains('title', 'E-Ticket Scanner');
    }

    public function testScannerManifestReturnsJson(): void
    {
        $client = static::createClient();
        $client->request('GET', '/scanner/manifest.json');

        self::assertResponseIsSuccessful();
        self::assertResponseHeaderSame('Content-Type', 'application/manifest+json');

        $data = json_decode($client->getResponse()->getContent(), true);
        self::assertSame('E-Ticket Scanner', $data['name']);
        self::assertSame('standalone', $data['display']);
        self::assertSame('/scanner/', $data['start_url']);
    }

    public function testScannerPageIsAccessibleWithoutAuth(): void
    {
        $client = static::createClient();
        $client->request('GET', '/scanner/');

        self::assertResponseIsSuccessful();
        self::assertResponseStatusCodeSame(200);
    }
}
