51 lines
2.2 KiB
PHP
51 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use App\Console\Commands\RunAccountMappingResync;
|
|
use Illuminate\Contracts\Console\Kernel;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Modules\EcommerceFinance\Services\AccountMappingResyncDispatcher;
|
|
use Tests\TestCase;
|
|
|
|
class AccountMappingResyncBudgetTest extends TestCase
|
|
{
|
|
public function test_default_budget_yields_after_one_job_and_retains_edits_received_during_sync(): void
|
|
{
|
|
config(['cache.stores.upstream_shared' => ['driver' => 'array']]);
|
|
$table = AccountMappingResyncDispatcher::JOBS_TABLE;
|
|
Schema::dropIfExists($table);
|
|
Schema::create($table, function (Blueprint $table): void {
|
|
$table->increments('id');
|
|
$table->string('platform');
|
|
$table->string('month');
|
|
$table->string('status');
|
|
$table->unsignedInteger('attempts')->default(0);
|
|
$table->text('message')->nullable();
|
|
$table->timestamps();
|
|
});
|
|
foreach (['2026-09', '2026-10'] as $month) {
|
|
DB::table($table)->insert(['platform' => 'jingxi', 'month' => $month, 'status' => 'pending', 'created_at' => now(), 'updated_at' => now()]);
|
|
}
|
|
$command = new class extends RunAccountMappingResync {
|
|
public bool $edited = false;
|
|
protected function runSync(object $job): array
|
|
{
|
|
if ($this->edited) {
|
|
DB::table(AccountMappingResyncDispatcher::JOBS_TABLE)->where('id', $job->id)->update(['status' => 'pending']);
|
|
}
|
|
return [true, 'OK'];
|
|
}
|
|
};
|
|
$this->app->make(Kernel::class)->registerCommand($command);
|
|
$this->artisan('store-receipt:auto-resync')->assertSuccessful();
|
|
$this->assertSame(['done', 'pending'], DB::table($table)->orderBy('id')->pluck('status')->all());
|
|
$command->edited = true;
|
|
$this->artisan('store-receipt:auto-resync')->assertSuccessful();
|
|
$this->assertSame(['done', 'pending'], DB::table($table)->orderBy('id')->pluck('status')->all());
|
|
$this->assertSame([1, 1], DB::table($table)->orderBy('id')->pluck('attempts')->all());
|
|
}
|
|
}
|