<?php

declare(strict_types=1);

use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Tests\Concerns\SharesSupplierPdo;

uses(DatabaseTransactions::class);
uses(SharesSupplierPdo::class);

beforeEach(function (): void {
    config([
        'services.dadata.api_key' => 'k',
        'services.dadata.secret' => 's',
        'services.dadata.daily_cap_rub' => 100000,
    ]);
});

it('phone-region:smoke prints the resolution and writes nothing to DB', function (): void {
    Http::fake(['cleaner.dadata.ru/*' => Http::response([[
        'qc' => 0, 'region' => 'Москва', 'provider' => 'МТС',
    ]], 200)]);

    $this->artisan('phone-region:smoke', ['--phone' => '79161234567'])
        ->assertSuccessful()
        ->expectsOutputToContain('dadata')
        ->expectsOutputToContain('Москва');

    // Smoke не пишет в БД.
    expect(DB::table('lead_region_resolution_log')->count())->toBe(0);
    expect(DB::table('deals')->count())->toBe(0);
});

it('phone-region:smoke fails without --phone', function (): void {
    $this->artisan('phone-region:smoke')->assertFailed();
});
