hackatime/test/controllers/profiles_controller_test.rb
Mahad Kalam e3456be187
goaaaal! (#985)
* Add goals

* Fix up some migrations

* Formatting

* Simplify migration

* Update test/controllers/settings_goals_controller_test.rb

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Update test/controllers/settings_goals_controller_test.rb

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Fix svelte-check issues, make CI less janky on dev

* svelte-check/fix tests

* Fix N+1s

* Formatting!

* More tests, fix anonymization and N+1

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-19 18:47:01 +00:00

62 lines
2 KiB
Ruby

require "test_helper"
class ProfilesControllerTest < ActionDispatch::IntegrationTest
test "shows inertia profile page for existing user" do
user = User.create!(username: "profile_user_#{SecureRandom.hex(4)}", profile_bio: "I like building tools")
get profile_path(user.username)
assert_response :success
assert_inertia_component "Profiles/Show"
assert_inertia_prop "profile_visible", true
assert_equal "I like building tools", inertia_page.dig("props", "profile", "bio")
end
test "returns inertia not found for unknown profile" do
get profile_path("missing_#{SecureRandom.hex(4)}")
assert_response :not_found
assert_inertia_component "Errors/NotFound"
end
test "shows bio and socials while hiding stats for private profiles" do
user = User.create!(
username: "priv_#{SecureRandom.hex(3)}",
allow_public_stats_lookup: false,
profile_bio: "Private stats, public profile.",
profile_github_url: "https://github.com/hackclub"
)
get profile_path(user.username)
assert_response :success
assert_inertia_component "Profiles/Show"
assert_inertia_prop "profile_visible", false
assert_equal "Private stats, public profile.", inertia_page.dig("props", "profile", "bio")
assert_equal "GitHub", inertia_page.dig("props", "profile", "social_links", 0, "label")
assert_nil inertia_page.dig("props", "stats")
end
test "shows stats to owner even when profile is private" do
user = User.create!(
username: "own_#{SecureRandom.hex(3)}",
allow_public_stats_lookup: false
)
sign_in_as(user)
get profile_path(user.username)
assert_response :success
assert_inertia_component "Profiles/Show"
assert_inertia_prop "profile_visible", true
assert_inertia_prop "is_own_profile", true
end
private
def sign_in_as(user)
token = user.sign_in_tokens.create!(auth_type: :email)
get auth_token_path(token: token.token)
assert_equal user.id, session[:user_id]
end
end