-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Why these changes are being introduced: We need a GraphQL interface to record SearchEvents from TACOS consumers. Relevant ticket(s): https://mitlibraries.atlassian.net/browse/ENGX-234 How this addresses that need: This adds a SearchEvent type and corresponding query field that returns information about the search event and creates a new SearchEvent (and Term, if applicable). Side effects of this change: * Removed a couple of generated GraphQL test fields. * Miscellaneous rubocop fixes.
- Loading branch information
Showing
4 changed files
with
76 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
class MutationType < Types::BaseObject | ||
# TODO: remove me | ||
field :test_field, String, null: false, | ||
description: "An example field added by the generator" | ||
def test_field | ||
"Hello World" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
class SearchEventType < Types::BaseObject | ||
field :id, ID, null: false | ||
field :term_id, Integer | ||
field :source, String | ||
field :created_at, GraphQL::Types::ISO8601DateTime, null: false | ||
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'test_helper' | ||
|
||
class GraphqlControllerTest < ActionDispatch::IntegrationTest | ||
test 'search event query returns relevant data' do | ||
post '/graphql', params: { query: '{ | ||
logSearchEvent(sourceSystem: "bento", searchTerm: "range life") { | ||
termId | ||
source | ||
createdAt | ||
updatedAt | ||
} | ||
}' } | ||
assert_equal(200, response.status) | ||
json = JSON.parse(response.body) | ||
term_id = Term.last.id | ||
|
||
assert_equal 'bento', json['data']['logSearchEvent']['source'] | ||
assert_equal term_id, json['data']['logSearchEvent']['termId'] | ||
assert_equal Date.today, json['data']['logSearchEvent']['createdAt'].to_date | ||
assert_equal Date.today, json['data']['logSearchEvent']['updatedAt'].to_date | ||
end | ||
|
||
test 'search event query creates a new term if one does not exist' do | ||
initial_term_count = Term.count | ||
post '/graphql', params: { query: '{ | ||
logSearchEvent(sourceSystem: "bento", searchTerm: "range life") { | ||
termId | ||
source | ||
createdAt | ||
updatedAt | ||
} | ||
}' } | ||
assert_equal(200, response.status) | ||
assert_equal Term.count, (initial_term_count + 1) | ||
assert_equal 'range life', Term.last.phrase | ||
end | ||
|
||
test 'search event query does not create a new term if phrase is already stored' do | ||
initial_term_count = Term.count | ||
post '/graphql', params: { query: '{ | ||
logSearchEvent(sourceSystem: "timdex", searchTerm: "Super cool search") { | ||
termId | ||
source | ||
createdAt | ||
updatedAt | ||
} | ||
}' } | ||
assert_equal(200, response.status) | ||
assert_equal Term.count, initial_term_count | ||
end | ||
end |