logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

post_status_service_spec.rb (5544B)


  1. require 'rails_helper'
  2. RSpec.describe PostStatusService do
  3. subject { PostStatusService.new }
  4. it 'creates a new status' do
  5. account = Fabricate(:account)
  6. text = "test status update"
  7. status = subject.call(account, text)
  8. expect(status).to be_persisted
  9. expect(status.text).to eq text
  10. end
  11. it 'creates a new response status' do
  12. in_reply_to_status = Fabricate(:status)
  13. account = Fabricate(:account)
  14. text = "test status update"
  15. status = subject.call(account, text, in_reply_to_status)
  16. expect(status).to be_persisted
  17. expect(status.text).to eq text
  18. expect(status.thread).to eq in_reply_to_status
  19. end
  20. it 'creates a sensitive status' do
  21. status = create_status_with_options(sensitive: true)
  22. expect(status).to be_persisted
  23. expect(status).to be_sensitive
  24. end
  25. it 'creates a status with spoiler text' do
  26. spoiler_text = "spoiler text"
  27. status = create_status_with_options(spoiler_text: spoiler_text)
  28. expect(status).to be_persisted
  29. expect(status.spoiler_text).to eq spoiler_text
  30. end
  31. it 'creates a status with empty default spoiler text' do
  32. status = create_status_with_options(spoiler_text: nil)
  33. expect(status).to be_persisted
  34. expect(status.spoiler_text).to eq ''
  35. end
  36. it 'creates a status with the given visibility' do
  37. status = create_status_with_options(visibility: :private)
  38. expect(status).to be_persisted
  39. expect(status.visibility).to eq "private"
  40. end
  41. it 'creates a status for the given application' do
  42. application = Fabricate(:application)
  43. status = create_status_with_options(application: application)
  44. expect(status).to be_persisted
  45. expect(status.application).to eq application
  46. end
  47. it 'creates a status with a language set' do
  48. account = Fabricate(:account)
  49. text = 'This is an English text.'
  50. status = subject.call(account, text)
  51. expect(status.language).to eq 'en'
  52. end
  53. it 'processes mentions' do
  54. mention_service = double(:process_mentions_service)
  55. allow(mention_service).to receive(:call)
  56. allow(ProcessMentionsService).to receive(:new).and_return(mention_service)
  57. account = Fabricate(:account)
  58. status = subject.call(account, "test status update")
  59. expect(ProcessMentionsService).to have_received(:new)
  60. expect(mention_service).to have_received(:call).with(status)
  61. end
  62. it 'processes hashtags' do
  63. hashtags_service = double(:process_hashtags_service)
  64. allow(hashtags_service).to receive(:call)
  65. allow(ProcessHashtagsService).to receive(:new).and_return(hashtags_service)
  66. account = Fabricate(:account)
  67. status = subject.call(account, "test status update")
  68. expect(ProcessHashtagsService).to have_received(:new)
  69. expect(hashtags_service).to have_received(:call).with(status)
  70. end
  71. it 'gets distributed' do
  72. allow(DistributionWorker).to receive(:perform_async)
  73. allow(Pubsubhubbub::DistributionWorker).to receive(:perform_async)
  74. allow(ActivityPub::DistributionWorker).to receive(:perform_async)
  75. account = Fabricate(:account)
  76. status = subject.call(account, "test status update")
  77. expect(DistributionWorker).to have_received(:perform_async).with(status.id)
  78. expect(Pubsubhubbub::DistributionWorker).to have_received(:perform_async).with(status.stream_entry.id)
  79. expect(ActivityPub::DistributionWorker).to have_received(:perform_async).with(status.id)
  80. end
  81. it 'crawls links' do
  82. allow(LinkCrawlWorker).to receive(:perform_async)
  83. account = Fabricate(:account)
  84. status = subject.call(account, "test status update")
  85. expect(LinkCrawlWorker).to have_received(:perform_async).with(status.id)
  86. end
  87. it 'attaches the given media to the created status' do
  88. account = Fabricate(:account)
  89. media = Fabricate(:media_attachment)
  90. status = subject.call(
  91. account,
  92. "test status update",
  93. nil,
  94. media_ids: [media.id],
  95. )
  96. expect(media.reload.status).to eq status
  97. end
  98. it 'does not allow attaching more than 4 files' do
  99. account = Fabricate(:account)
  100. expect do
  101. subject.call(
  102. account,
  103. "test status update",
  104. nil,
  105. media_ids: [
  106. Fabricate(:media_attachment, account: account),
  107. Fabricate(:media_attachment, account: account),
  108. Fabricate(:media_attachment, account: account),
  109. Fabricate(:media_attachment, account: account),
  110. Fabricate(:media_attachment, account: account),
  111. ].map(&:id),
  112. )
  113. end.to raise_error(
  114. Mastodon::ValidationError,
  115. I18n.t('media_attachments.validations.too_many'),
  116. )
  117. end
  118. it 'does not allow attaching both videos and images' do
  119. account = Fabricate(:account)
  120. expect do
  121. subject.call(
  122. account,
  123. "test status update",
  124. nil,
  125. media_ids: [
  126. Fabricate(:media_attachment, type: :video, account: account),
  127. Fabricate(:media_attachment, type: :image, account: account),
  128. ].map(&:id),
  129. )
  130. end.to raise_error(
  131. Mastodon::ValidationError,
  132. I18n.t('media_attachments.validations.images_and_video'),
  133. )
  134. end
  135. it 'returns existing status when used twice with idempotency key' do
  136. account = Fabricate(:account)
  137. status1 = subject.call(account, 'test', nil, idempotency: 'meepmeep')
  138. status2 = subject.call(account, 'test', nil, idempotency: 'meepmeep')
  139. expect(status2.id).to eq status1.id
  140. end
  141. def create_status_with_options(**options)
  142. subject.call(Fabricate(:account), 'test', nil, options)
  143. end
  144. end