-
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.
Extend project table and API with hidden info
Add hidden_since and hidden_reason to the database and the API Add includeHidden: true flag to the allProjects API
- Loading branch information
1 parent
6d09913
commit ed31d7b
Showing
8 changed files
with
186 additions
and
2 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
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
10 changes: 10 additions & 0 deletions
10
priv/repo/migrations/20240809122904_extend_projects_table_hidden_info.exs
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,10 @@ | ||
defmodule Sanbase.Repo.Migrations.ExtendProjectsTableHiddenInfo do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:project) do | ||
add(:hidden_since, :utc_datetime) | ||
add(:hidden_reason, :text) | ||
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
119 changes: 119 additions & 0 deletions
119
test/sanbase_web/graphql/projects/project_hidden_api_test.exs
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,119 @@ | ||
defmodule SanbaseWeb.Graphql.ProjectHiddenApiTest do | ||
use SanbaseWeb.ConnCase, async: false | ||
|
||
import Sanbase.Factory | ||
import SanbaseWeb.Graphql.TestHelpers | ||
|
||
test "all projects", %{conn: conn} do | ||
p1 = insert(:random_erc20_project) | ||
p2 = insert(:random_erc20_project) | ||
p3 = insert(:random_erc20_project, is_hidden: true) | ||
|
||
# Without includeHidden flag. | ||
projects = all_projects(conn) | ||
assert length(projects) == 2 | ||
|
||
slugs = projects |> Enum.map(& &1["slug"]) | ||
|
||
assert p1.slug in slugs | ||
assert p2.slug in slugs | ||
refute p3.slug in slugs | ||
|
||
# With includeHidden: true flag | ||
projects = all_projects_including_hidden(conn) | ||
assert length(projects) == 3 | ||
|
||
slugs = projects |> Enum.map(& &1["slug"]) | ||
assert p1.slug in slugs | ||
assert p2.slug in slugs | ||
assert p3.slug in slugs | ||
end | ||
|
||
test "project by slug", %{conn: conn} do | ||
p1 = insert(:random_erc20_project) | ||
p2 = insert(:random_erc20_project) | ||
|
||
assert {:ok, _} = | ||
Sanbase.Project.changeset(p2, %{is_hidden: true, hidden_reason: "duplicate"}) | ||
|> Sanbase.Repo.update() | ||
|
||
# not a hidden project | ||
project = project_by_slug(conn, %{slug: p1.slug}) | ||
|
||
assert project == %{ | ||
"hiddenReason" => nil, | ||
"hiddenSince" => nil, | ||
"isHidden" => false, | ||
"slug" => p1.slug | ||
} | ||
|
||
# hidden project | ||
project = project_by_slug(conn, %{slug: p2.slug}) | ||
|
||
assert %{ | ||
"hiddenReason" => "duplicate", | ||
"hiddenSince" => dt, | ||
"isHidden" => true, | ||
"slug" => slug | ||
} = project | ||
|
||
assert slug == p2.slug | ||
|
||
assert Sanbase.TestUtils.datetime_close_to( | ||
DateTime.utc_now(), | ||
Sanbase.DateTimeUtils.from_iso8601!(dt), | ||
1, | ||
:seconds | ||
) | ||
end | ||
|
||
defp project_by_slug(conn, args) do | ||
query = """ | ||
{ | ||
projectBySlug(#{map_to_args(args)}){ | ||
slug | ||
isHidden | ||
hiddenSince | ||
hiddenReason | ||
} | ||
} | ||
""" | ||
|
||
conn | ||
|> post("/graphql", query_skeleton(query)) | ||
|> json_response(200) | ||
|> get_in(["data", "projectBySlug"]) | ||
end | ||
|
||
defp all_projects(conn) do | ||
query = """ | ||
{ | ||
allProjects{ | ||
slug | ||
isHidden | ||
} | ||
} | ||
""" | ||
|
||
conn | ||
|> post("/graphql", query_skeleton(query)) | ||
|> json_response(200) | ||
|> get_in(["data", "allProjects"]) | ||
end | ||
|
||
defp all_projects_including_hidden(conn) do | ||
query = """ | ||
{ | ||
allProjects(includeHidden: true){ | ||
slug | ||
isHidden | ||
} | ||
} | ||
""" | ||
|
||
conn | ||
|> post("/graphql", query_skeleton(query)) | ||
|> json_response(200) | ||
|> get_in(["data", "allProjects"]) | ||
end | ||
end |