dawarich/spec/services/points_limit_exceeded_spec.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

2025-05-16 13:53:42 -04:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe PointsLimitExceeded do
describe '#call' do
subject(:points_limit_exceeded) { described_class.new(user).call }
let(:user) { create(:user) }
context 'when app is self-hosted' do
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
end
it { is_expected.to be false }
end
context 'when app is not self-hosted' do
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
stub_const('DawarichSettings::BASIC_PAID_PLAN_LIMIT', 10)
end
context 'when user points count is equal to the limit' do
before do
2025-08-22 15:27:50 -04:00
allow(user).to receive(:points_count).and_return(10)
2025-05-16 13:53:42 -04:00
end
it { is_expected.to be true }
it 'caches the result' do
2025-08-22 15:27:50 -04:00
expect(user).to receive(:points_count).once
2.times { described_class.new(user).call }
end
2025-05-16 13:53:42 -04:00
end
context 'when user points count exceeds the limit' do
before do
2025-08-22 15:27:50 -04:00
allow(user).to receive(:points_count).and_return(11)
2025-05-16 13:53:42 -04:00
end
it { is_expected.to be true }
end
context 'when user points count is below the limit' do
before do
2025-08-22 15:27:50 -04:00
allow(user).to receive(:points_count).and_return(9)
2025-05-16 13:53:42 -04:00
end
it { is_expected.to be false }
end
end
end
end