Testing: Add convenience option to Channel factory

This commit is contained in:
Ryan Lue 2020-03-13 02:28:50 +08:00 committed by Thorsten Eckel
parent 227b2b25b3
commit c290a89a8b
2 changed files with 12 additions and 37 deletions

View file

@ -47,13 +47,9 @@ FactoryBot.define do
}, },
search: [ search: [
{ {
term: 'zammad', term: search_term,
group_id: Group.first.id group_id: Group.first.id
}, },
{
term: 'hash_tag1',
group_id: Group.first.id
}
], ],
}, },
subscribed_to_webhook_id: external_credential.credentials[:webhook_id], subscribed_to_webhook_id: external_credential.credentials[:webhook_id],
@ -65,6 +61,7 @@ FactoryBot.define do
external_credential { create(:twitter_credential) } external_credential { create(:twitter_credential) }
oauth_token { external_credential.credentials[:oauth_token] } oauth_token { external_credential.credentials[:oauth_token] }
oauth_token_secret { external_credential.credentials[:oauth_token_secret] } oauth_token_secret { external_credential.credentials[:oauth_token_secret] }
search_term { 'zammad' }
end end
trait :legacy do trait :legacy do

View file

@ -904,24 +904,15 @@ RSpec.describe Channel::Driver::Twitter do
end end
describe 'Race condition: when #fetch finds a half-processed, outgoing tweet' do describe 'Race condition: when #fetch finds a half-processed, outgoing tweet' do
subject!(:channel) { create(:twitter_channel, custom_options: custom_options) } subject!(:channel) do
create(:twitter_channel,
let(:custom_options) do search_term: 'zammadzammadzammad',
{ custom_options: {
user: { user: {
# Must match connected Twitter account's user ID (on Twitter)-- # Must match outgoing tweet author Twitter user ID
# that's how #fetch distinguishes between agents' tweets and other people's. id: '1205290247124217856',
id: '1205290247124217856' },
}, })
sync: {
search: [
{
term: 'zammadzammadzammad',
group_id: Group.first.id
}
]
}
}
end end
let!(:tweet) { create(:twitter_article, body: 'zammadzammadzammad') } let!(:tweet) { create(:twitter_article, body: 'zammadzammadzammad') }
@ -969,20 +960,7 @@ RSpec.describe Channel::Driver::Twitter do
end end
context 'for very common search terms' do context 'for very common search terms' do
subject(:channel) { create(:twitter_channel, custom_options: custom_options) } subject(:channel) { create(:twitter_channel, search_term: 'coronavirus') }
let(:custom_options) do
{
sync: {
search: [
{
term: 'coronavirus',
group_id: Group.first.id
}
]
}
}
end
let(:twitter_articles) { Ticket::Article.joins(:type).where(ticket_article_types: { name: 'twitter status' }) } let(:twitter_articles) { Ticket::Article.joins(:type).where(ticket_article_types: { name: 'twitter status' }) }