throw new ConnectionException('unreachable')); $remoteUrl = 'https://remote.example/users/alice'; $profile = Profile::factory()->create([ 'user_id' => null, 'domain' => 'remote.example', 'remote_url' => $remoteUrl, 'last_fetched_at' => now()->subDays(5), // stale -> needsFetch true ]); $result = Helpers::getOrFetchRemoteProfile($remoteUrl); expect($result)->not->toBeNull(); expect($result->id)->toBe($profile->id); }); it('returns the existing profile without fetching when fresh', function () { Http::fake(fn () => throw new ConnectionException('should not be called')); $remoteUrl = 'https://remote.example/users/bob'; $profile = Profile::factory()->create([ 'user_id' => null, 'domain' => 'remote.example', 'remote_url' => $remoteUrl, 'last_fetched_at' => now()->subMinutes(5), // fresh -> no fetch ]); $result = Helpers::getOrFetchRemoteProfile($remoteUrl); expect($result->id)->toBe($profile->id); Http::assertNothingSent(); });