Skip to content

Commit

Permalink
Remove references to Comment in /test
Browse files Browse the repository at this point in the history
Remove all references to `Comment` and `create_comment` from our tests.
  • Loading branch information
jayjay-w committed Feb 18, 2025
1 parent 6d1f193 commit cf46953
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 714 deletions.
2 changes: 1 addition & 1 deletion config/initializers/field_validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def field_validator_type_bot_response_format
errormsg = I18n.t(:task_suggestion_invalid_value)
begin
json = JSON.parse(self.value)
errors.add(:base, errormsg) if json.keys != ['suggestion']
errors.add(:base, errormsg) if json.keys != ['suggestion', 'comment']
rescue
errors.add(:base, errormsg)
end
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/graphql_controller_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ def teardown

test "should bulk-create tags" do
TagText.create! text: 'foo', team_id: @t.id
c = create_comment annotated: @pm1
d = create_dynamic_annotation annotated: @pm1
pm4 = create_project_media
query = 'mutation { createTags(input: { clientMutationId: "1", inputs: [{ tag: "foo", annotated_type: "ProjectMedia", annotated_id: "' + @pm1.id.to_s + '" }, { tag: "bar", annotated_type: "ProjectMedia", annotated_id: "' + @pm2.id.to_s + '" }, { tag: "foo", annotated_type: "ProjectMedia", annotated_id: "' + @pm3.id.to_s + '" }, { tag: "test", annotated_type: "ProjectMedia", annotated_id: "' + pm4.id.to_s + '" }, { tag: "bar", annotated_type: "Comment", annotated_id: "' + c.id.to_s + '" }]}) { team { dbid } } }'
query = 'mutation { createTags(input: { clientMutationId: "1", inputs: [{ tag: "foo", annotated_type: "ProjectMedia", annotated_id: "' + @pm1.id.to_s + '" }, { tag: "bar", annotated_type: "ProjectMedia", annotated_id: "' + @pm2.id.to_s + '" }, { tag: "foo", annotated_type: "ProjectMedia", annotated_id: "' + @pm3.id.to_s + '" }, { tag: "test", annotated_type: "ProjectMedia", annotated_id: "' + pm4.id.to_s + '" }, { tag: "bar", annotated_type: "Dynamic", annotated_id: "' + d.id.to_s + '" }]}) { team { dbid } } }'
assert_difference 'TagText.count', 1 do
assert_difference 'Tag.length', 3 do
post :create, params: { query: query, team: @t.slug }
Expand All @@ -166,7 +166,7 @@ def teardown
Sidekiq::Worker.drain_all
end
# should not duplicate tag
query = 'mutation { createTags(input: { clientMutationId: "1", inputs: [{ tag: "foo", annotated_type: "ProjectMedia", annotated_id: "' + @pm1.id.to_s + '" }, { tag: "bar", annotated_type: "ProjectMedia", annotated_id: "' + @pm2.id.to_s + '" }, { tag: "foo", annotated_type: "ProjectMedia", annotated_id: "' + @pm3.id.to_s + '" }, { tag: "test", annotated_type: "ProjectMedia", annotated_id: "' + pm4.id.to_s + '" }, { tag: "bar", annotated_type: "Comment", annotated_id: "' + c.id.to_s + '" }]}) { team { dbid } } }'
query = 'mutation { createTags(input: { clientMutationId: "1", inputs: [{ tag: "foo", annotated_type: "ProjectMedia", annotated_id: "' + @pm1.id.to_s + '" }, { tag: "bar", annotated_type: "ProjectMedia", annotated_id: "' + @pm2.id.to_s + '" }, { tag: "foo", annotated_type: "ProjectMedia", annotated_id: "' + @pm3.id.to_s + '" }, { tag: "test", annotated_type: "ProjectMedia", annotated_id: "' + pm4.id.to_s + '" }, { tag: "bar", annotated_type: "Dynamic", annotated_id: "' + d.id.to_s + '" }]}) { team { dbid } } }'
assert_no_difference 'TagText.count' do
assert_no_difference 'Tag.length' do
post :create, params: { query: query, team: @t.slug }
Expand Down
76 changes: 3 additions & 73 deletions test/controllers/graphql_controller_8_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,51 +125,7 @@ def setup
assert_no_match /items_count:0/, data['verification_statuses'].to_json
end

