fix(link): nullable field update, redis test key isolation
parent
69e6318db5
commit
b59dbfd95b
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in New Issue