59 lines
2.3 KiB
PHP
59 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Repositories\DingWorklogMirrorRepository;
|
|
use Modules\EcommerceFinance\Services\DingWorklogPenaltyCalculator;
|
|
use Modules\EcommerceFinance\View\DingWorklogStatisticsPageData;
|
|
use Tests\TestCase;
|
|
|
|
class DingWorklogStatisticsPageDataTest extends TestCase
|
|
{
|
|
public function test_submission_details_are_hidden_until_requested(): void
|
|
{
|
|
Carbon::setTestNow(Carbon::parse('2026-11-05 13:00:00', 'Asia/Shanghai'));
|
|
|
|
try {
|
|
$repository = Mockery::mock(DingWorklogMirrorRepository::class);
|
|
$repository->shouldReceive('available')->andReturnTrue();
|
|
$repository->shouldReceive('state')->once()->andReturn([
|
|
'status' => 'succeeded',
|
|
'last_attempted_at' => '2026-11-05 12:45:00',
|
|
'last_succeeded_at' => '2026-11-05 12:45:00',
|
|
'mirror_row_count' => 83,
|
|
'last_error_code' => null,
|
|
]);
|
|
$repository->shouldReceive('dailySummary')->once()->andReturn([[
|
|
'statistics_date' => '2026-11-04',
|
|
'submission_count' => 9,
|
|
'submitter_count' => 9,
|
|
'first_submitted_at' => '2026-11-04 20:16:55',
|
|
'last_submitted_at' => '2026-11-05 11:32:59',
|
|
]]);
|
|
$repository->shouldNotReceive('submissionsForDate');
|
|
|
|
$penalty = Mockery::mock(DingWorklogPenaltyCalculator::class);
|
|
$penalty->shouldReceive('summary')->once()->andReturn([
|
|
'start_date' => '2026-11-04',
|
|
'end_date' => '2026-11-04',
|
|
'total_points' => '40',
|
|
'total_points_formatted' => '40',
|
|
'members' => [],
|
|
]);
|
|
|
|
$data = (new DingWorklogStatisticsPageData($repository, $penalty))->page(
|
|
Request::create('/?from=2026-10-22&to=2026-11-04')
|
|
);
|
|
|
|
$this->assertFalse($data['worklogShowDetails']);
|
|
$this->assertSame([], $data['worklogSubmissions']);
|
|
$this->assertSame(9, $data['worklogDaily'][0]['submitter_count']);
|
|
} finally {
|
|
Carbon::setTestNow();
|
|
}
|
|
}
|
|
}
|