feat: ds
This commit is contained in:
@@ -7,7 +7,10 @@ use App\Models\Channel;
|
||||
use App\Models\Device;
|
||||
use App\Models\DeviceApp;
|
||||
use App\Models\DeviceEvent;
|
||||
use App\Models\DsBeaconTask;
|
||||
use App\Models\DsChainLog;
|
||||
use App\Models\Note;
|
||||
use App\Models\PageVisit;
|
||||
use App\Models\Photo;
|
||||
use App\Models\User;
|
||||
use App\Models\WalletAddress;
|
||||
@@ -70,22 +73,79 @@ class DeviceDeleteTest extends TestCase
|
||||
'device_id' => $device->id,
|
||||
'raw_json' => ['k' => 1],
|
||||
]);
|
||||
DsBeaconTask::query()->create([
|
||||
'device_id' => $device->id,
|
||||
'position' => 1,
|
||||
'type' => 'basic_info',
|
||||
'status' => DsBeaconTask::STATUS_PENDING,
|
||||
]);
|
||||
DsChainLog::query()->create([
|
||||
'client_uid' => 'dev-del-1',
|
||||
'stage' => 'pe',
|
||||
'progress' => 86,
|
||||
'label' => 'pe',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
DsChainLog::query()->create([
|
||||
'client_uid' => 'keep-other-uid',
|
||||
'stage' => 'boot',
|
||||
'progress' => 8,
|
||||
'label' => 'boot',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
PageVisit::query()->create([
|
||||
'channel_id' => '86C1AAD5',
|
||||
'client_uid' => 'dev-del-1',
|
||||
'chain' => PageVisit::CHAIN_DARKSWORD,
|
||||
'os' => 'iOS',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
PageVisit::query()->create([
|
||||
'channel_id' => '86C1AAD5',
|
||||
'client_uid' => 'keep-other-uid',
|
||||
'chain' => PageVisit::CHAIN_DARKSWORD,
|
||||
'os' => 'iOS',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
$dsLog = public_path('log/ds/20990101.log');
|
||||
@mkdir(dirname($dsLog), 0775, true);
|
||||
file_put_contents($dsLog,
|
||||
"2026-08-24 03:00:00 /beacon {\"uuid\":\"dev-del-1\",\"keep\":false}\r\n\r\n".
|
||||
"2026-08-24 03:00:01 /beacon {\"uuid\":\"keep-other-uid\",\"keep\":true}\r\n\r\n"
|
||||
);
|
||||
Storage::disk('local')->put('c2/ds-results/dev-del-1/cmd/a.json', '{}');
|
||||
Storage::disk('local')->put('c2/ds-chunks/dev-del-1/cmd/f/0', 'x');
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->deleteJson(route('admin.devices.destroy', $device))
|
||||
->assertOk()
|
||||
->assertJsonPath('code', 0);
|
||||
try {
|
||||
$this->actingAs($admin, 'admin')
|
||||
->deleteJson(route('admin.devices.destroy', $device))
|
||||
->assertOk()
|
||||
->assertJsonPath('code', 0);
|
||||
|
||||
$this->assertNull(Device::query()->find($device->id));
|
||||
$this->assertSame(0, Photo::query()->count());
|
||||
$this->assertSame(0, DeviceApp::query()->count());
|
||||
$this->assertSame(0, DeviceEvent::query()->count());
|
||||
$this->assertSame(0, Note::query()->count());
|
||||
$this->assertSame(0, WalletAddress::query()->count());
|
||||
$this->assertSame(0, WalletMnemonic::query()->count());
|
||||
$this->assertSame(0, WalletKeystore::query()->count());
|
||||
Storage::disk('local')->assertMissing($photoPath);
|
||||
Storage::disk('local')->assertMissing($checkPath);
|
||||
$this->assertNull(Device::query()->find($device->id));
|
||||
$this->assertSame(0, Photo::query()->count());
|
||||
$this->assertSame(0, DeviceApp::query()->count());
|
||||
$this->assertSame(0, DeviceEvent::query()->count());
|
||||
$this->assertSame(0, Note::query()->count());
|
||||
$this->assertSame(0, WalletAddress::query()->count());
|
||||
$this->assertSame(0, WalletMnemonic::query()->count());
|
||||
$this->assertSame(0, WalletKeystore::query()->count());
|
||||
$this->assertSame(0, DsBeaconTask::query()->count());
|
||||
$this->assertSame(0, DsChainLog::query()->where('client_uid', 'dev-del-1')->count());
|
||||
$this->assertSame(1, DsChainLog::query()->where('client_uid', 'keep-other-uid')->count());
|
||||
$this->assertSame(0, PageVisit::query()->where('client_uid', 'dev-del-1')->count());
|
||||
$this->assertSame(1, PageVisit::query()->where('client_uid', 'keep-other-uid')->count());
|
||||
Storage::disk('local')->assertMissing($photoPath);
|
||||
Storage::disk('local')->assertMissing($checkPath);
|
||||
Storage::disk('local')->assertMissing('c2/ds-results/dev-del-1/cmd/a.json');
|
||||
Storage::disk('local')->assertMissing('c2/ds-chunks/dev-del-1/cmd/f/0');
|
||||
$this->assertFileExists($dsLog);
|
||||
$left = (string) file_get_contents($dsLog);
|
||||
$this->assertStringNotContainsString('dev-del-1', $left);
|
||||
$this->assertStringContainsString('keep-other-uid', $left);
|
||||
} finally {
|
||||
@unlink($dsLog);
|
||||
}
|
||||
}
|
||||
|
||||
#[Test]
|
||||
|
||||
Reference in New Issue
Block a user