Packages
potionx
0.4.14
0.8.15
0.8.14
0.8.13
0.8.12
0.8.11
0.8.10
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.3
0.5.2
0.5.1
0.5.0
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.18
0.2.17
0.2.16
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.1.1
0.1.0
Potionx is a set of generators and functions that speeds up the process of setting up and deploying a full-stack application that uses Elixir with GraphQL for the server-side component and Vue for the frontend component.
Current section
Files
Jump to
Current section
Files
priv/templates/potion.gen.gql_for_model/mutations_test.exs
defmodule <%= module_name_graphql %>.Schema.<%= model_name %>MutationTest do
use <%= module_name_data %>.DataCase
alias <%= module_name_data %>.<%= context_name %>.<%= model_name %>
alias <%= module_name_data %>.<%= context_name %>.<%= model_name %>Mock
alias <%= module_name_data %>.<%= context_name %>.<%= model_name %>Service
def prepare_ctx(ctx) do
%{
ctx |
roles: [:admin],
session: %{
id: 1,
user: %{
id: 1,
roles: [:admin]
}
}
}
end
describe "<%= model_name_snakecase %> delete" do
setup do
ctx = %Potionx.Context.Service{
changes: <%= model_name %>Mock.run(),
} |> prepare_ctx
{:ok, entry} = <%= model_name %>Service.mutation(ctx)
{:ok, ctx: ctx, entry: entry}
end
test "deletes <%= model_name_snakecase %>", %{ctx: ctx, entry: entry} do
Elixir.File.read!("shared/src/models/<%= context_name %>/<%= model_name %>/<%= model_name_graphql_case %>Delete.gql")
|> Absinthe.run(
<%= module_name_graphql %>.Schema,
context: ctx,
variables: %{"filters" => %{"id" => entry.id}}
)
|> (fn {:ok, res} ->
assert res.data["<%= model_name_graphql_case %>Delete"]["node"]["id"] ===
Absinthe.Relay.Node.to_global_id(
:<%= model_name_snakecase %>,
entry.id,
<%= module_name_graphql %>.Schema
)
end).()
end
end
describe "<%= model_name_snakecase %> new mutation" do
setup do
ctx =
%Potionx.Context.Service{
changes: <%= model_name %>Mock.run() |> Map.delete(:id)
} |> prepare_ctx
{:ok, ctx: ctx}
end
test "creates <%= model_name_snakecase %>", %{ctx: ctx} do
changes = Enum.map(ctx.changes, fn
{k, v} when v === %{} -> {k, Jason.encode!(%{})}
{k, v} -> {k, v}
end)
|> Enum.into(%{})
Elixir.File.read!("shared/src/models/<%= context_name %>/<%= model_name %>/<%= model_name_graphql_case %>Mutation.gql")
|> Absinthe.run(
<%= module_name_graphql %>.Schema,
[
context: ctx,
variables: %{
"changes" => Jason.decode!(Jason.encode!(changes))
}
]
)
|> (fn {:ok, res} ->
assert res.data["<%= model_name_graphql_case %>Mutation"]["node"]["id"]
end).()
end
end
describe "<%= model_name_snakecase %> invalid mutation/2" do
setup do
ctx =
%Potionx.Context.Service{
changes: %{},
} |> prepare_ctx
{:ok, ctx: ctx}
end
test "invalid <%= model_name_snakecase %> mutation", %{ctx: ctx} do
Elixir.File.read!("shared/src/models/<%= context_name %>/<%= model_name %>/<%= model_name_graphql_case %>Mutation.gql")
|> Absinthe.run(
<%= module_name_graphql %>.Schema,
context: ctx,
variables: %{
"changes" => Jason.decode!(Jason.encode!(ctx.changes))
}
)
|> (fn {:ok, res} ->
assert res.data["<%= model_name_graphql_case %>Mutation"]["errorsFields"] |> Enum.at(0) |> Map.get("field")
assert res.data["<%= model_name_graphql_case %>Mutation"]["errorsFields"] |> Enum.at(0) |> Map.get("message")
end).()
end
end
describe "<%= model_name_snakecase %> patch mutation/2" do
setup do
ctx =
%Potionx.Context.Service{
changes: <%= model_name %>Mock.run(),
} |> prepare_ctx
required_field =
<%= model_name %>.changeset(%<%= model_name %>{}, %{})
|> Map.get(:errors)
|> Keyword.keys
|> Enum.at(0)
{:ok, entry} = <%= model_name %>Service.mutation(ctx)
{:ok, ctx: ctx, entry: entry, required_field: required_field}
end
test "patches <%= model_name_snakecase %>", %{ctx: ctx, entry: entry, required_field: required_field} do
changes =
required_field && Map.put(%{}, to_string(required_field), <%= model_name %>Mock.run_patch()[required_field]) || %{}
changes = Enum.map(changes, fn
{k, v} when v === %{} -> {k, Jason.encode!(%{})}
{k, v} -> {k, v}
end)
|> Enum.into(%{})
Elixir.File.read!("shared/src/models/<%= context_name %>/<%= model_name %>/<%= model_name_graphql_case %>Mutation.gql")
|> Absinthe.run(
<%= module_name_graphql %>.Schema,
context: ctx,
variables: %{
"changes" => changes,
"filters" => %{
"id" => Absinthe.Relay.Node.to_global_id(
:<%= model_name_snakecase %>,
entry.id,
<%= module_name_graphql %>.Schema
)
}
}
)
|> (fn {:ok, res} ->
assert res.data["<%= model_name_graphql_case %>Mutation"]["node"]["id"]
if required_field do
assert res.data["<%= model_name_graphql_case %>Mutation"]["node"][to_string(required_field)] === <%= model_name %>Mock.run_patch()[required_field]
end
end).()
end
end
end