Add test for label search (#7741)

* Add test for label search

* Changelog
pull/7746/head
nikitosing 1 year ago committed by GitHub
parent 3918862f5a
commit 663d6ab644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 17
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/search_controller_test.exs
  3. 4
      apps/explorer/lib/explorer/tags/address_tag.ex
  4. 12
      apps/explorer/test/support/factory.ex

@ -39,7 +39,7 @@
### Chore
- [#7699](https://github.com/blockscout/blockscout/pull/7699) - Add block_number index for address_coin_balances table
- [#7666](https://github.com/blockscout/blockscout/pull/7666), [#7740](https://github.com/blockscout/blockscout/pull/7740) - Search label query
- [#7666](https://github.com/blockscout/blockscout/pull/7666), [#7740](https://github.com/blockscout/blockscout/pull/7740), [#7741](https://github.com/blockscout/blockscout/pull/7741) - Search label query
- [#7644](https://github.com/blockscout/blockscout/pull/7644) - Publish docker images CI for prod/staging branches
- [#7594](https://github.com/blockscout/blockscout/pull/7594) - Stats service support in docker-compose config with new frontend
- [#7576](https://github.com/blockscout/blockscout/pull/7576) - Check left blocks in pending block operations in order to decide, if we need to display indexing int tx banner at the top

@ -143,6 +143,23 @@ defmodule BlockScoutWeb.API.V2.SearchControllerTest do
assert item["tx_hash"] == to_string(tx.hash)
assert item["url"] =~ to_string(tx.hash)
end
test "search tags", %{conn: conn} do
tag = insert(:address_to_tag)
request = get(conn, "/api/v2/search?q=#{tag.tag.display_name}")
assert response = json_response(request, 200)
assert Enum.count(response["items"]) == 1
assert response["next_page_params"] == nil
item = Enum.at(response["items"], 0)
assert item["type"] == "label"
assert item["address"] == Address.checksum(tag.address.hash)
assert item["name"] == tag.tag.display_name
assert item["url"] =~ Address.checksum(tag.address.hash)
end
end
describe "/search/check-redirect" do

@ -12,14 +12,13 @@ defmodule Explorer.Tags.AddressTag do
from: 2
]
alias Explorer.Chain.Address
alias Explorer.Repo
alias Explorer.Tags.{AddressTag, AddressToTag}
@typedoc """
* `:id` - id of Tag
* `:label` - Tag's label
* `:label` - Label's display name
* `:display_name` - Label's display name
"""
@type t :: %AddressTag{
label: String.t()
@ -28,7 +27,6 @@ defmodule Explorer.Tags.AddressTag do
schema "address_tags" do
field(:label, :string)
field(:display_name, :string)
has_many(:addresses, Address, foreign_key: :hash)
has_many(:tag_id, AddressToTag, foreign_key: :id)
timestamps()

@ -44,7 +44,7 @@ defmodule Explorer.Factory do
}
alias Explorer.SmartContract.Helper
alias Explorer.Tags.{AddressTag, AddressToTag}
alias Explorer.Market.MarketHistory
alias Explorer.Repo
@ -140,6 +140,16 @@ defmodule Explorer.Factory do
%{"name" => sequence("name"), "transaction_hash" => to_string(insert(:transaction).hash)}
end
def address_to_tag_factory do
%AddressToTag{
tag: %AddressTag{
label: sequence("label"),
display_name: sequence("display_name")
},
address: build(:address)
}
end
def account_watchlist_address_factory do
hash = build(:address).hash

Loading…
Cancel
Save