-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas | ||
|
||
require "spec_helper" | ||
|
||
describe Event::SurveyJob do | ||
include ActiveJob::TestHelper | ||
|
||
let(:course) do | ||
Fabricate(:sac_open_course, | ||
link_survey: "https://example.com/survey", | ||
dates: [Fabricate(:event_date, start_at: 1.week.ago, finish_at: 3.days.ago)], | ||
participations: Fabricate.times(2, :event_participation, state: :attended)) | ||
end | ||
|
||
subject(:job) { described_class.new } | ||
|
||
context "rescheduling" do | ||
it "reschedules for tomorrow at 5 minutes past midnight" do | ||
job.perform | ||
next_job = Delayed::Job.find_by("handler like '%Event::SurveyJob%'") | ||
expect(next_job.run_at).to eq Time.zone.tomorrow + 5.minutes | ||
end | ||
end | ||
|
||
context "with two attended participations" do | ||
before { course } | ||
|
||
it "sends an email to both participants" do | ||
expect { job.perform }.to have_enqueued_mail(Event::SurveyMailer, :survey).exactly(2).times | ||
end | ||
end | ||
|
||
context "with one attended participation" do | ||
before { course.participations.last.update!(state: :assigned) } | ||
|
||
it "sends an email to the participant" do | ||
expect { job.perform }.to have_enqueued_mail(Event::SurveyMailer, :survey).once | ||
end | ||
end | ||
|
||
context "without link_survey" do | ||
before { course.update!(link_survey: nil) } | ||
|
||
it "doesnt send an email" do | ||
expect { job.perform }.not_to have_enqueued_mail(Event::SurveyMailer) | ||
end | ||
end | ||
|
||
context "not 3 days ago" do | ||
before { course.dates.reload.first.update!(finish_at: 4.days.ago) } | ||
|
||
it "doesnt send an email" do | ||
expect { job.perform }.not_to have_enqueued_mail(Event::SurveyMailer) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas. | ||
|
||
require "spec_helper" | ||
|
||
describe Event::SurveyMailer do | ||
let(:event) do | ||
Fabricate(:sac_open_course, | ||
link_survey: "https://example.com/survey", | ||
dates: [Fabricate(:event_date, start_at: 1.week.ago, finish_at: 3.days.ago)], | ||
participations: [participation]) | ||
end | ||
|
||
let(:participation) { Fabricate(:event_participation, person: people(:mitglied), state: :attended) } | ||
let(:mail) { described_class.survey(event, participation) } | ||
|
||
before { event.groups.first.update!(course_admin_email: "admin@example.com") } | ||
|
||
context "minimum participants" do | ||
it "sends email to course leader" do | ||
expect(mail.to).to match_array(["e.hillary@hitobito.example.com"]) | ||
expect(mail.bcc).to match_array(["admin@example.com"]) | ||
expect(mail.body.to_s).to include( | ||
"Hallo Edmund,", | ||
"wenn du dir einen Moment Zeit nehmen könntest, um an unserer Umfrage teilzunehmen", | ||
"https://example.com/survey" | ||
) | ||
end | ||
end | ||
end |