75 lines
2.7 KiB
PHP
75 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Modules\EcommerceFinance\Repositories\DingAttendanceMirrorRepository;
|
|
use Tests\TestCase;
|
|
|
|
class DingAttendanceMirrorRepositoryTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
config([
|
|
'database.connections.business_mirror' => [
|
|
'driver' => 'sqlite',
|
|
'database' => ':memory:',
|
|
'prefix' => '',
|
|
],
|
|
'upstream_mirrors.connection' => 'business_mirror',
|
|
'app.timezone' => 'Asia/Shanghai',
|
|
'dingtalk.attendance.exempt_approval_tags' => ['请假', '休息'],
|
|
'dingtalk.attendance.exempt_time_results' => ['休息', 'Rest'],
|
|
]);
|
|
DB::purge('business_mirror');
|
|
|
|
Schema::connection('business_mirror')->create('business_mirror_table_states', function (Blueprint $table): void {
|
|
$table->string('dataset_key', 191)->primary();
|
|
$table->string('status', 24)->nullable();
|
|
});
|
|
(require base_path('database/migrations/2026_11_06_090000_create_ding_attendance_records.php'))->up();
|
|
}
|
|
|
|
public function test_only_approved_leave_or_rest_dates_are_returned(): void
|
|
{
|
|
DB::connection('business_mirror')->table('ding_attendance_records')->insert([
|
|
[
|
|
'record_id' => 'leave',
|
|
'user_id' => 'changyi',
|
|
'user_name' => '常仪',
|
|
'work_date' => '2026-11-04',
|
|
'approve_tag_name' => '请假',
|
|
'time_result' => 'NotSigned',
|
|
],
|
|
[
|
|
'record_id' => 'rest',
|
|
'user_id' => 'yaoyao',
|
|
'user_name' => '杳杳',
|
|
'work_date' => '2026-11-04',
|
|
'approve_tag_name' => null,
|
|
'time_result' => '休息',
|
|
],
|
|
[
|
|
'record_id' => 'missed',
|
|
'user_id' => 'other',
|
|
'user_name' => '其他人',
|
|
'work_date' => '2026-11-04',
|
|
'approve_tag_name' => null,
|
|
'time_result' => 'NotSigned',
|
|
],
|
|
]);
|
|
|
|
$dates = app(DingAttendanceMirrorRepository::class)
|
|
->exemptDatesForUsers(['changyi', 'yaoyao', 'other'], '2026-11-04', '2026-11-04');
|
|
|
|
$this->assertSame(['changyi', 'yaoyao'], array_keys($dates));
|
|
$this->assertTrue($dates['changyi']['2026-11-04']);
|
|
$this->assertTrue($dates['yaoyao']['2026-11-04']);
|
|
$this->assertArrayNotHasKey('other', $dates);
|
|
}
|
|
}
|