status_serializer_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe REST::StatusSerializer do
  4. subject do
  5. serialized_record_json(
  6. status,
  7. described_class,
  8. options: {
  9. scope: current_user,
  10. scope_name: :current_user,
  11. }
  12. )
  13. end
  14. let(:current_user) { Fabricate(:user) }
  15. let(:alice) { Fabricate(:account, username: 'alice') }
  16. let(:bob) { Fabricate(:account, username: 'bob', domain: 'other.com') }
  17. let(:status) { Fabricate(:status, account: alice) }
  18. context 'with a remote status' do
  19. let(:status) { Fabricate(:status, account: bob) }
  20. before do
  21. status.status_stat.tap do |status_stat|
  22. status_stat.reblogs_count = 10
  23. status_stat.favourites_count = 20
  24. status_stat.save
  25. end
  26. end
  27. context 'with only trusted counts' do
  28. it 'shows the trusted counts' do
  29. expect(subject['reblogs_count']).to eq(10)
  30. expect(subject['favourites_count']).to eq(20)
  31. end
  32. end
  33. context 'with untrusted counts' do
  34. before do
  35. status.status_stat.tap do |status_stat|
  36. status_stat.untrusted_reblogs_count = 30
  37. status_stat.untrusted_favourites_count = 40
  38. status_stat.save
  39. end
  40. end
  41. it 'shows the untrusted counts' do
  42. expect(subject['reblogs_count']).to eq(30)
  43. expect(subject['favourites_count']).to eq(40)
  44. end
  45. end
  46. end
  47. end