Skip to content

Commit

Permalink
[add] extra specs about reminder on gws/schedule/plans
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny4381 committed Nov 26, 2019
1 parent 4eead3e commit b3e34c7
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions spec/features/gws/schedule/plans/reminder_spec.rb
Expand Up @@ -16,6 +16,15 @@
end
let(:show_path) { gws_schedule_plan_path site, plan }

before do
# メール転送を有効にする
user = gws_user
user.notice_schedule_user_setting = "notify"
user.notice_schedule_email_user_setting = "notify"
user.send_notice_mail_address = "#{unique_id}@example.jp"
user.save!
end

before { login_gws_user }

it do
Expand All @@ -26,7 +35,8 @@
expect(Gws::Reminder.count).to eq 1
within ".gws-addon-reminder" do
within first('.remider-conditions tr') do
expect(page).to have_select("item[in_reminder_conditions][][state]", selected: I18n.t('gws/reminder.options.notify_state.mail'))
selected = I18n.t('gws/reminder.options.notify_state.mail')
expect(page).to have_select("item[in_reminder_conditions][][state]", selected: selected)
end
end

Expand All @@ -52,7 +62,7 @@
#
within ".gws-addon-reminder" do
within first('.remider-conditions tr') do
select I18n.t('gws/reminder.options.notify_state.mail'), from: 'item[in_reminder_conditions][][state]'
select I18n.t('gws/reminder.options.notify_state.enabled'), from: 'item[in_reminder_conditions][][state]'
end
click_on I18n.t('gws/reminder.buttons.register_reminder')
end
Expand All @@ -63,6 +73,47 @@
expect(page).to have_css('#notice', text: I18n.t('gws/reminder.notification.created'))

expect(Gws::Reminder.count).to eq 1
remider = Gws::Reminder.first
expect(remider.site_id).to eq plan.site_id
expect(remider.date).to eq plan.start_at
expect(remider.start_at).to eq plan.start_at
expect(remider.end_at).to eq plan.end_at
expect(remider.notifications.length).to eq 1
remider.notifications.first.tap do |notification|
expect(notification.state).to eq "enabled"
expect(notification.interval).to eq 10
expect(notification.interval_type).to eq "minutes"
expect(notification.notify_at).to eq plan.start_at - notification.interval.minutes
expect(notification.base_time).to be_blank
expect(notification.delivered_at).to eq Time.zone.at(0)
end

#
# リマインド日時まで時を進め、通知送信ジョブを実行する
#
Timecop.freeze(remider.notifications.first.notify_at + 1.minute) do
Gws::Reminder::NotificationJob.bind(site_id: site.id).perform_now
end

remider.reload
expect(remider.notifications.length).to eq 1
remider.notifications.first.tap do |notification|
expect(notification.delivered_at).to eq notification.notify_at + 1.minute
end

expect(SS::Notification.all.count).to eq 1
SS::Notification.all.first.tap do |notice|
subject = I18n.t(
"gws/reminder.notification.subject",
model: I18n.t("mongoid.models.#{remider.model}"), name: remider.name
)
expect(notice.subject).to eq subject
expect(notice.member_ids.length).to eq 1
expect(notice.member_ids).to include(remider.user_id)
end

# スケジュールの通知転送設定を有効にしても、リマインダーには効果なし
expect(ActionMailer::Base.deliveries.length).to eq 0
end
end
end

0 comments on commit b3e34c7

Please sign in to comment.