-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: query udt by name or symbol (#1488)
Signed-off-by: Miles Zhang <[email protected]>
- Loading branch information
1 parent
b1f3b2c
commit 70f3d61
Showing
4 changed files
with
86 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Api | ||
module V1 | ||
class UdtQueriesController < ApplicationController | ||
def index | ||
udts = Udt.query_by_name_or_symbl(params[:q].downcase) | ||
|
||
render json: UdtSerializer.new(udts, { fields: { udt: [:full_name, :symbol, :type_hash, :icon_file] } }) | ||
end | ||
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
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,69 @@ | ||
require "test_helper" | ||
|
||
module Api | ||
module V1 | ||
class UdtQueriesControllerTest < ActionDispatch::IntegrationTest | ||
test "should return empty array" do | ||
valid_get api_v1_udt_queries_url, params: { q: "CKB" } | ||
|
||
response_json = { data: [] }.to_json | ||
|
||
assert_response :success | ||
assert_equal "application/vnd.api+json", response.media_type | ||
assert_equal response_json, response.body | ||
end | ||
|
||
test "should query by symbol" do | ||
udt = create(:udt, full_name: "Nervos Token", symbol: "CKB") | ||
|
||
valid_get api_v1_udt_queries_url, params: { q: "CKB" } | ||
|
||
response_json = UdtSerializer.new([udt], | ||
{ | ||
fields: { | ||
udt: [ | ||
:full_name, :symbol, :type_hash, | ||
:icon_file | ||
] } }).serialized_json | ||
|
||
assert_response :success | ||
assert_equal response_json, response.body | ||
end | ||
|
||
test "should query by name" do | ||
udt = create(:udt, full_name: "Nervos Token", symbol: "CKB") | ||
|
||
valid_get api_v1_udt_queries_url, params: { q: "nervos" } | ||
|
||
response_json = UdtSerializer.new([udt], | ||
{ | ||
fields: { | ||
udt: [ | ||
:full_name, :symbol, :type_hash, | ||
:icon_file | ||
] } }).serialized_json | ||
|
||
assert_response :success | ||
assert_equal response_json, response.body | ||
end | ||
|
||
test "should query by symbol and name" do | ||
udt1 = create(:udt, full_name: "Nervos Token", symbol: "CKB") | ||
udt2 = create(:udt, full_name: "Nervos CKB", symbol: "NCKB") | ||
|
||
valid_get api_v1_udt_queries_url, params: { q: "CKB" } | ||
|
||
response_json = UdtSerializer.new([udt1, udt2], | ||
{ | ||
fields: { | ||
udt: [ | ||
:full_name, :symbol, :type_hash, | ||
:icon_file | ||
] } }).serialized_json | ||
|
||
assert_response :success | ||
assert_equal response_json, response.body | ||
end | ||
end | ||
end | ||
end |