Merge pull request #7058 from blockscout/vb-mock-requests

fetch_json mock requests in tests
pull/7061/head
Victor Baranov 2 years ago committed by GitHub
commit 8f3ab41756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 91
      apps/explorer/test/explorer/token/instance_metadata_retriever_test.exs

@ -7,7 +7,7 @@
### Fixes ### Fixes
- [#7008](https://github.com/blockscout/blockscout/pull/7008) - Fetch image/video content from IPFS link - [#7008](https://github.com/blockscout/blockscout/pull/7008) - Fetch image/video content from IPFS link
- [#7007](https://github.com/blockscout/blockscout/pull/7007), [#7031](https://github.com/blockscout/blockscout/pull/7031) - Token instance fetcher fixes - [#7007](https://github.com/blockscout/blockscout/pull/7007), [#7031](https://github.com/blockscout/blockscout/pull/7031), [#7058](https://github.com/blockscout/blockscout/pull/7058) - Token instance fetcher fixes
- [#7009](https://github.com/blockscout/blockscout/pull/7009) - Fix updating coin balances with empty value - [#7009](https://github.com/blockscout/blockscout/pull/7009) - Fix updating coin balances with empty value
### Chore ### Chore

@ -381,28 +381,38 @@ defmodule Explorer.Token.InstanceMetadataRetrieverTest do
assert "ipfs://bafybeihxuj3gxk7x5p36amzootyukbugmx3pw7dyntsrohg3se64efkuga/51.png" == Map.get(metadata, "image") assert "ipfs://bafybeihxuj3gxk7x5p36amzootyukbugmx3pw7dyntsrohg3se64efkuga/51.png" == Map.get(metadata, "image")
end end
test "Fetches metadata from '${url}'" do test "Fetches metadata from '${url}'", %{bypass: bypass} do
path = "/data/8/8578.json"
data = %{ data = %{
"c87b56dd" => "c87b56dd" =>
{:ok, {:ok,
[ [
"'https://cards.collecttrumpcards.com/data/8/8578.json'" "'http://localhost:#{bypass.port}#{path}'"
]} ]}
} }
json = """
{
"attributes": [
{"trait_type": "Character", "value": "Blue Suit Boxing Glove"},
{"trait_type": "Face", "value": "Wink"},
{"trait_type": "Hat", "value": "Blue"},
{"trait_type": "Background", "value": "Red Carpet"}
],
"image": "https://cards.collecttrumpcards.com/cards/0c68b1ab6.jpg",
"name": "Trump Digital Trading Card #8578",
"tokeId": 8578
}
"""
Bypass.expect(bypass, "GET", path, fn conn ->
Conn.resp(conn, 200, json)
end)
assert {:ok, assert {:ok,
%{ %{
metadata: %{ metadata: Jason.decode!(json)
"attributes" => [
%{"trait_type" => "Character", "value" => "Blue Suit Boxing Glove"},
%{"trait_type" => "Face", "value" => "Wink"},
%{"trait_type" => "Hat", "value" => "Blue"},
%{"trait_type" => "Background", "value" => "Red Carpet"}
],
"image" => "https://cards.collecttrumpcards.com/cards/0c68b1ab6.jpg",
"name" => "Trump Digital Trading Card #8578",
"tokenId" => 8578
}
}} == InstanceMetadataRetriever.fetch_json(data) }} == InstanceMetadataRetriever.fetch_json(data)
end end
@ -431,26 +441,47 @@ defmodule Explorer.Token.InstanceMetadataRetrieverTest do
}} == InstanceMetadataRetriever.fetch_json(data) }} == InstanceMetadataRetriever.fetch_json(data)
end end
test "Process URI directly from link" do test "Process URI directly from link", %{bypass: bypass} do
data = "https://dejob.io/api/dejobio/v1/nftproduct/1" path = "/api/dejobio/v1/nftproduct/1"
json = """
{
"image": "https:\/\/cdn.discordapp.com\/attachments\/1008567215739650078\/1080111780858187796\/savechives_a_dragon_playing_football_in_a_city_full_of_flowers__0739cc42-aae1-4909-a964-3f9c0ed1a9ed.png",
"external_url": "https:\/\/dejob.io\/blue-reign-the-dragon-football-champion-of-the-floral-city\/",
"name": "Blue Reign: The Dragon Football Champion of the Floral City",
"description": "Test",
"attributes": [
{
"trait_type": "Product Type",
"value": "Book"
},
{
"display_type": "number",
"trait_type": "Total Sold",
"value": "0"
},
{
"display_type": "number",
"trait_type": "Success Sold",
"value": "0"
},
{
"max_value": "100",
"trait_type": "Success Rate",
"value": "0"
}
]
}
"""
Bypass.expect(bypass, "GET", path, fn conn ->
Conn.resp(conn, 200, json)
end)
assert {:ok, assert {:ok,
%{ %{
metadata: %{ metadata: Jason.decode!(json)
"description" => }} == InstanceMetadataRetriever.fetch_json("http://localhost:#{bypass.port}#{path}")
"\\\"Blue Reign: The Dragon Football Champion of the Floral City\\\" is a science fiction story about a dragon who loves playing football and dreams of becoming a champion. The story takes place in a futuristic city full of flowers and blue light, and it is raining throughout the story.\r\n\r\nThroughout the story, the dragon faces challenges on and off the field, including intense training regimens, rival teams, and personal struggles. He perseveres through these obstacles and incorporates new techniques and strategies into his gameplay.\r\n\r\nAs the playoffs approach, the dragon\\'s team faces increasingly tough opponents, culminating in a highly anticipated championship game against their long-standing rivals, the Storm Hawks. The dragon\\'s heart-pumping performance and his team\\'s impressive plays lead them to victory, and they celebrate their status as champions.\r\n\r\nThe story ultimately focuses on the dragon\\'s journey towards achieving his dream and the teamwork and dedication required to succeed in a highly competitive sport.",
"name" => "Blue Reign: The Dragon Football Champion of the Floral City",
"attributes" => [
%{"trait_type" => "Product Type", "value" => "Book"},
%{"display_type" => "number", "trait_type" => "Total Sold", "value" => "0"},
%{"display_type" => "number", "trait_type" => "Success Sold", "value" => "0"},
%{"max_value" => "100", "trait_type" => "Success Rate", "value" => "0"}
],
"external_url" => "https://dejob.io/?p=49",
"image" =>
"https://cdn.discordapp.com/attachments/1008567215739650078/1080111780858187796/savechives_a_dragon_playing_football_in_a_city_full_of_flowers__0739cc42-aae1-4909-a964-3f9c0ed1a9ed.png"
}
}} == InstanceMetadataRetriever.fetch_json(data)
end end
end end
end end

Loading…
Cancel
Save