Skip to content

Commit

Permalink
Added degree level to dropdown, created filtering test
Browse files Browse the repository at this point in the history
  • Loading branch information
nwalker2398 authored and JackBlackLight committed Jan 4, 2024
1 parent edde100 commit 2f8e41d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/forms/usage_statistics_reports_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class UsageStatisticsReportsForm < FormObject
'Resource Type' => SolrDocument.field_semantics[:resource_type],
'Organization' => SolrDocument.field_semantics[:organization],
'Department' => SolrDocument.field_semantics[:department],
'Degree Level' => SolrDocument.field_semantics[:degree_level],
'Series' => SolrDocument.field_semantics[:columbia_series],
'Non CU Series' => SolrDocument.field_semantics[:non_columbia_series],
'CUL DOI' => SolrDocument.field_semantics[:id]
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_05_18_134528) do
ActiveRecord::Schema.define(version: 2022_12_08_202313) do

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down
35 changes: 35 additions & 0 deletions spec/academic_commons/metrics/usage_statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.describe AcademicCommons::Metrics::UsageStatistics do
let(:uni) { 'abc123' }
let(:degree_level) { 'Doctoral' }
let(:item_identifier) { '10.7916/ALICE' }
let(:item_fedora_pid) { 'actest:1' }
let(:other_item_identifier) { '10.7916/TESTDOC5' }
Expand Down Expand Up @@ -102,12 +103,33 @@
)
end

let(:item_by_degree_level_params) do
{
rows: 100_000, sort: 'title_sort asc', q: nil, page: 1,
fq: ["degree_level_name_ssim:\"#{degree_level}\"", 'has_model_ssim:"info:fedora/ldpd:ContentAggregator"'],
fl: 'title_ssi,id,cul_doi_ssi,fedora3_pid_ssi,publisher_doi_ssi,genre_ssim,record_creation_dtsi,object_state_ssi,free_to_read_start_date_ssi'
}
end
let(:item_by_degree_level_response) do
wrap_solr_response_data(
'response' => {
'docs' => [
{ 'id' => item_identifier, 'title_ssi' => 'First Test Document', 'object_state_ssi' => 'A', 'record_creation_dtsi' => '2018-08-07T03:40:22Z',
'cul_doi_ssi' => item_identifier, 'fedora3_pid_ssi' => item_fedora_pid, 'publisher_doi_ssi' => '', 'genre_ssim' => '', 'degree_level_name_ssim' => 'Doctoral' },
{ 'id' => other_item_identifier, 'title_ssi' => 'Second Test Document', 'object_state_ssi' => 'A', 'record_creation_dtsi' => '2018-08-07T03:40:22Z',
'cul_doi_ssi' => other_item_identifier, 'fedora3_pid_ssi' => other_item_fedora_pid, 'publisher_doi_ssi' => '', 'genre_ssim' => '', 'degree_level_name_ssim' => 'Doctoral' }
]
}
)
end

before do
allow(Blacklight.default_index).to receive(:search).with(any_by_author_params).and_return(any_by_author_response)
allow(Blacklight.default_index).to receive(:search).with(item_by_author_params).and_return(item_by_author_response)
allow(Blacklight.default_index).to receive(:search).with(assets_for_item_params).and_return(assets_for_item_response)
allow(Blacklight.default_index).to receive(:search).with(assets_for_other_item_params).and_return(assets_for_other_item_response)
allow(Blacklight.default_index).to receive(:search).with(list_items_params).and_return(list_items_response)
allow(Blacklight.default_index).to receive(:search).with(item_by_degree_level_params).and_return(item_by_degree_level_response)
end

describe '.new' do
Expand Down Expand Up @@ -226,6 +248,19 @@
expect(usage_stats.total_for(Statistic::DOWNLOAD, :lifetime)).to be 1
end
end

context 'when requesting stats for degree level' do
subject(:usage_stats) do
described_class.new(
solr_params: item_by_degree_level_params,
include_streaming: true
).calculate_lifetime
end

it 'returns correct results' do
expect(subject.map(&:document).map(&:to_h)).to eq item_by_degree_level_response.documents.map(&:to_h)
end
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/fedora_objs/mods.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<mods:dateIssued encoding="w3cdtf">1865</mods:dateIssued>
</mods:originInfo>

<mods:extension type="degree">
<mods:name type="text">Doctoral</mods:name>
<mods:grantor type="text">The Grantonator</mods:grantor>
<mods:discipline type="text">Disciplinary Studies</mods:discipline>
</mods:extension>

<mods:language>
<mods:languageTerm type="text">English</mods:languageTerm>
</mods:language>
Expand Down

0 comments on commit 2f8e41d

Please sign in to comment.