Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PropTrackr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kerdo
PropTrackr
Commits
2ecac50d
Commit
2ecac50d
authored
4 months ago
by
kerdo
Browse files
Options
Downloads
Plain Diff
Merge branch '22-fr-12-view-own-advertisements' into 'main'
Added TDD for "FR-12: View Own Advertisements" Closes
#22
See merge request
!18
parents
ea203658
2c42b894
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
Added TDD for "FR-12: View Own Advertisements"
Pipeline
#45121
passed
4 months ago
Stage: build
Stage: test
Changes
1
Pipelines
8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/proptrackr_web/controllers/my_advertisements_controller_test.exs
+119
-0
119 additions, 0 deletions
...ckr_web/controllers/my_advertisements_controller_test.exs
with
119 additions
and
0 deletions
test/proptrackr_web/controllers/my_advertisements_controller_test.exs
0 → 100644
+
119
−
0
View file @
2ecac50d
defmodule
PropTrackrWeb
.
MyPropertiesControllerTest
do
use
PropTrackrWeb
.
ConnCase
alias
PropTrackr
.
Accounts
.
User
alias
PropTrackr
.
Properties
.
Property
alias
PropTrackr
.
Repo
@valid_property
%{
title:
"Apartment"
,
description:
"Small apartment with a beautiful view of the city center"
,
type:
"rent"
,
property_type:
"apartment"
,
location:
"Tartu, Estonia"
,
room_count:
1
,
area:
13.0
,
floor:
2
,
floor_count:
4
,
price:
430.0
,
}
setup
do
# Create test user
user
=
%
User
{
name:
"Test"
,
surname:
"User"
,
birth_date:
"2000-01-01"
,
phone_number:
"000"
,
bio:
"Yo"
,
email:
"test.user@gmail.com"
,
password:
"testing"
,
confirm_password:
"testing"
,
}
user
=
Repo
.
insert!
(
user
)
# Create another user to test property visibility
other_user
=
%
User
{
name:
"Other"
,
surname:
"User"
,
birth_date:
"2000-01-01"
,
phone_number:
"111"
,
bio:
"Hey"
,
email:
"other.user@gmail.com"
,
password:
"testing"
,
confirm_password:
"testing"
,
}
other_user
=
Repo
.
insert!
(
other_user
)
# Create some test properties for the main user
property1
=
%
Property
{
reference:
Ecto
.
UUID
.
generate
(),
user_id:
user
.
id
}
property1
=
property1
|>
Property
.
changeset
(
@valid_property
)
|>
Repo
.
insert!
()
property2
=
%
Property
{
reference:
Ecto
.
UUID
.
generate
(),
user_id:
user
.
id
}
property2
=
property2
|>
Property
.
changeset
(%{
@valid_property
|
title:
"Second Property"
,
price:
500.0
})
|>
Repo
.
insert!
()
# Create a property for the other user
other_property
=
%
Property
{
reference:
Ecto
.
UUID
.
generate
(),
user_id:
other_user
.
id
}
other_property
=
other_property
|>
Property
.
changeset
(%{
@valid_property
|
title:
"Other User Property"
})
|>
Repo
.
insert!
()
{
:ok
,
%{
user:
user
,
other_user:
other_user
,
property1:
property1
,
property2:
property2
,
other_property:
other_property
}}
end
test
"Authenticated user can view their properties"
,
%{
conn:
conn
,
user:
user
,
property1:
property1
,
property2:
property2
,
other_property:
other_property
}
do
# Login user
conn
=
conn
|>
setup_session
(
user
)
conn
=
get
(
conn
,
"/me"
)
response
=
html_response
(
conn
,
200
)
assert
response
=~
~s|id="my_properties"|
# Access my properties page
conn
=
get
(
conn
,
"/me/properties"
)
assert
html_response
(
conn
,
200
)
=~
"My Properties"
# Assert successful response
response
=
html_response
(
conn
,
200
)
# Check if user's properties are visible
assert
response
=~
property1
.
title
assert
response
=~
property2
.
title
assert
response
=~
Float
.
to_string
(
property1
.
price
)
assert
response
=~
Float
.
to_string
(
property2
.
price
)
assert
response
=~
Float
.
to_string
(
property1
.
area
)
assert
response
=~
Float
.
to_string
(
property1
.
area
)
# Make sure other user's property is not visible
refute
response
=~
other_property
.
title
end
test
"Unauthorized user cannot access my properties page"
,
%{
conn:
conn
}
do
conn
=
get
conn
,
"/me"
assert
redirected_to
(
conn
)
==
"/login"
conn
=
get
conn
,
redirected_to
(
conn
)
assert
html_response
(
conn
,
200
)
=~
~r/You are not logged in!/
end
defp
setup_session
(
conn
,
user
)
do
conn
=
conn
|>
post
(
"/login"
,
email:
user
.
email
,
password:
user
.
password
)
conn
=
get
conn
,
redirected_to
(
conn
)
conn
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment