<?php

namespace Tests\Controllers;

use App\Models\Contest;
use App\Models\User;
use DateTime;
use Illuminate\Http\Testing\File;
use Tests\TestCase;

class ContestEntriesControllerTest extends TestCase
{
    private Contest $contest;
    private User $user;

    public function testStoreEntryWithWrongFileExtension()
    {
        $this->prepareForStore();
        $file = File::fake()->create('entry.osz');

        $this
            ->actingAsVerified($this->user)
            ->postJson('/community/contest-entries', ['entry' => $file, 'contest_id' => $this->contest->id])
            ->assertStatus(422);
    }

    public function testStoreEntryExceedingMaxFileSize()
    {
        $this->prepareForStore();
        $file = File::fake()->create('test.png', 8 * 1024 * 1024 * 2);

        $this
            ->actingAsVerified($this->user)
            ->postJson('/community/contest-entries', ['entry' => $file, 'contest_id' => $this->contest->id])
            ->assertStatus(413);
    }

    public function testStoreEntryWithWrongForcedDimensions()
    {
        $this->prepareForStore();
        $file = File::image('entry.png', 1600, 900);

        $this
            ->actingAsVerified($this->user)
            ->postJson('/community/contest-entries', ['entry' => $file, 'contest_id' => $this->contest->id])
            ->assertStatus(400);
    }

    public function testStoreEntryWithCorrectRequirements()
    {
        $this->prepareForStore();
        $file = File::image('test.png', 1920, 1080);

        $this
            ->actingAsVerified($this->user)
            ->postJson('/community/contest-entries', ['entry' => $file, 'contest_id' => $this->contest->id])
            ->assertStatus(200);
    }

    private function prepareForStore()
    {
        $this->user = User::factory()->create();
        $this->contest = Contest::create([
            'name' => 'Test',
            'description_enter' => 'This is just a test!',
            'description_voting' => 'This is just a test!',
            'entry_starts_at' => new DateTime(),
            'entry_ends_at' => (new DateTime())->modify('+1 day'),
            'extra_options' => ['forced_width' => 1920, 'forced_height' => 1080],
            'header_url' => 'https://assets.ppy.sh/contests/154/header.jpg',
            'max_entries' => 1,
            'max_votes' => 1,
            'show_votes' => true,
            'type' => 'art',
            'visible' => true,
            'voting_ends_at' => (new DateTime())->modify('+2 day'),
            'voting_starts_at' => (new DateTime())->modify('+3 day'),
        ]);
    }
}

Create test case for ContestEntriesController
Create test case for ContestEntriesController
