user = User::factory()->create(); $workspace = Workspace::factory()->create(['user_id' => $this->user->id]); $this->user->update(['current_workspace_id' => $workspace->id]); }); test('returns a link card for a valid url', function () { Http::fake([ 'https://example.com' => Http::response( '
' .'' .'', 200, ), ]); $this->actingAs($this->user) ->postJson(route('app.posts.link-preview'), ['url' => 'https://example.com']) ->assertOk() ->assertJson([ 'uri' => 'https://example.com', 'domain' => 'example.com', 'title' => 'Example', 'description' => 'Desc', 'image' => 'https://example.com/card.png', ]); }); test('returns no content when there is no card', function () { $this->actingAs($this->user) ->postJson(route('app.posts.link-preview'), ['url' => 'http://127.0.0.1/private']) ->assertNoContent(); }); test('validates that a url is required', function () { $this->actingAs($this->user) ->postJson(route('app.posts.link-preview'), []) ->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); }); test('requires authentication', function () { $this->postJson(route('app.posts.link-preview'), ['url' => 'https://example.com']) ->assertUnauthorized(); });