Skip to content
Snippets Groups Projects
Commit 54388128 authored by kerdo's avatar kerdo
Browse files

Merge branch '22-fr-12-view-own-advertisements-fixing' into 'main'

Improved BDD and TDD tests. Very slight changes in my properties page.

Closes #22

See merge request !23
parents b7624e3e 97606699
No related branches found
No related tags found
1 merge request!23Improved BDD and TDD tests. Very slight changes in my properties page.
Pipeline #45308 passed
......@@ -61,7 +61,8 @@ defmodule MyAdvertisementsContext do
fill_field({:id, "floor_count"}, state[:data][:floor_count])
fill_field({:id, "price"}, state[:data][:price])
click({:id, "submit_button"})
{:ok, state}
property = Repo.get_by(Property, title: state[:data][:title])
{:ok, state |> Map.put(:property, property)}
end
when_ ~r/^I navigate to my profile page$/, fn state ->
......@@ -75,7 +76,7 @@ defmodule MyAdvertisementsContext do
end
then_ ~r/^I should be redirected to my properties page$/, fn state ->
assert current_url() == "http://localhost:4001/me/properties"
assert current_path() == "/me/properties"
{:ok, state}
end
......@@ -89,6 +90,66 @@ defmodule MyAdvertisementsContext do
{:ok, state}
end
given_ ~r/^I am logged in as "(?<email>[^"]+)"$/, fn state, %{email: email} ->
user = Repo.get_by(User, email: email)
setup_session(email, "password")
{:ok, Map.put(state, :current_user, user)}
end
given_ ~r/^I log out$/, fn state ->
navigate_to("/logout")
{:ok, state}
end
and_ ~r/^I should not see other user's properties$/, fn state ->
advertisement = state[:data]
refute visible_in_page? ~r/#{advertisement.title}/
refute visible_in_page? ~r/#{advertisement.description}/
refute visible_in_page? ~r/#{advertisement.price}/
refute visible_in_page? ~r/#{advertisement.room_count}/
refute visible_in_page? ~r/#{advertisement.area}/
{:ok, state}
end
and_ ~r/^I click to View more button$/, fn state ->
view_state = state[:property]
click({:id, "edit-#{view_state.reference}"})
{:ok, state}
end
then_ ~r/^I should be redirected to property details page$/, fn state ->
view_state = state[:property]
assert current_path() == "/properties/#{view_state.reference}"
{:ok, state}
end
and_ ~r/^I should see the property details$/, fn state ->
advertisement = state[:property]
assert visible_in_page? ~r/#{advertisement.title}/
assert visible_in_page? ~r/#{advertisement.description}/
assert visible_in_page? ~r/#{advertisement.location}/
assert visible_in_page? ~r/#{advertisement.price}/
assert visible_in_page? ~r/#{advertisement.room_count}/
assert visible_in_page? ~r/#{advertisement.area}/
assert visible_in_page? ~r/#{advertisement.type}/
assert visible_in_page? ~r/#{advertisement.property_type}/
user = Repo.get_by(User, id: advertisement.user_id)
assert visible_in_page? ~r/#{user.name}/
assert visible_in_page? ~r/#{user.surname}/
assert visible_in_page? ~r/#{user.phone_number}/
assert visible_in_page? ~r/#{user.email}/
{:ok, state}
end
test "User cannot view non-existent property details", %{conn: conn, user: user} do
# Login user
conn = conn |> setup_session(user)
# Try to access non-existent property
conn = get(conn, "/properties/non-existent-reference")
assert html_response(conn, 500) =~ "Not found"
end
defp setup_session(email, password) do
navigate_to("/login")
fill_field({:id, "email"}, email)
......
......@@ -12,4 +12,38 @@ Feature: FR-12 View Own Advertisements
When I navigate to my profile page
And I click on My properties link
Then I should be redirected to my properties page
And I should see a list of all my properties
\ No newline at end of file
And I should see a list of all my properties
And I log out
Scenario: Authenticated user should not view other people's property listings from profile
Given there exists following accounts
| name | surname | birth_date | phone_number | email | password | confirm_password |
| First | User | 2000-01-01 | 000 | first.user@gmail.com | password | password |
| Second | User | 2000-01-01 | 111 | second.user@gmail.com | password | password |
Given I am logged in as "first.user@gmail.com"
Given I want to insert the following data
| title | description | type | property_type | location | room_count | area | floor | floor_count | price |
| Apartment | Small apartment in Tartu for rent | rent | apartment | Tartu, Estonia | 1 | 13 | 2 | 4 | 430 |
Given I created given properties
Given I log out
Given I am logged in as "second.user@gmail.com"
When I navigate to my profile page
And I click on My properties link
Then I should be redirected to my properties page
And I should not see other user's properties
And I log out
Scenario: Authenticated user should view details of own advertisement
Given there exists following accounts
| name | surname | birth_date | phone_number | email | password | confirm_password |
| Existing | Account | 2000-01-01 | 000 | existing.account@gmail.com | password | password |
Given I am logged in
Given I want to insert the following data
| title | description | type | property_type | location | room_count | area | floor | floor_count | price |
| Apartment | Small apartment in Tartu for rent | rent | apartment | Tartu, Estonia | 1 | 13 | 2 | 4 | 430 |
Given I created given properties
When I navigate to my profile page
And I click on My properties link
And I click to View more button
Then I should be redirected to property details page
And I should see the property details
\ No newline at end of file
......@@ -8,6 +8,8 @@
<h2 class="font-bold"><%= property.title %></h2>
<p><%= property.description %></p>
<p class="italic"><%= property.location %></p>
<div class="flex flex-row gap-x-2">
<span><%= property.price %></span>
<span><%= property.room_count %> rooms</span>
......@@ -15,9 +17,8 @@
</div>
<div class="flex flex-row justify-end">
<!-- TODO: Implement linking -->
<.link href={~p"/properties/#{property.reference}"}>
<.button type="button" class="text-white rounded px-4 py-2">View more</.button>
<.button type="button" class="text-white rounded px-4 py-2" id={ "edit-#{property.reference}" }>View more</.button>
</.link>
</div>
</div>
......
......@@ -111,6 +111,29 @@ defmodule PropTrackrWeb.MyPropertiesControllerTest do
assert html_response(conn, 200) =~ ~r/You are not logged in!/
end
test "Authenticated user can view own property details", %{conn: conn, user: user, property1: property1} do
# Login user
conn = conn |> setup_session(user)
# Access property details page
conn = get(conn, "/properties/#{property1.reference}")
response = html_response(conn, 200)
# Check if all property details are visible
assert response =~ property1.title
assert response =~ property1.description
assert response =~ property1.location
assert response =~ Float.to_string(property1.price)
assert response =~ Integer.to_string(property1.room_count)
assert response =~ Float.to_string(property1.area)
assert response =~ String.capitalize(to_string(property1.type))
assert response =~ String.capitalize(to_string(property1.property_type))
assert response =~ user.name
assert response =~ user.surname
assert response =~ user.phone_number
assert response =~ user.email
end
defp setup_session(conn, user) do
conn = conn |> post("/login", email: user.email, password: user.password)
conn = get conn, redirected_to(conn)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment