Skip to content

Commit

Permalink
Fix code coverage issues
Browse files Browse the repository at this point in the history
Fix code coverage issues
  • Loading branch information
jayjay-w committed Feb 26, 2025
1 parent 7ca3e79 commit a277f1f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/controllers/graphql_controller_8_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ def setup
assert_not_nil JSON.parse(@response.body)['data']['team']['verification_statuses']
end

test "should get tags from media" do
admin_user = create_user is_admin: true
t = create_team
p = create_project team: t
pm = create_project_media project: p
c = create_tag annotated: pm, fragment: 't=10,20'
authenticate_with_user(admin_user)
query = "query { project_media(ids: \"#{pm.id},#{p.id}\") { tags(first: 10) { edges { node { parsed_fragment } } } } }"
post :create, params: { query: query, team: t.slug }
assert_response :success
assert_equal({ 't' => [10, 20] }, JSON.parse(@response.body)['data']['project_media']['tags']['edges'][0]['node']['parsed_fragment'])
end

test "should get OCR" do
b = create_alegre_bot(name: 'alegre', login: 'alegre')
b.approve!
Expand Down
26 changes: 26 additions & 0 deletions test/models/tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,30 @@ def setup
Tag.create_project_media_tags(pm.id, ['one', 'two', 'three'].to_json)
assert_equal 3, pm.reload.annotations('tag').count
end

test "all_sorted returns tags sorted by created_at" do
t1 = create_tag(tag: 'a')
t1.update_columns(created_at: 2.days.ago)
t2 = create_tag(tag: 'b')
t2.update_columns(created_at: 1.day.ago)

sorted_asc = Tag.all_sorted('asc', 'created_at')
assert_operator sorted_asc.first.created_at, :<, sorted_asc.last.created_at

sorted_desc = Tag.all_sorted('desc', 'created_at')
assert_operator sorted_desc.first.created_at, :>, sorted_desc.last.created_at
end

test "current_team returns the team when annotated is ProjectMedia" do
u = create_user
team = create_team
p = create_project(team: team)
pm = create_project_media(project: p, user: u)

tag = create_tag(annotated: pm)
tag.annotated_type = 'ProjectMedia'
tag.save

assert_equal team, tag.current_team
end
end
11 changes: 11 additions & 0 deletions test/models/team_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1590,4 +1590,15 @@ def setup
t = create_team
assert_equal [], t.search_for_similar_articles('Test')
end

test "should extract slug from URL using URI.extract" do
url = "https://example.com/my-team"
assert_equal "my-team", Team.slug_from_url(url)

text_with_url = "Some text [http://example.com/team-slug] more text"
assert_equal "team-slug", Team.slug_from_url(text_with_url)

complex_url = "https://example.com/team123/extra/info"
assert_equal "team123", Team.slug_from_url(complex_url)
end
end

0 comments on commit a277f1f

Please sign in to comment.