mirror of
https://github.com/linuxserver/Heimdall.git
synced 2026-08-07 07:16:13 +00:00
2555ab1b3c
The :memory: overrides in phpunit.xml had been commented out since 2024, so RefreshDatabase ran migrate:fresh against the real .env database and wiped it on every local test run. Enable the overrides, let the special :memory: identifier bypass database_path() resolution and the boot-time touch(), and add a TestCase guard that aborts the suite unless it is pointed at in-memory sqlite. ItemExportTest only ever passed by reading the populated dev database; seed the root dashboard item it depends on so it passes on a fresh DB.
113 lines
2.8 KiB
PHP
113 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Item;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
class ItemExportTest extends TestCase
|
|
{
|
|
|
|
use RefreshDatabase;
|
|
|
|
public function test_returns_empty_jsonarray_when_there_are_no_items_in_the_db(): void
|
|
{
|
|
$response = $this->get('api/item');
|
|
|
|
$response->assertJsonCount(0);
|
|
}
|
|
|
|
public function test_returns_exactly_the_defined_fields(): void
|
|
{
|
|
$exampleItem = [
|
|
"appdescription" => "Description",
|
|
"appid" => "123",
|
|
"colour" => "#000",
|
|
"description" => "Description",
|
|
"title" => "Item Title",
|
|
"url" => "http://gorczany.com/nihil-rerum-distinctio-voluptate-assumenda-accusantium-exercitationem"
|
|
];
|
|
Item::factory()
|
|
->create($exampleItem);
|
|
|
|
$response = $this->get('api/item');
|
|
|
|
$response->assertExactJson([$exampleItem + ["tags" => []]]);
|
|
}
|
|
|
|
public function test_exports_assigned_tag_titles_excluding_the_root_tag(): void
|
|
{
|
|
// Mirror the root/default dashboard row that production seeds (id 0),
|
|
// so the item_tag pivot's foreign key to items.id is satisfied on a
|
|
// fresh in-memory database.
|
|
DB::table('items')->insert([
|
|
'id' => 0,
|
|
'title' => 'app.dashboard',
|
|
'url' => '',
|
|
'type' => 1,
|
|
'user_id' => 0,
|
|
'pinned' => 0,
|
|
]);
|
|
|
|
$item = Item::factory()
|
|
->create([
|
|
'title' => 'Tagged Item',
|
|
]);
|
|
$tag = Item::factory()
|
|
->create([
|
|
'type' => 1,
|
|
'title' => 'Media',
|
|
]);
|
|
|
|
// Assign both the root/default dashboard (id 0) and the Media tag.
|
|
$item->parents()->sync([0, $tag->id]);
|
|
|
|
$response = $this->get('api/item');
|
|
|
|
$response->assertJsonCount(1);
|
|
$response->assertJsonPath('0.tags', ['Media']);
|
|
}
|
|
|
|
public function test_returns_all_items(): void
|
|
{
|
|
Item::factory()
|
|
->count(3)
|
|
->create();
|
|
|
|
$response = $this->get('api/item');
|
|
|
|
$response->assertJsonCount(3);
|
|
}
|
|
|
|
public function test_does_not_return_deleted_item(): void
|
|
{
|
|
Item::factory()
|
|
->create([
|
|
'deleted_at' => Date::create('1970')
|
|
]);
|
|
Item::factory()
|
|
->create();
|
|
|
|
$response = $this->get('api/item');
|
|
|
|
$response->assertJsonCount(1);
|
|
}
|
|
|
|
public function test_does_not_return_tags(): void
|
|
{
|
|
Item::factory()
|
|
->create([
|
|
'type' => 1
|
|
]);
|
|
Item::factory()
|
|
->create();
|
|
|
|
$response = $this->get('api/item');
|
|
|
|
$response->assertJsonCount(1);
|
|
}
|
|
}
|