Skip to content

Commit

Permalink
Test for searches with multiple detections
Browse files Browse the repository at this point in the history
** Why are these changes being introduced:

* Some of our search traffic may meet conditions of multiple detections.
  We need our reports to correctly count these events in all relevant
  categories.

** Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/tco-43

** How does this address that need:

* This starts by creating a single term fixture that should trigger more
  than one detector - a citation which includes both a DOI and PubMedID
  for an article.

* A new test is also created, which generates a report based only on
  a search for this term, which asserts that two different counters
  should have non-zero numbers.

** Document any side effects to this change:

* It is a bit awkward to have too many tests that start by deleting
  existing records from our fixtures - but we're not yet at the point
  where we'd need something like a factory. We'll talk about that at
  some point if the need more clearly arises.
  • Loading branch information
matt-bernhardt committed Aug 14, 2024
1 parent 806ecc3 commit aa5026b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions test/fixtures/terms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ isbn_9781319145446:

journal_nature_medicine:
phrase: 'nature medicine'

multiple_detections:
phrase: 'Environmental and Health Impacts of Air Pollution: A Review. Frontiers in Public Health. PMID: 32154200. DOI: 10.3389/fpubh.2020.00014'
16 changes: 14 additions & 2 deletions test/models/metrics/algorithms_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class Algorithms < ActiveSupport::TestCase
assert_equal 2, aggregate.unmatched
end

test 'searches with multiple patterns are accounted for correctly' do
# Drop all search events to ensure the report has only what we care about.
SearchEvent.delete_all

SearchEvent.create(term: terms(:multiple_detections), source: 'test')

aggregate = Metrics::Algorithms.new.generate(DateTime.now)

assert_equal 1, aggregate.doi
assert_equal 1, aggregate.pmid
end

test 'creating lots of searchevents leads to correct data for monthly' do
# drop all searchevents to make math easier and minimize fragility over time as more fixtures are created
SearchEvent.delete_all
Expand Down Expand Up @@ -97,7 +109,7 @@ class Algorithms < ActiveSupport::TestCase
test 'dois counts are included in total aggregation' do
aggregate = Metrics::Algorithms.new.generate

assert_equal 1, aggregate.doi
assert_equal 2, aggregate.doi
end

test 'issns counts are included in total aggregation' do
Expand All @@ -115,7 +127,7 @@ class Algorithms < ActiveSupport::TestCase
test 'pmids counts are included in total aggregation' do
aggregate = Metrics::Algorithms.new.generate

assert_equal 2, aggregate.pmid
assert_equal 3, aggregate.pmid
end

test 'journal exact counts are included in total aggregation' do
Expand Down

0 comments on commit aa5026b

Please sign in to comment.