From b59dbfd95b9962ff40ab1191f68d5e2d0c5e7deb Mon Sep 17 00:00:00 2001 From: boban Date: Sat, 16 May 2026 00:48:15 +0200 Subject: [PATCH] fix(link): nullable field update, redis test key isolation --- app/Domains/Link/Actions/UpdateLink.php | 27 ++++++++++++------------ tests/Unit/Link/LinkCacheServiceTest.php | 14 +++++++++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/Domains/Link/Actions/UpdateLink.php b/app/Domains/Link/Actions/UpdateLink.php index 58bf9a5..2b14986 100644 --- a/app/Domains/Link/Actions/UpdateLink.php +++ b/app/Domains/Link/Actions/UpdateLink.php @@ -12,22 +12,21 @@ class UpdateLink public function handle(Link $link, User $updater, array $data): Link { - $link->update([ - 'target_url' => $data['target_url'] ?? $link->target_url, - 'title' => $data['title'] ?? $link->title, - 'description' => $data['description'] ?? $link->description, - 'status' => $data['status'] ?? $link->status, - 'expires_at' => $data['expires_at'] ?? $link->expires_at, - 'click_limit' => $data['click_limit'] ?? $link->click_limit, - 'rules' => $data['rules'] ?? $link->rules, - 'pixel_config' => $data['pixel_config'] ?? $link->pixel_config, - 'tags' => $data['tags'] ?? $link->tags, - 'updated_by' => $updater->id, - ]); + $fillable = ['target_url', 'title', 'description', 'status', 'expires_at', 'click_limit', 'rules', 'pixel_config', 'tags']; + + $updates = ['updated_by' => $updater->id]; + foreach ($fillable as $field) { + if (array_key_exists($field, $data)) { + $updates[$field] = $data[$field]; + } + } + + $link->update($updates); $this->cache->forget($link->slug, $link->domain_id); - $this->cache->warmFromLink($link->fresh()); + $fresh = $link->fresh(); + $this->cache->warmFromLink($fresh); - return $link->fresh(); + return $fresh; } } diff --git a/tests/Unit/Link/LinkCacheServiceTest.php b/tests/Unit/Link/LinkCacheServiceTest.php index 337427d..39e924f 100644 --- a/tests/Unit/Link/LinkCacheServiceTest.php +++ b/tests/Unit/Link/LinkCacheServiceTest.php @@ -2,9 +2,17 @@ use App\Domains\Link\Services\LinkCacheService; use Illuminate\Support\Facades\Redis; -use Tests\TestCase; -uses(TestCase::class); +uses(Tests\TestCase::class); + +beforeEach(function () { + // Clean up test keys + Redis::del('link:testslug'); +}); + +afterEach(function () { + Redis::del('link:testslug'); +}); it('stores link data in redis hash', function () { $service = new LinkCacheService; @@ -12,7 +20,7 @@ it('stores link data in redis hash', function () { $service->put('testslug', [ 'target' => 'https://example.com', 'status' => 'active', - 'workspace_id' => 1, + 'workspace_id' => '1', ]); $data = $service->get('testslug');