Skip to content

Commit

Permalink
Updated tests to work with the latest changes
Browse files Browse the repository at this point in the history
Updated tests to specify note's description and author when creating note (to follow the latest scheme).
  • Loading branch information
nenad-vujicic committed Jan 8, 2025
1 parent 3273d25 commit 1d5bade
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
12 changes: 6 additions & 6 deletions test/controllers/api/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def test_comment_with_notifications_success
second_user = create(:user)
third_user = create(:user)

note_with_comments_by_users = create(:note) do |note|
note_with_comments_by_users = create(:note, :author => first_user) do |note|
create(:note_comment, :note => note, :author => first_user)
create(:note_comment, :note => note, :author => second_user)
end
Expand Down Expand Up @@ -664,10 +664,10 @@ def test_show_success
end

def test_show_hidden_comment
note_with_hidden_comment = create(:note) do |note|
create(:note_comment, :note => note, :body => "Valid comment for hidden note")
create(:note_comment, :note => note, :visible => false)
create(:note_comment, :note => note, :body => "Another valid comment for hidden note")
note_with_hidden_comment = create(:note, :description => "Test Note description") do |note|
create(:note_comment, :note => note, :event => "opened", :body => "")
create(:note_comment, :note => note, :event => "commented", :visible => false, :body => "Valid comment for hidden note")
create(:note_comment, :note => note, :event => "commented", :body => "Another valid comment for hidden note")
end

get api_note_path(note_with_hidden_comment, :format => "json")
Expand All @@ -677,7 +677,7 @@ def test_show_hidden_comment
assert_equal "Feature", js["type"]
assert_equal note_with_hidden_comment.id, js["properties"]["id"]
assert_equal 2, js["properties"]["comments"].count
assert_equal "Valid comment for hidden note", js["properties"]["comments"][0]["text"]
assert_equal "Test Note description", js["properties"]["comments"][0]["text"]
assert_equal "Another valid comment for hidden note", js["properties"]["comments"][1]["text"]
end

Expand Down
1 change: 1 addition & 0 deletions test/factories/notes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
factory :note do
latitude { 1 * GeoRecord::SCALE }
longitude { 1 * GeoRecord::SCALE }
description { "This is note's description!" }
# tile { QuadTile.tile_for_point(1,1) }

trait :closed do
Expand Down
16 changes: 8 additions & 8 deletions test/models/note_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ def test_closed?
end

def test_author
comment = create(:note_comment)
assert_nil comment.note.author
note = create(:note)
assert_nil note.author

user = create(:user)
comment = create(:note_comment, :author => user)
assert_equal user, comment.note.author
note = create(:note, :author => user)
assert_equal user, note.author
end

def test_author_ip
comment = create(:note_comment)
assert_nil comment.note.author_ip
note = create(:note)
assert_nil note.author_ip

comment = create(:note_comment, :author_ip => IPAddr.new("192.168.1.1"))
assert_equal IPAddr.new("192.168.1.1"), comment.note.author_ip
note = create(:note, :user_ip => IPAddr.new("192.168.1.1"))
assert_equal IPAddr.new("192.168.1.1"), note.author_ip
end

# Ensure the lat/lon is formatted as a decimal e.g. not 4.0e-05
Expand Down
8 changes: 4 additions & 4 deletions test/system/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class IndexTest < ApplicationSystemTestCase

test "can navigate from hidden note to visible note" do
sign_in_as(create(:moderator_user))
hidden_note = create(:note, :status => "hidden")
create(:note_comment, :note => hidden_note, :body => "this-is-a-hidden-note")
hidden_note = create(:note, :status => "hidden", :description => "this-is-a-hidden-note")
create(:note_comment, :note => hidden_note, :event => "opened", :body => "")
position = (1.003 * GeoRecord::SCALE).to_i
visible_note = create(:note, :latitude => position, :longitude => position)
create(:note_comment, :note => visible_note, :body => "this-is-a-visible-note")
visible_note = create(:note, :latitude => position, :longitude => position, :description => "this-is-a-visible-note")
create(:note_comment, :note => visible_note, :event => "opened", :body => "")

visit root_path(:anchor => "map=15/1/1") # view place of hidden note in case it is not rendered during note_path(hidden_note)
visit note_path(hidden_note)
Expand Down
4 changes: 2 additions & 2 deletions test/system/report_note_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class ReportNoteTest < ApplicationSystemTestCase
def test_no_link_when_not_logged_in
note = create(:note_with_comments)
note = create(:note_with_comments, :description => "TD 1")
visit note_path(note)
assert_content note.comments.first.body
assert_content "TD 1"

assert_no_content I18n.t("notes.show.report")
end
Expand Down
4 changes: 2 additions & 2 deletions test/system/report_user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class ReportUserTest < ApplicationSystemTestCase
def test_no_link_when_not_logged_in
note = create(:note_with_comments)
note = create(:note_with_comments, :description => "TD 1")
visit note_path(note)
assert_content note.comments.first.body
assert_content "TD 1"

assert_no_content I18n.t("users.show.report")
end
Expand Down

0 comments on commit 1d5bade

Please sign in to comment.