mirror of
https://github.com/mastodon/mastodon
synced 2025-04-12 00:56:38 +02:00
Add worker specs
This commit is contained in:
parent
77488e1dab
commit
95f02467c9
@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Fasp::AnnounceAccountLifecycleEventWorker do
|
||||
include ProviderRequestHelper
|
||||
|
||||
let(:account_uri) { 'https://masto.example.com/accounts/1' }
|
||||
let(:subscription) do
|
||||
Fabricate(:fasp_subscription, category: 'account')
|
||||
end
|
||||
let(:provider) { subscription.fasp_provider }
|
||||
let!(:stubbed_request) do
|
||||
stub_provider_request(provider,
|
||||
method: :post,
|
||||
path: '/data_sharing/v0/announcements',
|
||||
response_body: {
|
||||
source: {
|
||||
subscription: {
|
||||
id: subscription.id.to_s,
|
||||
},
|
||||
},
|
||||
category: 'account',
|
||||
eventType: 'new',
|
||||
objectUris: [account_uri],
|
||||
})
|
||||
end
|
||||
|
||||
it 'sends the account uri to subscribed providers' do
|
||||
described_class.new.perform(account_uri, 'new')
|
||||
|
||||
expect(stubbed_request).to have_been_made
|
||||
end
|
||||
end
|
@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Fasp::AnnounceContentLifecycleEventWorker do
|
||||
include ProviderRequestHelper
|
||||
|
||||
let(:status_uri) { 'https://masto.example.com/status/1' }
|
||||
let(:subscription) do
|
||||
Fabricate(:fasp_subscription)
|
||||
end
|
||||
let(:provider) { subscription.fasp_provider }
|
||||
let!(:stubbed_request) do
|
||||
stub_provider_request(provider,
|
||||
method: :post,
|
||||
path: '/data_sharing/v0/announcements',
|
||||
response_body: {
|
||||
source: {
|
||||
subscription: {
|
||||
id: subscription.id.to_s,
|
||||
},
|
||||
},
|
||||
category: 'content',
|
||||
eventType: 'new',
|
||||
objectUris: [status_uri],
|
||||
})
|
||||
end
|
||||
|
||||
it 'sends the status uri to subscribed providers' do
|
||||
described_class.new.perform(status_uri, 'new')
|
||||
|
||||
expect(stubbed_request).to have_been_made
|
||||
end
|
||||
end
|
52
spec/workers/fasp/announce_trend_worker_spec.rb
Normal file
52
spec/workers/fasp/announce_trend_worker_spec.rb
Normal file
@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Fasp::AnnounceTrendWorker do
|
||||
include ProviderRequestHelper
|
||||
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:subscription) do
|
||||
Fabricate(:fasp_subscription,
|
||||
category: 'content',
|
||||
subscription_type: 'trends',
|
||||
threshold_timeframe: 15,
|
||||
threshold_likes: 2)
|
||||
end
|
||||
let(:provider) { subscription.fasp_provider }
|
||||
let!(:stubbed_request) do
|
||||
stub_provider_request(provider,
|
||||
method: :post,
|
||||
path: '/data_sharing/v0/announcements',
|
||||
response_body: {
|
||||
source: {
|
||||
subscription: {
|
||||
id: subscription.id.to_s,
|
||||
},
|
||||
},
|
||||
category: 'content',
|
||||
eventType: 'trending',
|
||||
objectUris: [status.uri],
|
||||
})
|
||||
end
|
||||
|
||||
context 'when the configured threshold is met' do
|
||||
before do
|
||||
Fabricate.times(2, :favourite, status:)
|
||||
end
|
||||
|
||||
it 'sends the account uri to subscribed providers' do
|
||||
described_class.new.perform(status.id, 'favourite')
|
||||
|
||||
expect(stubbed_request).to have_been_made
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the configured threshold is not met' do
|
||||
it 'does not notify any provider' do
|
||||
described_class.new.perform(status.id, 'favourite')
|
||||
|
||||
expect(stubbed_request).to_not have_been_made
|
||||
end
|
||||
end
|
||||
end
|
32
spec/workers/fasp/backfill_worker_spec.rb
Normal file
32
spec/workers/fasp/backfill_worker_spec.rb
Normal file
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Fasp::BackfillWorker do
|
||||
include ProviderRequestHelper
|
||||
|
||||
let(:backfill_request) { Fabricate(:fasp_backfill_request) }
|
||||
let(:provider) { backfill_request.fasp_provider }
|
||||
let(:status) { Fabricate(:status) }
|
||||
let!(:stubbed_request) do
|
||||
stub_provider_request(provider,
|
||||
method: :post,
|
||||
path: '/data_sharing/v0/announcements',
|
||||
response_body: {
|
||||
source: {
|
||||
backfillRequest: {
|
||||
id: backfill_request.id.to_s,
|
||||
},
|
||||
},
|
||||
category: 'content',
|
||||
objectUris: [status.uri],
|
||||
moreObjectsAvailable: false,
|
||||
})
|
||||
end
|
||||
|
||||
it 'sends status uri to provider that requested backfill' do
|
||||
described_class.new.perform(backfill_request.id)
|
||||
|
||||
expect(stubbed_request).to have_been_made
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user