discourse-rewind/spec/services/fetch_reports_spec.rb
Kris 972cc6e5d9
UX: restyling for 2025 (#28)
This generally updates the styles for the 2025 version. I also made more
features work in development environments (so it's easier to test) and
fixed an issue with invites that was causing the report to not show.


<img width="400" alt="image"
src="https://github.com/user-attachments/assets/69a62b79-12e3-4539-a82c-9bbf9673abe2"
/>

<img width="1554" height="896" alt="image"
src="https://github.com/user-attachments/assets/60fabac5-6f20-4e01-9679-fd228c6850c2"
/>

<img width="754" height="459" alt="image"
src="https://github.com/user-attachments/assets/6725c6e2-1bac-417e-b4ee-190841ab656b"
/>

<img width="1472" height="490" alt="image"
src="https://github.com/user-attachments/assets/87c95e6a-5d78-4fb6-9f2d-dad13bcc9788"
/>

<img width="1480" height="702" alt="image"
src="https://github.com/user-attachments/assets/67bec8f9-dce5-4077-a07d-fe9e13696958"
/>
2025-11-18 09:03:41 -05:00

61 lines
1.7 KiB
Ruby

# frozen_string_literal: true
RSpec.describe(DiscourseRewind::FetchReports) do
describe ".call" do
subject(:result) { described_class.call(**dependencies) }
fab!(:current_user, :user)
let(:guardian) { Guardian.new(current_user) }
let(:dependencies) { { guardian: } }
context "when in january" do
before { freeze_time DateTime.parse("2021-01-22") }
it "computes the correct previous year" do
expect(result.year).to eq(2020)
end
end
context "when in december" do
before { freeze_time DateTime.parse("2021-12-22") }
it "computes the correct previous year" do
expect(result.year).to eq(2021)
end
end
context "when out of valid months december" do
before { freeze_time DateTime.parse("2021-02-22") }
it { is_expected.to fail_to_find_a_model(:year) }
end
context "when reports is cached" do
before { freeze_time DateTime.parse("2021-12-22") }
it "returns the cached reports" do
initial_count = result.reports.length
expect(initial_count).to be > 0
allow(DiscourseRewind::Action::TopWords).to receive(:call)
expect(result.reports.length).to eq(initial_count)
expect(DiscourseRewind::Action::TopWords).to_not have_received(:call)
end
end
context "when reports is not cached" do
before do
freeze_time DateTime.parse("2021-01-22")
Discourse.redis.del("rewind:#{current_user.username}:2020")
end
it "returns the reports" do
allow(DiscourseRewind::Action::TopWords).to receive(:call)
expect(result.reports.length).to be > 0
expect(DiscourseRewind::Action::TopWords).to have_received(:call)
end
end
end
end