* Article query spec for scheduled articles * Added scheduled article badge on the user dashboard * Added published_at field to editor options * Accept and validate published_at from editor * Refactor published_at validation * Allow 1-minute difference in published_at * Notice on an unpublished article page * Added specs for 'Click to edit' link on scheduled article preview page * ContextNotification model * Articles::Publish worker * Added specs for articles publish worker * Schedule publish articles worker * Added tests to check for scheduled posts in feeds * Don't allow managing scheduled articles * Don't send notifications for scheduled articles * Set published_at in Articles::Updater when publishing * Published_at value in post options * Pass timezone and set published_at accordingly * Limit setting published_at to the future * Readonly published_at for articles that were already published * Chagning published_at format in editor v1 (start) * Changed published_at format in frontmatter, specs * Added specs for updating published_at from frontmatter * Fixed accepting past published_at for articles published_from_feed * Enabled published_at validation: don't allow updating published_at for already published articles * Validate published_at on create * Added a spec for updating published_at for exported articles * Fixed specs related to creating articles with past published_at * Fixed specs related to past published_at for articles * Added a hack so that admins would be able to update published_at * Switch button text schedule/publish when changin publishedAt * Fixed saving published_at with timezone * Added a feature flag for scheduling articles * Default text in markdown editor depends on feature flag * Enable article editor cache again * Fixed the default value in the markdown editor * Fix sitemaps spec * Removed tooltip * Fixed articles update specs * Added missing locales * Fixed article create specs * Fixed spec * Removed commented code * Returned enabling extensions in the schema * Returned accidentally deleted constraint * Make articles query spec more stable Co-authored-by: Jeremy Friesen <jeremy.n.friesen@gmail.com> * Removed commented code * Removed unused code * A clearer policy Co-authored-by: Jeremy Friesen <jeremy.n.friesen@gmail.com> * Use StringInquirer for article current state * Added a note and todo to articles factory past trait * Remove duplicated PropType Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Refactor query in the Articles::PublishWorker Co-authored-by: Mac Siri <krairit.siri@gmail.com> * Refactor articleForm.jsx Co-authored-by: Mac Siri <krairit.siri@gmail.com> * Removed specs that are no longer relevant * Removed useless onKeyUp on a hidden input * Refactored articleForm * Hide scheduling from post options when published_at is readonly * Run sends notifications worker every 5 minutes instead of every minute Co-authored-by: Jeremy Friesen <jeremy.n.friesen@gmail.com> Co-authored-by: Suzanne Aitchison <suzanne@forem.com> Co-authored-by: Mac Siri <krairit.siri@gmail.com>
104 lines
3.7 KiB
Ruby
104 lines
3.7 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Articles::PublishWorker, type: :worker do
|
|
include_examples "#enqueues_on_correct_queue", "medium_priority"
|
|
|
|
describe "#perform" do
|
|
let(:worker) { subject }
|
|
let!(:article) { create(:article, published: true) }
|
|
|
|
it "calls Slack::Messengers::ArticlePublished to send slack notifications" do
|
|
allow(Slack::Messengers::ArticlePublished).to receive(:call)
|
|
worker.perform
|
|
expect(Slack::Messengers::ArticlePublished).to have_received(:call).with(article: article)
|
|
end
|
|
|
|
it "sends notifications to mentioned users and followers" do
|
|
allow(Notification).to receive(:send_to_mentioned_users_and_followers)
|
|
worker.perform
|
|
expect(Notification).to have_received(:send_to_mentioned_users_and_followers).with(article)
|
|
end
|
|
|
|
it "schedules Notifications::NotifiableActionWorker" do
|
|
args = [article.id, "Article", "Published"]
|
|
sidekiq_assert_enqueued_with(job: Notifications::NotifiableActionWorker, args: args) do
|
|
worker.perform
|
|
end
|
|
end
|
|
|
|
it "doesn't send notifications for an old article" do
|
|
old_article = create(:article, :past, published: true, past_published_at: 1.year.ago)
|
|
allow(Notification).to receive(:send_to_mentioned_users_and_followers)
|
|
worker.perform
|
|
expect(Notification).not_to have_received(:send_to_mentioned_users_and_followers).with(old_article)
|
|
end
|
|
|
|
it "doesn't send notifications for a scheduled article" do
|
|
scheduled_article = create(:article, published: true, published_at: 1.day.from_now)
|
|
allow(Notification).to receive(:send_to_mentioned_users_and_followers)
|
|
worker.perform
|
|
expect(Notification).not_to have_received(:send_to_mentioned_users_and_followers).with(scheduled_article)
|
|
end
|
|
|
|
context "with 2 articles" do
|
|
let!(:article2) { create(:article, published: true) }
|
|
|
|
it "schedules Notifications::NotifiableActionWorker twice for 2 articles" do
|
|
sidekiq_assert_enqueued_jobs(2, only: Notifications::NotifiableActionWorker) do
|
|
worker.perform
|
|
end
|
|
end
|
|
|
|
it "sends notifications to mentioned users and followers for 2 articles" do
|
|
allow(Notification).to receive(:send_to_mentioned_users_and_followers)
|
|
worker.perform
|
|
expect(Notification).to have_received(:send_to_mentioned_users_and_followers).with(article2)
|
|
end
|
|
end
|
|
|
|
describe "creating notifications" do
|
|
let!(:user2) { create(:user) }
|
|
let(:article2) { create(:article, published: true, user: user2) }
|
|
|
|
before do
|
|
user2.follow(article.user)
|
|
end
|
|
|
|
it "creates a notification eventually" do
|
|
expect do
|
|
sidekiq_perform_enqueued_jobs(only: Notifications::NotifiableActionWorker) do
|
|
worker.perform
|
|
end
|
|
end.to change(Notification, :count).by(1)
|
|
end
|
|
|
|
it "creates a context notification as well" do
|
|
expect do
|
|
sidekiq_perform_enqueued_jobs(only: Notifications::NotifiableActionWorker) do
|
|
worker.perform
|
|
end
|
|
end.to change(ContextNotification, :count).by(1)
|
|
end
|
|
|
|
it "creates a notification for each article" do
|
|
article2
|
|
article.user.follow(article2.user)
|
|
expect do
|
|
sidekiq_perform_enqueued_jobs(only: Notifications::NotifiableActionWorker) do
|
|
worker.perform
|
|
end
|
|
end.to change(Notification, :count).by(2)
|
|
end
|
|
|
|
it "creates a ContextNotification for each article" do
|
|
article2
|
|
article.user.follow(article2.user)
|
|
expect do
|
|
sidekiq_perform_enqueued_jobs(only: Notifications::NotifiableActionWorker) do
|
|
worker.perform
|
|
end
|
|
end.to change(ContextNotification, :count).by(2)
|
|
end
|
|
end
|
|
end
|
|
end
|