<?php

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;

uses(RefreshDatabase::class);

test('label import requires authentication', function () {
    $response = $this->post(route('settings.labels.import'), []);
    $response->assertRedirect(route('login'));
});

test('label import returns json on valid file', function () {
    $user = User::factory()->create();
    $response = $this->actingAs($user)
        ->post(route('settings.labels.import'), [
            'file' => new UploadedFile(base_path('tests/fixtures/labels-sample.bin'), 'labels.bin', null, null, true),
        ]);

    $response->assertStatus(200)
        ->assertJsonStructure(['new', 'updated', 'total']);
});

test('label import returns 422 on invalid file', function () {
    $user = User::factory()->create();
    $response = $this->actingAs($user)
        ->post(route('settings.labels.import'), [
            'file' => UploadedFile::fake()->create('notalabels.bin', 1),
        ]);

    $response->assertStatus(422);
});
