-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor typeahead service #3107
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,28 @@ | ||
class ExecuteTypeahead | ||
def by(type, search_criteria, limit) | ||
execute(type, search_criteria, limit) | ||
end | ||
|
||
private | ||
|
||
def execute(type, search_criteria, limit) | ||
sservice = TypeaheadService.new | ||
sresult = TagList.new | ||
result = case type | ||
when :all | ||
sservice.search_all(search_criteria.query, limit) | ||
when :profiles | ||
sservice.search_profiles(search_criteria.query, limit) | ||
when :notes | ||
sservice.search_notes(search_criteria.query, limit) | ||
when :questions | ||
sservice.search_questions(search_criteria.query, limit) | ||
when :tags | ||
sservice.search_tags(search_criteria.query, limit) | ||
when :comments | ||
sservice.search_comments(search_criteria.query, limit) | ||
else | ||
[] | ||
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 |
---|---|---|
@@ -1,138 +1,123 @@ | ||
require 'test_helper' | ||
|
||
# TODO: Rework to get better inclusion of JsonExpressions pattern matching | ||
# TODO: Add tests for negative matches--check echo of search parameters and null result | ||
# HACK: Parameterize the 'get' URLs to make passing and changing test values easier | ||
|
||
class TypeaheadApiTest < ActiveSupport::TestCase | ||
include Rack::Test::Methods | ||
|
||
def app | ||
Rails.application | ||
end | ||
|
||
def setup | ||
@stxt = 'lat' | ||
@sprofile = 'adm' | ||
@stags = 'everything' | ||
@sseq = 7 | ||
@scom = 'comm' | ||
end | ||
|
||
test 'typeahead all functionality' do | ||
get '/api/typeahead/all?srchString=lat&seq=7' | ||
get '/api/typeahead/all?srchString=Blog' | ||
assert last_response.ok? | ||
|
||
# Expected typeahead pattern | ||
pattern = { | ||
# TODO: Need more/better understanding and data for the test database | ||
# return will be nil for now | ||
# items: nil, | ||
srchParams: { | ||
srchString: @stxt, | ||
seq: @sseq | ||
srchString: 'Blog', | ||
seq: nil | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
|
||
matcher = JsonExpressions::Matcher.new(pattern) | ||
|
||
assert matcher =~ JSON.parse(last_response.body) | ||
json = JSON.parse(last_response.body) | ||
|
||
assert matcher =~ json | ||
end | ||
|
||
test 'typeahead profile functionality' do | ||
get '/api/typeahead/profiles?srchString=adm&seq=7' | ||
get '/api/typeahead/profiles?srchString=Jeff' | ||
assert last_response.ok? | ||
|
||
# Expected profile response pattern | ||
pattern = { | ||
# TODO: Need more/better understanding and data for the test database | ||
# return will be nil for now | ||
# items: nil, | ||
srchParams: { | ||
srchString: @sprofile, | ||
seq: @sseq | ||
srchString: 'Jeff', | ||
seq: nil | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
|
||
matcher = JsonExpressions::Matcher.new(pattern) | ||
|
||
assert matcher =~ JSON.parse(last_response.body) | ||
json = JSON.parse(last_response.body) | ||
|
||
assert matcher =~ json | ||
end | ||
|
||
test 'typeahead notes functionality' do | ||
get '/api/typeahead/notes?srchString=lat&seq=7' | ||
get '/api/typeahead/notes?srchString=Blog' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, a more realistic and readable API call too... |
||
assert last_response.ok? | ||
|
||
# Expected notes pattern | ||
pattern = { | ||
# TODO: Need more/better understanding and data for the test database | ||
# return will be nil for now | ||
# items: nil, | ||
srchParams: { | ||
srchString: @stxt, | ||
seq: @sseq | ||
srchString: 'Blog', | ||
seq: nil | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
|
||
matcher = JsonExpressions::Matcher.new(pattern) | ||
|
||
assert matcher =~ JSON.parse(last_response.body) | ||
json = JSON.parse(last_response.body) | ||
|
||
assert matcher =~ json | ||
end | ||
|
||
test 'typeahead questions functionality' do | ||
get '/api/typeahead/questions?srchString=lat&seq=7' | ||
get '/api/typeahead/questions?srchString=Question' | ||
assert last_response.ok? | ||
|
||
# Expected question pattern | ||
# Returns null right now for test--need to set a better search sequence on demo seed data | ||
pattern = { | ||
# TODO: Need more/better understanding and data for the test database | ||
# return will be nil for now | ||
# items: nil, | ||
srchParams: { | ||
srchString: @stxt, | ||
seq: @sseq | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
srchString: 'Question', | ||
seq: nil, | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
|
||
matcher = JsonExpressions::Matcher.new(pattern) | ||
matcher = JsonExpressions::Matcher.new(pattern) | ||
|
||
assert matcher =~ JSON.parse(last_response.body) | ||
json = JSON.parse(last_response.body) | ||
|
||
assert matcher =~ json | ||
end | ||
|
||
test 'typeahead tags functionality' do | ||
get '/api/typeahead/tags?srchString=everything&seq=7' | ||
get '/api/typeahead/tags?srchString=everything' | ||
assert last_response.ok? | ||
|
||
# Expected tag pattern | ||
pattern = { | ||
# TODO: Need more/better understanding and data for the test database | ||
# return will be nil for now | ||
# items: nil, | ||
srchParams: { | ||
srchString: @stags, | ||
seq: @sseq | ||
srchString: 'everything', | ||
seq: nil | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
|
||
matcher = JsonExpressions::Matcher.new(pattern) | ||
|
||
assert matcher =~ JSON.parse(last_response.body) | ||
json = JSON.parse(last_response.body) | ||
|
||
assert matcher =~ json | ||
end | ||
|
||
test 'typeahead comments functionality' do | ||
get '/api/typeahead/comments?srchString=comm&seq=7' | ||
get '/api/typeahead/comments?srchString=comment' | ||
assert last_response.ok? | ||
|
||
# Expected comment pattern | ||
pattern = { | ||
srchParams: { | ||
srchString: @scom, | ||
seq: @sseq | ||
srchString: 'comment', | ||
seq: nil | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
|
||
matcher = JsonExpressions::Matcher.new(pattern) | ||
|
||
assert matcher =~ JSON.parse(last_response.body) | ||
json = JSON.parse(last_response.body) | ||
|
||
assert matcher =~ json | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So much better/more readable!!