Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Sep 25, 2024
1 parent 6c7e281 commit 00d7539
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 6 deletions.
61 changes: 61 additions & 0 deletions spec/jobs/event/survey_job_spec.rb
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
6 changes: 3 additions & 3 deletions spec/mailers/event/application_closed_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Copyright (c) 2012-2013, Jungwacht Blauring Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# 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.
# https://github.com/hitobito/hitobito_sac_cas.

require "spec_helper"

Expand Down
6 changes: 3 additions & 3 deletions spec/mailers/event/participation_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Copyright (c) 2012-2013, Jungwacht Blauring Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# 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.
# https://github.com/hitobito/hitobito_sac_cas.

require "spec_helper"

Expand Down
34 changes: 34 additions & 0 deletions spec/mailers/event/survey_mailer_spec.rb
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

0 comments on commit 00d7539

Please sign in to comment.