docbrown/spec/requests/admin/overview_spec.rb
Anna Buianova ff76cdd3c5
Scheduling articles (#17939)
* 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>
2022-07-07 17:32:49 +03:00

106 lines
3.2 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin", type: :request do
let(:super_admin) { create(:user, :super_admin) }
before do
sign_in super_admin
allow(FeatureFlag).to receive(:enabled?).and_call_original
end
describe "Last deployed and Latest Commit ID card" do
before do
ForemInstance.instance_variable_set(:@deployed_at, nil)
end
after do
ForemInstance.instance_variable_set(:@deployed_at, nil)
end
it "shows the correct value if the Last deployed time is available" do
stub_const("ENV", ENV.to_h.merge("HEROKU_RELEASE_CREATED_AT" => "Some date"))
get admin_path
expect(response.body).to include(ENV.fetch("HEROKU_RELEASE_CREATED_AT", nil))
end
end
describe "analytics" do
subject(:body) { response.body }
before do
Timecop.freeze("2019-04-30T12:00:00Z")
get admin_path
end
after { Timecop.return }
it { is_expected.to include("Analytics and trends") }
it { is_expected.to include("Yesterday") }
xit { is_expected.to include("Apr 23") }
xit "displays correct number of posts from past week" do
create(:article, published_at: Time.current)
create(:article, published_at: 1.day.ago)
create(:article, published_at: 7.days.ago)
create(:article, published_at: 8.days.ago)
get admin_path
expect(body).to include "2</span> Posts"
end
it "displays correct number of comments from past week" do
create(:comment, created_at: Time.current)
create(:comment, created_at: 1.day.ago)
create(:comment, created_at: 8.days.ago)
get admin_path
expect(body).to include "1</span> Comments"
end
it "displays correct number of reactions from past week" do
create(:reaction, created_at: Time.current)
create(:reaction, created_at: 3.days.ago)
create(:reaction, created_at: 2.weeks.ago)
get admin_path
expect(body).to include "1</span> Reaction"
end
it "displays correct number of new members from past week" do
create(:user, registered_at: Time.current)
create(:user, registered_at: 2.days.ago)
create(:user, registered_at: 10.days.ago)
get admin_path
expect(body).to include "1</span> New members"
end
it "does not display data from previous weeks", :aggregate_failures do
create(:article, :past, past_published_at: 8.days.ago)
create(:comment, created_at: 2.weeks.ago)
create(:reaction, created_at: 1.month.ago)
create(:user, registered_at: 10.days.ago)
get admin_path
expect(body).to include "0</span> Posts"
expect(body).to include "0</span> Comments"
expect(body).to include "0</span> Reactions"
expect(body).to include "0</span> New members"
end
it "does not display data from today", :aggregate_failures do
create(:article, published_at: Time.current)
create(:comment, created_at: Time.current)
create(:reaction, created_at: Time.current)
create(:user, registered_at: Time.current)
get admin_path
expect(body).to include "0</span> Posts"
expect(body).to include "0</span> Comments"
expect(body).to include "0</span> Reactions"
expect(body).to include "0</span> New members"
end
end
end