diff --git a/test/functional/time_tracker_controller_test.rb b/test/functional/time_tracker_controller_test.rb index e0c71b3..f62fc1f 100644 --- a/test/functional/time_tracker_controller_test.rb +++ b/test/functional/time_tracker_controller_test.rb @@ -23,8 +23,6 @@ def setup @request.session[:user_id] = 1 end - # auth spec - test '#create - without login' do @controller.logged_user = nil @request.session[:user_id] = nil @@ -46,11 +44,11 @@ def setup assert_response 403 end - # create tests + # Non auth tests test '#create - with complete params' do - recorded_time = Time.zone.now - 1.hour assert_equal 0, TimerSession.count + recorded_time = Time.zone.now - 1.hour post :create, params: { timer_session: { timer_start: recorded_time, timer_end: Time.zone.now, @@ -63,8 +61,8 @@ def setup end test '#create - with end time present' do - recorded_time = Time.zone.now - 1.hour assert_equal 0, TimerSession.count + recorded_time = Time.zone.now - 1.hour post :create, params: { timer_session: { timer_start: recorded_time, timer_end: Time.zone.now, @@ -76,7 +74,21 @@ def setup assert_response 200 end + test '#create - with invalid params' do + assert_equal 0, TimerSession.count + recorded_time = Time.zone.now + 1.hour + post :create, params: { timer_session: { + timer_start: recorded_time, + timer_end: Time.zone.now, + comments: 'Starting a new session', + issue_ids: ['1'] + } }, xhr: true + assert_equal 1, TimerSession.count + assert_response 422 + end + test '#update - with end time' do + assert_equal 0, TimerSession.count FactoryBot.create(:timer_session, user: User.find(1), finished: false) recorded_time = Time.zone.now - 1.hour @@ -89,6 +101,18 @@ def setup assert_response 200 end + test '#update - with no end time' do + FactoryBot.create(:timer_session, user: User.find(1), finished: false) + + post :update, params: { timer_session: { + timer_start: Time.zone.now - 1.hours, + timer_end: nil, + comments: 'Worked for an hour', + issue_ids: ['1'] + } }, xhr: true + assert_response 200 + end + test '#update - with invalid params' do FactoryBot.create(:timer_session, user: User.find(1), finished: false)