Skip to content

Commit

Permalink
Re-adding integration tests for review applications view
Browse files Browse the repository at this point in the history
cleanup - group tests
  • Loading branch information
nsiwnf committed Mar 18, 2024
1 parent 828cd38 commit 9170c1d
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 182 deletions.
2 changes: 1 addition & 1 deletion test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
profile_show { true }
status { 1 }

adopter_account
adopter_account { association :adopter_account, :with_adopter_foster_profile }
pet

trait :adoption_pending do
Expand Down
155 changes: 79 additions & 76 deletions test/integration/adoptable_pet_show_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,120 +7,123 @@ class AdoptablePetShowTest < ActionDispatch::IntegrationTest
@pet_in_draft = create(:pet, published: false)
@pet_pending_adoption = create(:pet, :adoption_pending)
@adopted_pet = create(:pet, :adopted)
@staff_user = create(:staff_account).user
@adopter_user = create(:adopter_account).user
create(:adopter_foster_profile, adopter_account: @adopter_user.adopter_account)
end

teardown do
check_messages
:after_teardown
end

test "unauthenticated users can see an available pet" do
get adoptable_pet_path(@available_pet)
context "unauthenticated user" do
should "see an available pet" do
get adoptable_pet_path(@available_pet)

assert_response :success
assert_cannot_apply_to_adopt
end
assert_response :success
assert_cannot_apply_to_adopt
end

test "unauthenticated users can see a pet with a pending adoption" do
get adoptable_pet_path(@pet_pending_adoption)
should "see a pet with a pending adoption" do
get adoptable_pet_path(@pet_pending_adoption)

assert_response :success
end
assert_response :success
end

test "unauthenticated users cannot see an unpublished pet" do
get adoptable_pet_path(@pet_in_draft)
should "not see an unpublished pet" do
get adoptable_pet_path(@pet_in_draft)

assert_response :redirect
end
assert_response :redirect
end

test "unauthenticated users cannot see an adopted pet" do
get adoptable_pet_path(@adopted_pet)
should "not see an adopted pet" do
get adoptable_pet_path(@adopted_pet)

assert_response :redirect
assert_response :redirect
end
end

test "staff can see an available pet" do
sign_in @staff_user
get adoptable_pet_path(@available_pet)
context "staff" do
setup do
sign_in create(:staff_account).user
end

assert_response :success
end
should "see an available pet" do
get adoptable_pet_path(@available_pet)

test "staff can see a pet with a pending adoption" do
sign_in @staff_user
get adoptable_pet_path(@pet_pending_adoption)
assert_response :success
end

assert_response :success
assert_cannot_apply_to_adopt
end
should "see a pet with a pending adoption" do
get adoptable_pet_path(@pet_pending_adoption)

test "staff cannot see an unpublished pet" do
sign_in @staff_user
get adoptable_pet_path(@pet_in_draft)
assert_response :success
assert_cannot_apply_to_adopt
end

assert_response :redirect
end
should "not see an unpublished pet" do
get adoptable_pet_path(@pet_in_draft)

assert_response :redirect
end

test "staff cannot see an adopted pet" do
sign_in @staff_user
get adoptable_pet_path(@adopted_pet)
should "not see an adopted pet" do
get adoptable_pet_path(@adopted_pet)

assert_response :redirect
assert_response :redirect
end
end

test "adopter can see and apply to an available pet" do
sign_in @adopter_user
get adoptable_pet_path(@available_pet)
context "an adopter" do
setup do
adopter_user = create(:adopter_account).user
create(:adopter_foster_profile, adopter_account: adopter_user.adopter_account)

assert_response :success
assert_can_apply_to_adopt
end
sign_in adopter_user
end

test "adopter can see a pet with a pending adoption" do
sign_in @adopter_user
get adoptable_pet_path(@pet_pending_adoption)
should "see and apply to an available pet" do
get adoptable_pet_path(@available_pet)
assert_response :success
assert_can_apply_to_adopt
end

assert_response :success
end
should "see a pet with a pending adoption" do
get adoptable_pet_path(@pet_pending_adoption)

test "adopter cannot see an unpublished pet" do
sign_in @adopter_user
get adoptable_pet_path(@pet_in_draft)
assert_response :success
end

assert_response :redirect
end
should "not see an unpublished pet" do
get adoptable_pet_path(@pet_in_draft)

test "adopter cannot see an adopted pet" do
sign_in @adopter_user
get adoptable_pet_path(@adopted_pet)
assert_response :redirect
end

assert_response :redirect
end
should "not see an adopted pet" do
get adoptable_pet_path(@adopted_pet)

test "adopter application sees application status" do
skip("while new ui is implemented")
# pet = create(:pet, :adoption_pending)
# user = create(:user, :adopter_with_profile, organization: pet.organization)
# create(:adopter_application, adopter_account: user.adopter_account, pet: pet, status: :awaiting_review)
# sign_in user
assert_response :redirect
end

# get "/adoptable_pets/#{pet.id}"
should_eventually "adopter application sees application status" do
# pet = create(:pet, :adoption_pending)
# user = create(:user, :adopter_with_profile, organization: pet.organization)
# create(:adopter_application, adopter_account: user.adopter_account, pet: pet, status: :awaiting_review)
# sign_in user

# check_messages
# assert_select "h4.me-2", "Application Awaiting Review"
end
# get "/adoptable_pets/#{pet.id}"

# check_messages
# assert_select "h4.me-2", "Application Awaiting Review"
end

test "pet name shows adoption pending if it has any applications with that status" do
skip("while new ui is implemented")
# pet = create(:pet, :adoption_pending)
should_eventually "pet name shows adoption pending if it has any applications with that status" do
# pet = create(:pet, :adoption_pending)

# get "/adoptable_pets/#{pet.id}"
# get "/adoptable_pets/#{pet.id}"

# check_messages
# assert_select "h1", "#{pet.name} (Adoption Pending)"
# check_messages
# assert_select "h1", "#{pet.name} (Adoption Pending)"
end
end

def assert_can_apply_to_adopt
Expand Down
Loading

0 comments on commit 9170c1d

Please sign in to comment.