-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add info to the Project GraphQL type (#4486)
* Add info to the Project GraphQL type * Add test for project's info field
- Loading branch information
1 parent
d1319d0
commit 7969092
Showing
7 changed files
with
109 additions
and
1 deletion.
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,28 @@ | ||
defmodule Sanbase.Clickhouse.Project do | ||
def projects_info(slugs) do | ||
query = projects_info_query(slugs) | ||
|
||
Sanbase.ClickhouseRepo.query_reduce(query, %{}, fn [slug, full, summary], acc -> | ||
Map.put(acc, slug, %{full: full, summary: summary}) | ||
end) | ||
end | ||
|
||
defp projects_info_query(slugs) do | ||
sql = """ | ||
SELECT | ||
slug, | ||
info, | ||
info_summary | ||
FROM projects_info | ||
WHERE | ||
version = ( SELECT max(version) FROM projects_info) AND | ||
slug IN {{slugs}} | ||
""" | ||
|
||
params = %{ | ||
slugs: slugs | ||
} | ||
|
||
Sanbase.Clickhouse.Query.new(sql, params) | ||
end | ||
end |
Empty file.
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
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,50 @@ | ||
defmodule Sanbase.Project.InfoTest do | ||
use SanbaseWeb.ConnCase, async: false | ||
|
||
import Sanbase.Factory | ||
import SanbaseWeb.Graphql.TestHelpers | ||
|
||
test "get project's available metrics", context do | ||
insert(:project, slug: "bitcoin") | ||
insert(:project, slug: "ethereum") | ||
|
||
rows = [ | ||
["bitcoin", "bitcoin full info", "short btc info"], | ||
["ethereum", "ethereum full info", "short eth info"] | ||
] | ||
|
||
Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) | ||
|> Sanbase.Mock.run_with_mocks(fn -> | ||
result = get_projects_info(context.conn) |> get_in(["data", "allProjects"]) | ||
assert length(result) == 2 | ||
|
||
assert %{ | ||
"info" => %{"full" => "bitcoin full info", "summary" => "short btc info"}, | ||
"slug" => "bitcoin" | ||
} in result | ||
|
||
assert %{ | ||
"info" => %{"full" => "ethereum full info", "summary" => "short eth info"}, | ||
"slug" => "ethereum" | ||
} in result | ||
end) | ||
end | ||
|
||
defp get_projects_info(conn) do | ||
query = """ | ||
{ | ||
allProjects{ | ||
slug | ||
info { | ||
full | ||
summary | ||
} | ||
} | ||
} | ||
""" | ||
|
||
conn | ||
|> post("/graphql", query_skeleton(query)) | ||
|> json_response(200) | ||
end | ||
end |