2017-01-18 11:48:16 -05:00
|
|
|
shared_examples 'an unauthorized API user' do
|
|
|
|
it { is_expected.to eq(403) }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'time tracking endpoints' do |issuable_name|
|
|
|
|
issuable_collection_name = issuable_name.pluralize
|
|
|
|
|
|
|
|
describe "POST /projects/:id/#{issuable_collection_name}/:#{issuable_name}_id/time_estimate" do
|
|
|
|
context 'with an unauthorized user' do
|
2017-02-25 03:44:09 -05:00
|
|
|
subject { post(api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/time_estimate", non_member), duration: '1w') }
|
2017-01-18 11:48:16 -05:00
|
|
|
|
|
|
|
it_behaves_like 'an unauthorized API user'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the time estimate for #{issuable_name}" do
|
2017-02-25 03:44:09 -05:00
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/time_estimate", user), duration: '1w'
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(json_response['human_time_estimate']).to eq('1w')
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'updating the current estimate' do
|
|
|
|
before do
|
2017-02-25 03:44:09 -05:00
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/time_estimate", user), duration: '1w'
|
2017-01-18 11:48:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when duration has a bad format' do
|
|
|
|
it 'does not modify the original estimate' do
|
2017-02-25 03:44:09 -05:00
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/time_estimate", user), duration: 'foo'
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(400)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(issuable.reload.human_time_estimate).to eq('1w')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a valid duration' do
|
|
|
|
it 'updates the estimate' do
|
2017-02-25 03:44:09 -05:00
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/time_estimate", user), duration: '3w1h'
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(issuable.reload.human_time_estimate).to eq('3w 1h')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/#{issuable_collection_name}/:#{issuable_name}_id/reset_time_estimate" do
|
|
|
|
context 'with an unauthorized user' do
|
2017-02-25 03:44:09 -05:00
|
|
|
subject { post(api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/reset_time_estimate", non_member)) }
|
2017-01-18 11:48:16 -05:00
|
|
|
|
|
|
|
it_behaves_like 'an unauthorized API user'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "resets the time estimate for #{issuable_name}" do
|
2017-02-25 03:44:09 -05:00
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/reset_time_estimate", user)
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(json_response['time_estimate']).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/#{issuable_collection_name}/:#{issuable_name}_id/add_spent_time" do
|
|
|
|
context 'with an unauthorized user' do
|
|
|
|
subject do
|
2017-02-25 03:44:09 -05:00
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", non_member),
|
2017-01-18 11:48:16 -05:00
|
|
|
duration: '2h'
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'an unauthorized API user'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "add spent time for #{issuable_name}" do
|
2018-05-08 11:00:51 -04:00
|
|
|
Timecop.travel(1.minute.from_now) do
|
|
|
|
expect do
|
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user),
|
|
|
|
duration: '2h'
|
|
|
|
end.to change { issuable.reload.updated_at }
|
|
|
|
end
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(201)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(json_response['human_total_time_spent']).to eq('2h')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when subtracting time' do
|
|
|
|
it 'subtracts time of the total spent time' do
|
2018-05-08 11:00:51 -04:00
|
|
|
Timecop.travel(1.minute.from_now) do
|
|
|
|
expect do
|
|
|
|
issuable.update_attributes!(spend_time: { duration: 7200, user_id: user.id })
|
|
|
|
end.to change { issuable.reload.updated_at }
|
|
|
|
end
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-02-25 03:44:09 -05:00
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user),
|
2017-01-18 11:48:16 -05:00
|
|
|
duration: '-1h'
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(201)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(json_response['total_time_spent']).to eq(3600)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when time to subtract is greater than the total spent time' do
|
|
|
|
it 'does not modify the total time spent' do
|
2017-12-14 14:32:55 -05:00
|
|
|
issuable.update_attributes!(spend_time: { duration: 7200, user_id: user.id })
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2018-05-08 11:00:51 -04:00
|
|
|
Timecop.travel(1.minute.from_now) do
|
|
|
|
expect do
|
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user),
|
|
|
|
duration: '-1w'
|
|
|
|
end.not_to change { issuable.reload.updated_at }
|
|
|
|
end
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(400)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(json_response['message']['time_spent'].first).to match(/exceeds the total time spent/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/#{issuable_collection_name}/:#{issuable_name}_id/reset_spent_time" do
|
|
|
|
context 'with an unauthorized user' do
|
2017-02-25 03:44:09 -05:00
|
|
|
subject { post(api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/reset_spent_time", non_member)) }
|
2017-01-18 11:48:16 -05:00
|
|
|
|
|
|
|
it_behaves_like 'an unauthorized API user'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "resets spent time for #{issuable_name}" do
|
2018-05-08 11:00:51 -04:00
|
|
|
Timecop.travel(1.minute.from_now) do
|
|
|
|
expect do
|
|
|
|
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/reset_spent_time", user)
|
|
|
|
end.to change { issuable.reload.updated_at }
|
|
|
|
end
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(json_response['total_time_spent']).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/#{issuable_collection_name}/:#{issuable_name}_id/time_stats" do
|
|
|
|
it "returns the time stats for #{issuable_name}" do
|
2017-12-14 14:32:55 -05:00
|
|
|
issuable.update_attributes!(spend_time: { duration: 1800, user_id: user.id },
|
2017-01-18 11:48:16 -05:00
|
|
|
time_estimate: 3600)
|
|
|
|
|
2017-02-25 03:44:09 -05:00
|
|
|
get api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/time_stats", user)
|
2017-01-18 11:48:16 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-18 11:48:16 -05:00
|
|
|
expect(json_response['total_time_spent']).to eq(1800)
|
|
|
|
expect(json_response['time_estimate']).to eq(3600)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|