Commit 0256fd38 authored by Tugce Nur Tas's avatar Tugce Nur Tas
Browse files

add verify_termination to group_assignment model, update system test recordingly

parent 66b5a19a
......@@ -24,6 +24,15 @@ class GroupAssignment < ApplicationRecord
create_log_of_self(period_start_before_last_save, period_end_before_last_save)
end
def termination_verifiable?
ended? && termination_submitted_by.present?
end
def verify_termination(user)
update(termination_verified_by: user, termination_verified_at: Time.zone.now)
create_log_of_self
end
def create_log_of_self(start_date = period_start, end_date = period_end)
GroupAssignmentLog.create!(
attributes.except('id', 'created_at', 'updated_at', 'active')
......
......@@ -12,10 +12,16 @@ class GroupAssignmentTerminationIndexTest < ApplicationSystemTestCase
@not_ended = create :group_assignment, group_offer: @group_offer1, volunteer: @volunteer1,
period_start: 3.weeks.ago, period_end: nil
@un_submitted = create :group_assignment, group_offer: @group_offer1, volunteer: @volunteer2,
period_start: 3.weeks.ago, period_end: 2.days.ago
period_start: 3.weeks.ago, period_end: 2.days.ago, period_end_set_by: @superadmin
@submitted = create :group_assignment, group_offer: @group_offer1, volunteer: @volunteer3,
period_start: 3.weeks.ago, period_end: 2.days.ago,
termination_submitted_at: 2.days.ago, termination_submitted_by: @volunteer3.user
termination_submitted_at: 2.days.ago, termination_submitted_by: @volunteer3.user,
period_end_set_by: @superadmin
@verified = create :group_assignment, group_offer: @group_offer1, volunteer: @volunteer4,
period_start: 3.weeks.ago, period_end: 2.days.ago,
termination_submitted_at: 2.days.ago, termination_submitted_by: @volunteer4.user,
period_end_set_by: @superadmin, termination_verified_at: 2.days.ago,
termination_verified_by: @superadmin
login_as @superadmin
end
......@@ -33,6 +39,7 @@ class GroupAssignmentTerminationIndexTest < ApplicationSystemTestCase
assert page.has_text? termination_index_table_text(@un_submitted)
assert page.has_text? termination_index_table_text(@submitted)
refute page.has_text? termination_index_table_text(@not_ended)
refute page.has_text? termination_index_table_text(@verified)
end
test 'filtering_submitted_terminations' do
......@@ -53,6 +60,32 @@ class GroupAssignmentTerminationIndexTest < ApplicationSystemTestCase
refute page.has_text? termination_index_table_text(@submitted)
end
test 'filtering_for_only_verified' do
visit terminated_index_group_assignments_path(q: { termination_verified_by_id_null: 'true' })
click_link 'Quittiert: Unquittiert'
click_link exact_text: 'Quittiert'
visit current_url
refute page.has_text? termination_index_table_text(@un_submitted)
refute page.has_text? termination_index_table_text(@submitted)
assert page.has_text? termination_index_table_text(@verified)
end
test 'ended_assignment_can_be_verified' do
visit group_offers_path
click_link 'Beendete Begleitungen'
assert page.has_text? termination_index_table_text(@un_submitted)
assert page.has_text? termination_index_table_text(@submitted)
refute page.has_text? termination_index_table_text(@verified)
page.find_all('a', text: 'Beendigung Quittieren').first.click
click_link 'Beendigung Quittieren'
assert page.has_text? 'Beendete Begleitungen'
refute page.has_text? termination_index_table_text(@un_submitted)
refute page.has_text? termination_index_table_text(@submitted)
refute page.has_text? termination_index_table_text(@verified)
end
test 'clear_filter_link_is_working_correctly' do
visit group_offers_path
click_link 'Beendete Begleitungen'
......@@ -67,6 +100,7 @@ class GroupAssignmentTerminationIndexTest < ApplicationSystemTestCase
assert page.has_text? termination_index_table_text(@un_submitted)
assert page.has_text? termination_index_table_text(@submitted)
refute page.has_text? termination_index_table_text(@not_ended)
refute page.has_text? termination_index_table_text(@verified)
end
test 'there_is_correct_links_to_the_termination_forms' do
......@@ -83,26 +117,41 @@ class GroupAssignmentTerminationIndexTest < ApplicationSystemTestCase
href: new_volunteer_certificate_path(@submitted.volunteer.id)
end
test 'group_assignment_quittieren_creates_a_group_assignment_log_record_from_group_assignment' do
visit terminated_index_group:assignments_path(q: { termination_verified_by_id_null: 'true' })
click_link 'Beendigung Quittieren', href: verify_termination_group_assignment_path(@submitted.id)
assert page.has_text? 'Der Einsatz wurde erfolgreich quittiert.'
assert_equal @submitted, GroupAssignmentLog.find_by(group_assignment_id: @submitted.id).group_assignment
end
test 'there_is_correct_links_on_email_status_column' do
create :email_template_termination
visit terminated_index_group_assignments_path(q: { termination_verified_by_id_null: 'true' })
# Assignment has an end-date, but no reminder mailing was created
# GroupAssignment has an end-date, but no reminder mailing was created
click_link 'Beendigungs Email erstellen',
href: new_termination_group_assignment_reminder_mailings_path(@un_submitted)
click_button 'Erstellen und Vorschau anzeigen'
# Assignment has an end-date, reminder mailing was created, but not sent
# GroupAssignment has an end-date, reminder mailing was created, but not sent
visit terminated_index_group_assignments_path(q: { termination_verified_by_id_null: 'true' })
click_link 'Nicht versandt',
href: reminder_mailing_path(@un_submitted.reminder_mailings.termination.last)
click_link 'Nicht versandt', href: reminder_mailing_path(@un_submitted.reminder_mailings
.termination.last)
click_link 'Email versenden'
assert page.has_text? 'Beendigungs-Email wird versendet.'
# Assignment has an end-date, reminder mailing was created and was sent
# GroupAssignment has an end-date, reminder mailing was created and was sent
visit terminated_index_group_assignments_path(q: { termination_verified_by_id_null: 'true' })
@un_submitted.reload
mailing = @un_submitted.reminder_mailings.termination.last
assert page.has_link? "Übermittelt am #{I18n.l(mailing.updated_at.to_date)}",
href: reminder_mailing_path(mailing)
assert page.has_link? 'Übermittelt am ',
href: reminder_mailing_path(@un_submitted.reminder_mailings.termination.last)
click_link 'Beendigung Quittieren', href: /group_assignments\/#{@un_submitted.id}\/verify_termination/
assert page.has_text? 'Der Einsatz wurde erfolgreich quittiert.'
visit terminated_index_assignments_path(q: { termination_verified_by_id_not_null: 'true' })
@un_submitted.reload
assert page.has_text? "Quittiert von #{@un_submitted.termination_verified_by.full_name} am"\
" #{I18n.l(@un_submitted.termination_verified_at.to_date)}"
end
end
Supports Markdown
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