Skip to content

Commit

Permalink
Reviewing uncovered lines
Browse files Browse the repository at this point in the history
The latest refactoring surfaced some uncovered lines. This PR adds a test for part of the code that was left untested and also deletes code that is not needed anymore.

Reference: CV2-4159.
  • Loading branch information
caiosba authored Jan 5, 2024
1 parent 6d60fb7 commit eb0dc5b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
14 changes: 0 additions & 14 deletions app/models/annotations/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,6 @@ def get_file_from_uri(params)
params
end

def existing_files
self.first_response_obj&.load&.file.to_a
end

def add_files(new_files)
self.file = [self.existing_files].flatten.reject{ |f| f.blank? }.concat(new_files)
self.response = '{}'
end

def remove_files(filenames)
self.file = [existing_files].flatten.reject{ |f| f.blank? || filenames.include?(f.to_s.split('/').last) }
self.response = '{}'
end

def first_response_obj
return @response if @response
responses = self.responses
Expand Down
10 changes: 10 additions & 0 deletions test/controllers/graphql_controller_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,16 @@ def teardown
assert_equal [pm.id], JSON.parse(@response.body)['data']['project_medias']['edges'].collect{ |x| x['node']['dbid'] }
end

test "should upload files when calling a mutation" do
u = create_user is_admin: true
t = create_task
f = Rack::Test::UploadedFile.new(File.join(Rails.root, 'test', 'data', 'rails.png'), 'image/png')
authenticate_with_user(u)
query = 'mutation { updateTask(input: { clientMutationId: "1", id: "' + t.graphql_id + '" }) { task { id } } }' # It could be any other mutation, not only updateTask
post :create, params: { query: query, team: t.slug, file: { '0' => f } }
assert_response :success
end

protected

def assert_error_message(expected)
Expand Down
4 changes: 2 additions & 2 deletions test/models/project_media_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def perform(id)
pm = create_project_media team: t, set_tasks_responses: { 'upload_a_file' => url }
end
task = pm.annotations('task').last
assert task.existing_files.size > 0
assert task.first_response_obj&.load&.file.to_a.size > 0
end
end

Expand Down Expand Up @@ -463,4 +463,4 @@ def perform(id)
assert_equal 2, ProjectMedia.where(id: [pm_s.id, pm_t.id], archived: CheckArchivedFlags::FlagCodes::NONE).count
assert_not_nil Relationship.where(id: r.id).last
end
end
end

0 comments on commit eb0dc5b

Please sign in to comment.