Skip to content

Commit

Permalink
Working toward including response in GraphQL
Browse files Browse the repository at this point in the history
GraphQL

GraphQL

GraphQL tests
  • Loading branch information
matt-bernhardt committed Sep 26, 2024
1 parent 65e2d5c commit 02bc065
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/graphql/types/categories_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Types
class CategoriesType < Types::BaseObject
description 'Information about one category linked to this search term'

field :confidence, Float, null: false, description: 'The application\'s confidence that the term belongs to this category - measured from 0.0 to 1.0'
field :name, String, null: false, description: 'The name of this category'

def name
@object.category.name
end
end
end
5 changes: 5 additions & 0 deletions app/graphql/types/search_event_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Types
class SearchEventType < Types::BaseObject
field :categories, [Types::CategoriesType], description: 'The list of categories linked to term provided in this search'
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :detectors, Types::DetectorsType
field :id, ID, null: false
Expand All @@ -14,6 +15,10 @@ def phrase
@object.term.phrase
end

def categories
@object.term.categorizations
end

def detectors
@object.term.phrase
end
Expand Down
5 changes: 5 additions & 0 deletions app/graphql/types/term_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Types
class TermType < Types::BaseObject
field :categories, [Types::CategoriesType], description: 'The list of categories linked to this term'
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :detectors, Types::DetectorsType
field :id, ID, null: false
Expand All @@ -14,6 +15,10 @@ def occurence_count
@object.search_events.count
end

def categories
@object.categorizations
end

def detectors
@object.phrase
end
Expand Down
32 changes: 32 additions & 0 deletions test/controllers/graphql_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,36 @@ class GraphqlControllerTest < ActionDispatch::IntegrationTest
assert_nil(json['data']['logSearchEvent']['detectors']['standardIdentifiers'].first['details']['authors'])
end
end

test 'search event query can return categorization details for searches that trip a detector' do
post '/graphql', params: { query: '{
logSearchEvent(sourceSystem: "timdex", searchTerm: "https://doi.org/10.1080/10509585.2015.1092083.") {
categories {
name
confidence
}
}
}' }

json = response.parsed_body

assert_equal 'Transactional', json['data']['logSearchEvent']['categories'].first['name']
assert_equal 0.95, json['data']['logSearchEvent']['categories'].first['confidence']
end

test 'term lookup query can return categorization details for searches that trip a detector' do
post '/graphql', params: { query: '{
lookupTerm(searchTerm: "10.1016/j.physio.2010.12.004") {
categories {
name
confidence
}
}
}' }

json = response.parsed_body

assert_equal 'Transactional', json['data']['lookupTerm']['categories'].first['name']
assert_equal 0.95, json['data']['lookupTerm']['categories'].first['confidence']
end
end
17 changes: 17 additions & 0 deletions test/fixtures/categorizations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# == Schema Information
#
# Table name: categorizations
#
# id :integer not null, primary key
# category_id :integer not null
# term_id :integer not null
# confidence :float
# detector_version :string
# created_at :datetime not null
# updated_at :datetime not null
#
one:
category: transactional
term: doi
confidence: 0.95
detector_version: 1

0 comments on commit 02bc065

Please sign in to comment.