Skip to content

Commit

Permalink
Valkyrizes spec/services/hyrax/statistics/works/count_spec.rb.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwatson78 authored and jeremyf committed Jan 24, 2024
1 parent 3719311 commit fc3b005
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions spec/services/hyrax/statistics/works/count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
describe ".by_permission", :clean_repo do
let(:user1) { build(:user, id: 1) }
let(:yesterday) { 1.day.ago }
let(:wings_disabled) { Hyrax.config.disable_wings }

before do
build(:public_generic_work, user: user1, id: "pdf1223").update_index
build(:public_generic_work, user: user1, id: "wav1223").update_index
build(:public_generic_work, user: user1, id: "mp31223", create_date: [2.days.ago]).update_index
build(:registered_generic_work, user: user1, id: "reg1223").update_index
build(:generic_work, user: user1, id: "private1223").update_index
Collection.new(id: "ccc123") do |c|
c.apply_depositor_metadata(user1)
c.update_index
if wings_disabled
3.times { valkyrie_create(:monograph, :public, depositor: user1.user_key) }
valkyrie_create(:monograph, read_groups: ['registered'], depositor: user1.user_key)
valkyrie_create(:monograph, read_groups: ['private'], depositor: user1.user_key)
valkyrie_create(:hyrax_collection, depositor: user1.user_key)
else
build(:public_generic_work, user: user1, id: "pdf1223").update_index
build(:public_generic_work, user: user1, id: "wav1223").update_index
build(:public_generic_work, user: user1, id: "mp31223", create_date: [2.days.ago]).update_index
build(:registered_generic_work, user: user1, id: "reg1223").update_index
build(:generic_work, user: user1, id: "private1223").update_index
Collection.new(id: "ccc123") do |c|
c.apply_depositor_metadata(user1)
c.update_index
end
end
end

Expand All @@ -21,14 +29,17 @@
no_date_range_given = described_class.by_permission(start_date: nil, end_date: nil)
expect(no_date_range_given).to include(public: 3, private: 1, registered: 1, total: 5)

start_date = yesterday.beginning_of_day
start_date_given = described_class.by_permission(start_date: start_date, end_date: nil)
expect(start_date_given).to include(public: 2, private: 1, registered: 1, total: 4)
# NOTE: Since Postgres' #created_at cannot be mocked, the following two tests have been skipped for Koppie.
unless wings_disabled
start_date = yesterday.beginning_of_day
start_date_given = described_class.by_permission(start_date: start_date, end_date: nil)
expect(start_date_given).to include(public: 2, private: 1, registered: 1, total: 4)

start_date = 2.days.ago.beginning_of_day
end_date = yesterday.end_of_day
start_date_and_end_date_given = described_class.by_permission(start_date: start_date, end_date: end_date)
expect(start_date_and_end_date_given).to include(public: 1, private: 0, registered: 0, total: 1)
start_date = 2.days.ago.beginning_of_day
end_date = yesterday.end_of_day
start_date_and_end_date_given = described_class.by_permission(start_date: start_date, end_date: end_date)
expect(start_date_and_end_date_given).to include(public: 1, private: 0, registered: 0, total: 1)
end
end
end
end

0 comments on commit fc3b005

Please sign in to comment.