1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-01-17 21:28:30 +01:00

Make imported tags private if specified in the user settings (#588)

This commit is contained in:
Kovah 2023-01-22 11:35:59 +01:00
parent ae83084bb0
commit e902e7c6f0
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B
3 changed files with 45 additions and 14 deletions

View File

@ -79,6 +79,7 @@ class ImportHtmlBookmarks
$newTag = Tag::firstOrCreate([
'user_id' => $userId,
'name' => $tag,
'is_private' => usersettings('tags_private_default') === '1',
]);
$newTags[] = $newTag->id;
}

View File

@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Laravel\Fortify\TwoFactorAuthenticatable;
/**
@ -52,7 +53,7 @@ class User extends Authenticatable
return $this->hasMany(Setting::class, 'user_id', 'id');
}
public function settings(): \Illuminate\Support\Collection
public function settings(): Collection
{
if ($this->rawSettings->isEmpty()) {
$this->load('rawSettings');

View File

@ -2,12 +2,12 @@
namespace Tests\Controller\App;
use App\Helper\HtmlMeta;
use App\Models\Link;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Http;
use Illuminate\Testing\TestResponse;
use Tests\TestCase;
class ImportControllerTest extends TestCase
@ -28,11 +28,48 @@ class ImportControllerTest extends TestCase
{
$response = $this->get('import');
$response->assertOk()
->assertSee('Import');
$response->assertOk()->assertSee('Import');
}
public function testValidImportActionResponse(): void
{
$response = $this->importBookmarks();
$response->assertOk()
->assertJson([
'success' => true,
]);
$this->assertDatabaseCount('links', 5);
$this->assertDatabaseCount('tags', 18);
}
public function testImportWithPrivateDefaults(): void
{
Setting::create(['user_id' => 1, 'key' => 'links_private_default', 'value' => '1']);
Setting::create(['user_id' => 1, 'key' => 'tags_private_default', 'value' => '1']);
$response = $this->importBookmarks();
$response->assertOk()
->assertJson([
'success' => true,
]);
$this->assertDatabaseCount('links', 5);
$this->assertDatabaseHas('links', [
'url' => 'https://loader.io/',
'is_private' => true,
]);
$this->assertDatabaseHas('tags', [
'name' => 'article',
'is_private' => '1',
]);
}
protected function importBookmarks(): TestResponse
{
$testHtml = '<!DOCTYPE html><head><title>DuckDuckGo</title></head></html>';
Http::fake(['*' => Http::response($testHtml)]);
@ -40,18 +77,10 @@ class ImportControllerTest extends TestCase
$exampleData = file_get_contents(__DIR__ . '/data/import_example.html');
$file = UploadedFile::fake()->createWithContent('import_example.html', $exampleData);
$response = $this->post('import', [
return $this->post('import', [
'import-file' => $file,
], [
'Accept' => 'application/json',
]);
$response->assertOk()
->assertJson([
'success' => true,
]);
$linkCount = Link::count();
$this->assertEquals(5, $linkCount);
}
}