mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Add specs for updated user serializer
This commit is contained in:
parent
14f6f4dcc1
commit
2af1aab787
1 changed files with 56 additions and 0 deletions
|
|
@ -81,5 +81,61 @@ RSpec.describe Api::UserSerializer do
|
|||
expect(settings[:maps]).to eq({ 'distance_unit' => 'mi' })
|
||||
end
|
||||
end
|
||||
|
||||
context 'subscription data' do
|
||||
context 'when not self-hosted (hosted instance)' do
|
||||
before do
|
||||
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
|
||||
end
|
||||
|
||||
it 'includes subscription data' do
|
||||
expect(serializer).to have_key(:subscription)
|
||||
expect(serializer[:subscription]).to include(:status, :active_until)
|
||||
end
|
||||
|
||||
it 'returns correct subscription values' do
|
||||
subscription = serializer[:subscription]
|
||||
expect(subscription[:status]).to eq(user.status)
|
||||
expect(subscription[:active_until]).to eq(user.active_until)
|
||||
end
|
||||
|
||||
context 'with specific subscription values' do
|
||||
it 'serializes trial user status correctly' do
|
||||
# When not self-hosted, users start with trial status via start_trial callback
|
||||
test_user = create(:user)
|
||||
serializer_result = described_class.new(test_user).call
|
||||
subscription = serializer_result[:subscription]
|
||||
|
||||
expect(subscription[:status]).to eq('trial')
|
||||
expect(subscription[:active_until]).to be_within(1.second).of(7.days.from_now)
|
||||
end
|
||||
|
||||
it 'serializes subscription data with all expected fields' do
|
||||
test_user = create(:user)
|
||||
serializer_result = described_class.new(test_user).call
|
||||
subscription = serializer_result[:subscription]
|
||||
|
||||
expect(subscription).to include(:status, :active_until)
|
||||
expect(subscription[:status]).to be_a(String)
|
||||
expect(subscription[:active_until]).to be_a(ActiveSupport::TimeWithZone)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when self-hosted' do
|
||||
before do
|
||||
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
|
||||
end
|
||||
|
||||
it 'does not include subscription data' do
|
||||
expect(serializer).not_to have_key(:subscription)
|
||||
end
|
||||
|
||||
it 'still includes user and settings data' do
|
||||
expect(serializer).to have_key(:user)
|
||||
expect(serializer[:user]).to include(:email, :theme, :settings)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue