Commit a30dfddc authored by a_luna's avatar a_luna

Send :use_specialized_service param for MRs

This ensures the new service is called when the add_spent_time endpoint
for merge requests is used.

The update service for issues does not know anything about this parameter
so we skip it when the object to add spent time to is an issue.
parent fa8c9dff
......@@ -85,10 +85,15 @@ module API
post ":id/#{issuable_collection_name}/:#{issuable_key}/add_spent_time" do
authorize! admin_issuable_key, load_issuable
update_issuable(spend_time: {
duration: Gitlab::TimeTrackingFormatter.parse(params.delete(:duration)),
user_id: current_user.id
})
update_params = {
spend_time: {
duration: Gitlab::TimeTrackingFormatter.parse(params.delete(:duration)),
user_id: current_user.id
}
}
update_params[:use_specialized_service] = true if issuable_name == 'merge_request'
update_issuable(update_params)
end
desc "Reset spent time for a project #{issuable_name}"
......
......@@ -125,6 +125,22 @@ RSpec.shared_examples 'time tracking endpoints' do |issuable_name|
expect(json_response['message']['base'].first).to eq(_('Time to subtract exceeds the total time spent'))
end
end
if issuable_name == 'merge_request'
it 'calls update service with :use_specialized_service param' do
expect(::MergeRequests::UpdateService).to receive(:new).with(project, user, hash_including(use_specialized_service: true))
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user), params: { duration: '2h' }
end
end
if issuable_name == 'issue'
it 'calls update service without :use_specialized_service param' do
expect(::Issues::UpdateService).to receive(:new).with(project, user, hash_not_including(use_specialized_service: true))
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user), params: { duration: '2h' }
end
end
end
describe "POST /projects/:id/#{issuable_collection_name}/:#{issuable_name}_id/reset_spent_time" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment