A global "View tech bonuses" permission shows the weeks run and each week's hours, tiers and bonuses, read-only: no attendance boxes, run button or Email again, and no customer accounts, emailed-to addresses, or QuickBooks/PDF links. "Run tech bonuses" is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
4.8 KiB
Ruby
121 lines
4.8 KiB
Ruby
#The MIT License (MIT)
|
|
#
|
|
#Copyright (c) 2026 rick barrette
|
|
#
|
|
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
#
|
|
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
#
|
|
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
require File.expand_path('../test_helper', __dir__)
|
|
|
|
class TechBonusesTest < Redmine::IntegrationTest
|
|
include QboBonusTestHelper
|
|
|
|
def setup
|
|
Customer.any_instance.stubs(:email).returns('tech@example.com')
|
|
RedmineQboBonus::Settings.stubs(:item).returns(Struct.new(:id, :name).new('31', 'Tech Bonus'))
|
|
RedmineQboBonus::CreditMemoWriter.stubs(:send_email).returns(true)
|
|
RedmineQboBonus::CreditMemoWriter.any_instance.stubs(:create).returns(saved_credit_memo)
|
|
create_technician(2)
|
|
log_time(2, 100)
|
|
log_time(3, 15.5)
|
|
end
|
|
|
|
def test_needs_the_permission
|
|
log_user('jsmith', 'jsmith')
|
|
get '/tech_bonuses'
|
|
assert_response :forbidden
|
|
|
|
Role.find(1).add_permission!(:run_tech_bonuses)
|
|
get '/tech_bonuses'
|
|
assert_response :success
|
|
assert_select '#top-menu a.tech-bonuses'
|
|
end
|
|
|
|
def test_view_only
|
|
log_user('admin', 'admin')
|
|
post '/tech_bonuses/2026-11-08', params: { attended: ['2'] }
|
|
credit = TechBonusCredit.find_by(user_id: 2)
|
|
|
|
Role.find(1).add_permission!(:view_tech_bonuses)
|
|
reset!
|
|
log_user('jsmith', 'jsmith')
|
|
get '/tech_bonuses'
|
|
assert_response :success
|
|
assert_select '#top-menu a.tech-bonuses'
|
|
get '/tech_bonuses/2026-11-08'
|
|
assert_response :success
|
|
assert_select 'td', text: '$100.00'
|
|
assert_select 'td', text: '#1042'
|
|
assert_select 'input[name=?]', 'attended[]', count: 0
|
|
assert_select '#tech-bonus-run input[type=submit]', count: 0
|
|
assert_select 'a[href*="creditmemo"]', count: 0
|
|
assert_select 'a[href*="/pdf"]', count: 0
|
|
assert_select 'a[href*="/resend"]', count: 0
|
|
assert_not_includes response.body, 'tech@example.com'
|
|
|
|
assert_no_difference 'TechBonusCredit.count' do
|
|
post '/tech_bonuses/2026-11-15', params: { attended: ['2'] }
|
|
end
|
|
assert_response :forbidden
|
|
post "/tech_bonuses/credits/#{credit.id}/resend"
|
|
assert_response :forbidden
|
|
get "/tech_bonuses/credits/#{credit.id}/pdf"
|
|
assert_response :forbidden
|
|
end
|
|
|
|
def test_week_preview
|
|
log_user('admin', 'admin')
|
|
get '/tech_bonuses', params: { week: '2026-11-10' }
|
|
assert_redirected_to '/tech_bonuses/2026-11-08'
|
|
get '/tech_bonuses/2026-11-08'
|
|
assert_response :success
|
|
assert_select 'h2', text: /2026-46/
|
|
assert_select '.tech-bonus-summary .value', text: '115.5'
|
|
assert_select 'input[name=?][value="2"]', 'attended[]'
|
|
assert_select 'td', text: '$100.00'
|
|
assert_select 'a[href^="/time_entries/report"]'
|
|
end
|
|
|
|
def test_run_week
|
|
log_user('admin', 'admin')
|
|
post '/tech_bonuses/2026-11-08', params: { attended: ['2'] }
|
|
assert_redirected_to '/tech_bonuses/2026-11-08'
|
|
credit = TechBonusCredit.find_by(user_id: 2)
|
|
assert_equal 'emailed', credit.status
|
|
assert_equal '1042', credit.doc_number
|
|
follow_redirect!
|
|
assert_select 'a[href*="creditmemo?txnId=777"]', text: '#1042'
|
|
|
|
get '/tech_bonuses'
|
|
assert_select 'table.tech-bonus-weeks td', text: /115.5\/110/
|
|
end
|
|
|
|
def test_pdf
|
|
log_user('admin', 'admin')
|
|
post '/tech_bonuses/2026-11-08', params: { attended: ['2'] }
|
|
credit = TechBonusCredit.find_by(user_id: 2)
|
|
RedmineQboBonus::CreditMemoWriter.expects(:pdf).with('777').returns('%PDF-1.4')
|
|
get "/tech_bonuses/credits/#{credit.id}/pdf"
|
|
assert_response :success
|
|
assert_equal 'application/pdf', response.media_type
|
|
end
|
|
|
|
def test_resend
|
|
log_user('admin', 'admin')
|
|
post '/tech_bonuses/2026-11-08', params: { attended: ['2'] }
|
|
credit = TechBonusCredit.find_by(user_id: 2)
|
|
RedmineQboBonus::CreditMemoWriter.expects(:send_email).with('777', 'tech@example.com').returns(true)
|
|
post "/tech_bonuses/credits/#{credit.id}/resend"
|
|
assert_redirected_to '/tech_bonuses/2026-11-08'
|
|
end
|
|
|
|
def test_not_a_week
|
|
log_user('admin', 'admin')
|
|
get '/tech_bonuses/2026-02-31'
|
|
assert_response :not_found
|
|
end
|
|
end
|