<?php

use App\Models\User;
use Illuminate\Support\Facades\Queue;

test('registration screen can be rendered', function () {
    $response = $this->get('/register');

    $response->assertStatus(200)
    ->assertSee('Read signup and login help')
    ->assertSee(route('help.auth'), false)
    ->assertSee(route('help.troubleshooting'), false)
    ->assertDontSee('name="name"', false)
    ->assertDontSee('name="username"', false)
        ->assertDontSee('name="password"', false)
        ->assertDontSee('name="password_confirmation"', false);
});

test('new users can register', function () {
    Queue::fake();
    config()->set('services.turnstile.enabled', false);

    $response = $this->post('/register', [
        'email' => 'test@example.com',
    ]);

    $user = User::query()->where('email', 'test@example.com')->firstOrFail();

    $this->assertAuthenticatedAs($user);
    $response->assertRedirect(route('setup.password.create', absolute: false));

    $this->assertDatabaseHas('users', [
        'email' => 'test@example.com',
        'onboarding_step' => 'verified',
        'is_active' => 1,
        'needs_password_reset' => 1,
    ]);

    expect($user->email_verified_at)->toBeNull();
    $this->assertDatabaseCount('user_verification_tokens', 0);
    Queue::assertNothingPushed();
});
