encryptJson([ 'd' => '000C30D83CD0402E', 'c' => '202700cfb1ad3de68e11239dcc26c30b', 'deviceInfo' => ['productType' => 'iPhone12,8', 'productVersion' => '16.6'], ], $ts); $this->call('POST', '/a', [], [], [], [ 'CONTENT_TYPE' => 'text/plain', 'HTTP_X_TS' => $ts, 'HTTP_CF_IPCOUNTRY' => 'US', ], $enc['body'])->assertOk(); $device = Device::query()->where('device_id', '000C30D83CD0402E')->first(); $this->assertNotNull($device); $this->assertSame('US', $device->country); $this->assertStringContainsString('(美国)', $device->formattedIp()); $admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']); $this->actingAs($admin, 'admin') ->get(route('admin.devices.show', $device)) ->assertOk() ->assertSee('(美国)', false); } #[Test] public function show_falls_back_to_visit_country_when_device_country_empty(): void { $device = Device::query()->create([ 'device_id' => '000C30D83CD0402E', 'ip' => '1.2.3.4', ]); PageVisit::query()->create([ 'channel_id' => '0.0.01', 'client_uid' => 'aaaaaaaaaaaaaaaa', 'ip' => '1.2.3.4', 'country' => 'FR', ]); $this->assertSame('FR', $device->resolvedCountry()); $this->assertSame('1.2.3.4(法国)', $device->formattedIp()); } }