Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
CuddlyBunion341 committed Jun 25, 2024
1 parent 853fb89 commit 4c098c7
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions test/functional/time_tracker_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 4c098c7

Please sign in to comment.