discourse/spec/jobs/process_shelved_notifications_spec.rb
Jarek Radosz 694b5f108b
DEV: Fix various rubocop lints (#24749)
These (21 + 3 from previous PRs) are soon to be enabled in rubocop-discourse:

Capybara/VisibilityMatcher
Lint/DeprecatedOpenSSLConstant
Lint/DisjunctiveAssignmentInConstructor
Lint/EmptyConditionalBody
Lint/EmptyEnsure
Lint/LiteralInInterpolation
Lint/NonLocalExitFromIterator
Lint/ParenthesesAsGroupedExpression
Lint/RedundantCopDisableDirective
Lint/RedundantRequireStatement
Lint/RedundantSafeNavigation
Lint/RedundantStringCoercion
Lint/RedundantWithIndex
Lint/RedundantWithObject
Lint/SafeNavigationChain
Lint/SafeNavigationConsistency
Lint/SelfAssignment
Lint/UnreachableCode
Lint/UselessMethodDefinition
Lint/Void

Previous PRs:
Lint/ShadowedArgument
Lint/DuplicateMethods
Lint/BooleanSymbol
RSpec/SpecFilePathSuffix
2023-12-06 23:25:00 +01:00

52 lines
1.7 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Jobs::ProcessShelvedNotifications do
subject(:job) { described_class.new }
fab!(:user)
let(:post) { Fabricate(:post) }
it "removes all past do not disturb timings" do
future = Fabricate(:do_not_disturb_timing, ends_at: 1.day.from_now)
past = Fabricate(:do_not_disturb_timing, starts_at: 2.day.ago, ends_at: 1.minute.ago)
expect { job.execute({}) }.to change { DoNotDisturbTiming.count }.by(-1)
expect(DoNotDisturbTiming.find_by(id: future.id)).to eq(future)
expect(DoNotDisturbTiming.find_by(id: past.id)).to eq(nil)
end
it "does not process shelved_notifications when the user is in DND" do
user.do_not_disturb_timings.create(starts_at: 2.days.ago, ends_at: 2.days.from_now)
notification =
Notification.create(
read: false,
user_id: user.id,
topic_id: 2,
post_number: 1,
data: "{}",
notification_type: 1,
)
expect(notification.shelved_notification).to be_present
job.execute({})
expect(notification.shelved_notification).to be_present
end
it "processes and destroys shelved_notifications when the user leaves DND" do
user.do_not_disturb_timings.create(starts_at: 2.days.ago, ends_at: 2.days.from_now)
notification =
Notification.create(
read: false,
user_id: user.id,
topic_id: 2,
post_number: 1,
data: "{}",
notification_type: 1,
)
user.do_not_disturb_timings.last.update(ends_at: 1.days.ago)
expect(notification.shelved_notification).to be_present
job.execute({})
expect { notification.shelved_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end