test "should get nested comment" do
admin_user = create_user is_admin: true
t = create_team
p = create_project team: t
pm = create_project_media project: p
c1 = create_comment annotated: pm, text: 'Parent'
c2 = create_comment annotated: c1, text: 'Child'
authenticate_with_user(admin_user)
query = %{
query {
project_media(ids: "#{pm.id},#{p.id}") {
comments: annotations(first: 10000, annotation_type: "comment") {
edges {
node {
... on Comment {
id
text
comments: annotations(first: 10000, annotation_type: "comment") {
edges {
node {
... on Comment {
id
text
}
}
}
}
}
}
}
}
}
}
}
post :create, params: { query: query, team: t.slug }
assert_response :success
comments = JSON.parse(@response.body)['data']['project_media']['comments']['edges']
assert_equal 1, comments.size
assert_equal 'Parent', comments[0]['node']['text']
child_comments = comments[0]['node']['comments']['edges']
assert_equal 1, child_comments.size
assert_equal 'Child', child_comments[0]['node']['text']
end

test "should get project using API key" do
test "should get project using API key" do
t = create_team
a = create_api_key
b = create_bot_user api_key_id: a.id, team: t
Expand Down Expand Up @@ -365,32 +321,6 @@ def setup
assert_not_nil JSON.parse(@response.body)['data']['team']['verification_statuses']
end

test "should create comment with fragment" do
admin_user = create_user is_admin: true
pm = create_project_media
authenticate_with_user(admin_user)
query = 'mutation { createComment(input: { fragment: "t=10,20", annotated_type: "ProjectMedia", annotated_id: "' + pm.id.to_s + '", text: "Test" }) { comment { parsed_fragment } } }'
assert_difference 'Comment.length', 1 do
post :create, params: { query: query, team: pm.team.slug }
end
assert_response :success
assert_equal({ 't' => [10, 20] }, JSON.parse(@response.body)['data']['createComment']['comment']['parsed_fragment'])
assert_equal({ 't' => [10, 20] }, pm.get_annotations('comment').last.load.parsed_fragment)
end

test "should get comments 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_comment annotated: pm, fragment: 't=10,20'
authenticate_with_user(admin_user)
query = "query { project_media(ids: \"#{pm.id},#{p.id}\") { comments(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']['comments']['edges'][0]['node']['parsed_fragment'])
end

test "should get OCR" do
b = create_alegre_bot(name: 'alegre', login: 'alegre')
b.approve!
Expand Down Expand Up @@ -431,7 +361,7 @@ def setup
with_current_user_and_team(u, t) do
n.times do
pm = create_project_media project: p, disable_es_callbacks: false
m.times { create_comment annotated: pm, annotator: u, disable_es_callbacks: false }
m.times { create_tag annotated: pm, annotator: u, disable_es_callbacks: false }
end
end
sleep 4
Expand Down Expand Up @@ -463,7 +393,7 @@ def setup
pm = create_project_media project: p, user: create_user, disable_es_callbacks: false
s = create_source
create_account_source source: s, disable_es_callbacks: false
m.times { create_comment annotated: pm, annotator: create_user, disable_es_callbacks: false }
m.times { create_tag annotated: pm, annotator: create_user, disable_es_callbacks: false }
end
create_project_media project: p, user: u, disable_es_callbacks: false
pm = create_project_media project: p, disable_es_callbacks: false
Expand Down
36 changes: 5 additions & 31 deletions test/controllers/graphql_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ def setup
assert_graphql_create('account_source', { source_id: s.id, url: url })
end

