-
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
API Search profiles: adding parameter to search (only) by username #3235
Changes from all commits
f851f23
9e1654c
f7a09d5
14c6823
330b104
0b92a20
fcb2c90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ test_user: | |
password_salt: <%= salt = Authlogic::Random.hex_token %> | ||
crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("secretive" + salt) %> | ||
persistence_token: <%= Authlogic::Random.hex_token %> | ||
bio: '' | ||
bio: 'I love ruby' | ||
created_at: <%= Time.now %> | ||
updated_at: <%= Time.now %> | ||
|
||
|
@@ -210,3 +210,16 @@ steff3: | |
bio: '' | ||
created_at: <%= Time.now %> | ||
updated_at: <%= Time.now %> | ||
|
||
data: | ||
username: data | ||
status: 1 | ||
email: data@pxlshp.com | ||
id: 18 | ||
password_salt: <%= salt = Authlogic::Random.hex_token %> | ||
crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("secretive" + salt) %> | ||
persistence_token: <%= Authlogic::Random.hex_token %> | ||
last_request_at: <%= Time.now %> | ||
bio: 'data is a nice cat and he loves steff!' | ||
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. 😹 |
||
created_at: <%= Time.now %> | ||
updated_at: <%= Time.now %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,9 +75,9 @@ def app | |
|
||
end | ||
|
||
# returns users by id when order_by is not provided and sorted direction default DESC | ||
test 'search profiles without order_by and default sort_direction' do | ||
get '/api/srch/profiles?srchString=steff' | ||
# search by username and returns users by id when order_by is not provided and sorted direction default DESC | ||
test 'search profiles by username without order_by and default sort_direction' do | ||
get '/api/srch/profiles?srchString=steff&field=username' | ||
assert last_response.ok? | ||
|
||
# Expected search pattern | ||
|
@@ -100,9 +100,9 @@ def app | |
|
||
end | ||
|
||
# returns users sorteded by recent activity and order direction default DESC | ||
test 'search recent profiles with sort_by=recent present' do | ||
get '/api/srch/profiles?srchString=steff&sort_by=recent' | ||
# search by username and returns users sorteded by recent activity and order direction default DESC | ||
test 'search recent profiles by username with sort_by=recent present' do | ||
get '/api/srch/profiles?srchString=steff&field=username&sort_by=recent' | ||
assert last_response.ok? | ||
|
||
# Expected search pattern | ||
|
@@ -124,9 +124,9 @@ def app | |
assert matcher =~ json | ||
end | ||
|
||
# returns users ordered by recent activity and sorted by ASC direction | ||
test 'search recent profiles with sort_by=recent present and order_direction ASC' do | ||
get '/api/srch/profiles?srchString=steff&sort_by=recent&order_direction=ASC' | ||
# search by username and returns users ordered by recent activity and sorted by ASC direction | ||
test 'search recent profiles by username with sort_by=recent present and order_direction ASC' do | ||
get '/api/srch/profiles?srchString=steff&field=username&sort_by=recent&order_direction=ASC' | ||
assert last_response.ok? | ||
|
||
# Expected search pattern | ||
|
@@ -148,6 +148,59 @@ def app | |
assert matcher =~ json | ||
end | ||
|
||
# search by username and bio, returns users by id when order_by is not provided and sorted direction default DESC | ||
test 'search profiles by username and bio without order_by and default sort_direction' do | ||
get '/api/srch/profiles?srchString=steff' | ||
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. Sorry, looking on my phone... is there also a text for only bio content? Something that has no username matches? 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. we did like this: the previous tests (that we first had in mind to search only by username) have the 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. @jywarren we pushed some changes, thanks for the feedback! |
||
assert last_response.ok? | ||
|
||
# User.search() only works for mysql/mariadb | ||
if ActiveRecord::Base.connection.adapter_name == 'Mysql2' | ||
# Expected search pattern | ||
pattern = { | ||
srchParams: { | ||
srchString: 'steff', | ||
seq: nil, | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
|
||
matcher = JsonExpressions::Matcher.new(pattern) | ||
|
||
json = JSON.parse(last_response.body) | ||
|
||
assert_equal "/profile/data", json['items'][0]['docUrl'] | ||
assert_equal "/profile/steff3", json['items'][1]['docUrl'] | ||
assert_equal "/profile/steff2", json['items'][2]['docUrl'] | ||
assert_equal "/profile/steff1", json['items'][3]['docUrl'] | ||
|
||
assert matcher =~ json | ||
end | ||
end | ||
|
||
# search by bio only | ||
test 'search profiles by bio without order_by and default sort_direction' do | ||
get '/api/srch/profiles?srchString=ruby' | ||
assert last_response.ok? | ||
|
||
# User.search() only works for mysql/mariadb | ||
if ActiveRecord::Base.connection.adapter_name == 'Mysql2' | ||
# Expected search pattern | ||
pattern = { | ||
srchParams: { | ||
srchString: 'ruby', | ||
seq: nil, | ||
}.ignore_extra_keys! | ||
}.ignore_extra_keys! | ||
|
||
matcher = JsonExpressions::Matcher.new(pattern) | ||
|
||
json = JSON.parse(last_response.body) | ||
|
||
assert_equal "/profile/testuser", json['items'][0]['docUrl'] | ||
|
||
assert matcher =~ json | ||
end | ||
end | ||
|
||
test 'search notes functionality' do | ||
get '/api/srch/notes?srchString=Blog' | ||
assert last_response.ok? | ||
|
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.
😄 💎