test "should create comment" do
p = create_project team: @team
pm = create_project_media project: p
assert_graphql_create('comment', { text: 'test', annotated_type: 'ProjectMedia', annotated_id: pm.id.to_s })
end

test "should create media" do
p = create_project team: @team
url = random_url
Expand Down Expand Up @@ -141,19 +135,17 @@ def setup
pm = create_project_media project: p
u = create_user name: 'The Annotator'
create_team_user user: u, team: @team
c = create_comment annotated: pm, annotator: u
c.assign_user(u.id)
tg = create_tag annotated: pm
tg = create_tag annotated: pm, annotator: u
tg.assign_user(u.id)
query = "query GetById { project_media(ids: \"#{pm.id},#{p.id}\") { tasks { edges { node { dbid } } }, tasks_count, published, language, language_code, last_status_obj {dbid}, annotations(annotation_type: \"comment,tag\") { edges { node { ... on Comment { dbid, assignments { edges { node { name } } }, annotator { user { name } } } ... on Tag { dbid, assignments { edges { node { name } } }, annotator { user { name } } } } } } } }"
query = "query GetById { project_media(ids: \"#{pm.id},#{p.id}\") { tasks { edges { node { dbid } } }, tasks_count, published, language, language_code, last_status_obj {dbid}, annotations(annotation_type: \"tag\") { edges { node { ... on Tag { dbid, assignments { edges { node { name } } }, annotator { user { name } } } } } } } }"
post :create, params: { query: query, team: @team.slug }
assert_response :success
data = JSON.parse(@response.body)['data']['project_media']
assert_not_empty data['published']
assert_not_empty data['last_status_obj']['dbid']
assert data.has_key?('language')
assert data.has_key?('language_code')
assert_equal 2, data['annotations']['edges'].size
assert_equal 1, data['annotations']['edges'].size
users = data['annotations']['edges'].collect{ |e| e['node']['annotator']['user']['name'] }
assert users.include?('The Annotator')
users = data['annotations']['edges'].collect{ |e| e['node']['assignments']['edges'][0]['node']['name'] }
Expand Down Expand Up @@ -400,7 +392,7 @@ def setup
create_team_user user: u, team: t
p = create_project team: t
pm = create_project_media project: p
create_comment annotated: pm, annotator: u
create_tag annotated: pm, annotator: u
query = "query GetById { project(id: \"#{p.id}\") { project_medias(first: 1) { edges { node { permissions } } } } }"
post :create, params: { query: query, team: 'team' }
assert_response :success
Expand Down Expand Up @@ -442,7 +434,7 @@ def setup
with_current_user_and_team(u, t) do
n.times do
pm = create_project_media project: p
m.times { create_comment annotated: pm, annotator: u }
m.times { create_tag annotated: pm, annotator: u }
end
end

Expand Down Expand Up @@ -526,24 +518,6 @@ def setup
assert_graphql_create('dynamic', { set_fields: fields, annotated_type: 'ProjectMedia', annotated_id: pm.id.to_s, annotation_type: 'geolocation' })
end

test "should create comment with image" do
u = create_user
t = create_team
create_team_user team: t, user: u
p = create_project team: t
pm = create_project_media project: p
authenticate_with_user(u)
path = File.join(Rails.root, 'test', 'data', 'rails.png')
file = Rack::Test::UploadedFile.new(path, 'image/png')
query = 'mutation create { createComment(input: { text: "Comment with image", clientMutationId: "1", annotated_type: "ProjectMedia", annotated_id: "' + pm.id.to_s + '" }) { comment { id } } }'
assert_difference 'Comment.count' do
post :create, params: { query: query, file: file }
end
assert_response :success
data = JSON.parse(Comment.where(annotation_type: 'comment').last.content)
assert_match /\.png$/, data['file_path']
end

test "should not query invalid type" do
u = create_user
p = create_project team: @team
Expand Down
Loading

0 comments on commit cf46953

Please sign in to comment.