@@ -1,190 +0,0 @@
|
||||
defmodule MobilizonWeb.ActorControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
{:ok, conn: conn, user: user, actor: actor}
|
||||
end
|
||||
|
||||
@create_attrs %{
|
||||
preferred_username: "otheridentity",
|
||||
summary: "This is my other identity"
|
||||
}
|
||||
|
||||
describe "index" do
|
||||
test "lists all actors", %{conn: conn, user: user, actor: actor} do
|
||||
conn = get(conn, actor_path(conn, :index))
|
||||
assert hd(json_response(conn, 200)["data"])["username"] == actor.preferred_username
|
||||
end
|
||||
end
|
||||
|
||||
describe "create actor" do
|
||||
test "from an existing user", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, actor_path(conn, :create), actor: @create_attrs)
|
||||
assert json_response(conn, 201)["data"]["username"] == @create_attrs.preferred_username
|
||||
end
|
||||
end
|
||||
|
||||
describe "show actor" do
|
||||
test "show existing actor", %{conn: conn, actor: actor} do
|
||||
actor_id = actor.id
|
||||
conn = get(conn, actor_path(conn, :show, actor.preferred_username))
|
||||
assert %{"data" => %{"id" => actor_id}} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "show non-existing actor", %{conn: conn, actor: actor} do
|
||||
actor_id = actor.id
|
||||
conn = get(conn, actor_path(conn, :show, "nonexisting"))
|
||||
assert "" == response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "search for actors" do
|
||||
test "search for existing actors", %{conn: conn, actor: actor} do
|
||||
actor_username = actor.preferred_username
|
||||
conn = get(conn, actor_path(conn, :search, actor_username))
|
||||
assert %{"data" => [%{"username" => actor_username}]} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "search for existing actors with similar username", %{conn: conn, actor: actor} do
|
||||
actor_username = actor.preferred_username
|
||||
conn = get(conn, actor_path(conn, :search, "thom"))
|
||||
assert %{"data" => [%{"username" => actor_username}]} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "search for nothing", %{conn: conn, actor: actor} do
|
||||
actor_username = actor.preferred_username
|
||||
conn = get(conn, actor_path(conn, :search, "nothing"))
|
||||
assert %{"data" => []} = json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "update actor" do
|
||||
test "update actor with valid attrs", %{conn: conn, user: user, actor: actor} do
|
||||
conn = auth_conn(conn, user)
|
||||
|
||||
conn =
|
||||
patch(conn, actor_path(conn, :update, actor.preferred_username), %{
|
||||
"actor" => %{"name" => "glouglou"}
|
||||
})
|
||||
|
||||
assert %{"data" => %{"display_name" => "glouglou"}} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "update actor with invalid attrs", %{conn: conn, user: user, actor: actor} do
|
||||
conn = auth_conn(conn, user)
|
||||
|
||||
conn =
|
||||
patch(conn, actor_path(conn, :update, actor.preferred_username), %{
|
||||
"actor" => %{"preferred_username" => nil}
|
||||
})
|
||||
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
###
|
||||
# Not possible atm
|
||||
###
|
||||
# describe "delete actor" do
|
||||
# setup [:create_actor]
|
||||
#
|
||||
# test "deletes own actor", %{conn: conn, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = delete conn, actor_path(conn, :delete, user.actor)
|
||||
# assert response(conn, 204)
|
||||
# assert_error_sent 404, fn ->
|
||||
# get conn, actor_path(conn, :show, user.actor)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# test "deletes other actor", %{conn: conn, actor: actor, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = delete conn, actor_path(conn, :delete, actor)
|
||||
# assert response(conn, 401)
|
||||
# conn = get conn, actor_path(conn, :show, actor)
|
||||
# assert response(conn, 200)
|
||||
# end
|
||||
# end
|
||||
|
||||
@create_group_attrs %{
|
||||
preferred_username: "mygroup",
|
||||
summary: "This is my awesome group",
|
||||
name: "My Group"
|
||||
}
|
||||
|
||||
describe "index groups" do
|
||||
test "lists all actor groups", %{conn: conn} do
|
||||
conn = get(conn, group_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
|
||||
test "after creating a group", %{conn: conn, user: user, actor: actor} do
|
||||
# create group
|
||||
conn = auth_conn(conn, user)
|
||||
create_group_attrs = Map.put(@create_group_attrs, :actor_admin, actor.preferred_username)
|
||||
conn = post(conn, group_path(conn, :create), group: create_group_attrs)
|
||||
|
||||
group_res = json_response(conn, 201)
|
||||
assert group_res["username"] == @create_group_attrs.preferred_username
|
||||
|
||||
conn = get(conn, group_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == [group_res]
|
||||
end
|
||||
end
|
||||
|
||||
describe "create group" do
|
||||
test "with valid attributes", %{conn: conn, user: user, actor: actor} do
|
||||
conn = auth_conn(conn, user)
|
||||
create_group_attrs = Map.put(@create_group_attrs, :actor_admin, actor.preferred_username)
|
||||
conn = post(conn, group_path(conn, :create), group: create_group_attrs)
|
||||
|
||||
assert json_response(conn, 201)["username"] == @create_group_attrs.preferred_username
|
||||
end
|
||||
end
|
||||
|
||||
describe "join group" do
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
group = insert(:group, preferred_username: "mygroup")
|
||||
{:ok, conn: conn, user: user, actor: actor, group: group}
|
||||
end
|
||||
|
||||
test "from valid account", %{conn: conn, user: user, actor: actor, group: group} do
|
||||
conn = auth_conn(conn, user)
|
||||
|
||||
conn =
|
||||
post(conn, group_path(conn, :join, group.preferred_username), %{
|
||||
"actor_name" => actor.preferred_username
|
||||
})
|
||||
|
||||
resp = json_response(conn, 201)
|
||||
|
||||
assert resp = %{
|
||||
"actor" => %{"username" => actor.preferred_username},
|
||||
"group" => %{"username" => group.preferred_username},
|
||||
"role" => 0
|
||||
}
|
||||
end
|
||||
|
||||
test "join non existent group", %{conn: conn, user: user, actor: actor} do
|
||||
conn = auth_conn(conn, user)
|
||||
|
||||
conn =
|
||||
post(conn, group_path(conn, :join, "mygroup@nonexistent.tld"), %{
|
||||
"actor_name" => actor.preferred_username
|
||||
})
|
||||
|
||||
resp = json_response(conn, 404)
|
||||
|
||||
assert resp = %{msg: "Resource not found", details: "group or actor doesn't exist"}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,144 +0,0 @@
|
||||
defmodule MobilizonWeb.AddressControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Addresses
|
||||
alias Mobilizon.Addresses.Address
|
||||
|
||||
@create_attrs %{
|
||||
addressCountry: "some addressCountry",
|
||||
addressLocality: "some addressLocality",
|
||||
addressRegion: "some addressRegion",
|
||||
description: "some description",
|
||||
floor: "some floor",
|
||||
postalCode: "some postalCode",
|
||||
streetAddress: "some streetAddress",
|
||||
geom: %{type: :point, data: %{latitude: -20, longitude: 30}}
|
||||
}
|
||||
@update_attrs %{
|
||||
addressCountry: "some updated addressCountry",
|
||||
addressLocality: "some updated addressLocality",
|
||||
addressRegion: "some updated addressRegion",
|
||||
description: "some updated description",
|
||||
floor: "some updated floor",
|
||||
postalCode: "some updated postalCode",
|
||||
streetAddress: "some updated streetAddress",
|
||||
geom: %{type: :point, data: %{latitude: -40, longitude: 40}}
|
||||
}
|
||||
@invalid_attrs %{
|
||||
addressCountry: nil,
|
||||
addressLocality: nil,
|
||||
addressRegion: nil,
|
||||
description: nil,
|
||||
floor: nil,
|
||||
postalCode: nil,
|
||||
streetAddress: nil,
|
||||
geom: %{type: "oh no", data: %{latitude: nil, longitude: nil}}
|
||||
}
|
||||
|
||||
def fixture(:address) do
|
||||
{:ok, address} = Addresses.create_address(@create_attrs)
|
||||
address
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all addresses", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = get(conn, address_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create address" do
|
||||
test "renders address when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, address_path(conn, :create), address: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, address_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"addressCountry" => "some addressCountry",
|
||||
"addressLocality" => "some addressLocality",
|
||||
"addressRegion" => "some addressRegion",
|
||||
"description" => "some description",
|
||||
"floor" => "some floor",
|
||||
"postalCode" => "some postalCode",
|
||||
"streetAddress" => "some streetAddress",
|
||||
"geom" => %{
|
||||
"data" => %{"latitude" => -20.0, "longitude" => 30.0},
|
||||
"type" => "point"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, address_path(conn, :create), address: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update address" do
|
||||
setup [:create_address]
|
||||
|
||||
test "renders address when data is valid", %{
|
||||
conn: conn,
|
||||
address: %Address{id: id} = address,
|
||||
user: user
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, address_path(conn, :update, address), address: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, address_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"addressCountry" => "some updated addressCountry",
|
||||
"addressLocality" => "some updated addressLocality",
|
||||
"addressRegion" => "some updated addressRegion",
|
||||
"description" => "some updated description",
|
||||
"floor" => "some updated floor",
|
||||
"postalCode" => "some updated postalCode",
|
||||
"streetAddress" => "some updated streetAddress",
|
||||
"geom" => %{
|
||||
"data" => %{"latitude" => -40.0, "longitude" => 40.0},
|
||||
"type" => "point"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, address: address, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, address_path(conn, :update, address), address: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete address" do
|
||||
setup [:create_address]
|
||||
|
||||
test "deletes chosen address", %{conn: conn, address: address, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, address_path(conn, :delete, address))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, address_path(conn, :show, address))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_address(_) do
|
||||
{:ok, address: insert(:address)}
|
||||
end
|
||||
end
|
||||
@@ -1,94 +0,0 @@
|
||||
defmodule MobilizonWeb.BotControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Bot
|
||||
|
||||
@create_attrs %{source: "some source", type: "some type", name: "some name"}
|
||||
@update_attrs %{
|
||||
source: "some updated source",
|
||||
type: "some updated type",
|
||||
name: "some updated name"
|
||||
}
|
||||
@invalid_attrs %{source: nil, type: nil, name: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json"), user: user}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all bots", %{conn: conn} do
|
||||
conn = get(conn, bot_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create bot" do
|
||||
test "renders bot when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, bot_path(conn, :create), bot: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, bot_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"source" => "some source",
|
||||
"type" => "some type"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, bot_path(conn, :create), bot: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update bot" do
|
||||
setup [:create_bot]
|
||||
|
||||
test "renders bot when data is valid", %{conn: conn, bot: %Bot{id: id} = bot, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, bot_path(conn, :update, bot), bot: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, bot_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"source" => "some updated source",
|
||||
"type" => "some updated type"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, bot: bot, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, bot_path(conn, :update, bot), bot: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete bot" do
|
||||
setup [:create_bot]
|
||||
|
||||
test "deletes chosen bot", %{conn: conn, bot: bot, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, bot_path(conn, :delete, bot))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, bot_path(conn, :show, bot))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_bot(_) do
|
||||
bot = insert(:bot)
|
||||
{:ok, bot: bot}
|
||||
end
|
||||
end
|
||||
@@ -1,105 +0,0 @@
|
||||
defmodule MobilizonWeb.CategoryControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Category
|
||||
|
||||
@create_attrs %{description: "some description", picture: "some picture", title: "some title"}
|
||||
@update_attrs %{
|
||||
description: "some updated description",
|
||||
picture: "some updated picture",
|
||||
title: "some updated title"
|
||||
}
|
||||
@invalid_attrs %{description: nil, picture: nil, title: nil}
|
||||
|
||||
def fixture(:category) do
|
||||
{:ok, category} = Events.create_category(@create_attrs)
|
||||
category
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all categories", %{conn: conn} do
|
||||
conn = get(conn, category_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create category" do
|
||||
test "renders category when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, category_path(conn, :create), category: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, category_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"description" => "some description",
|
||||
"picture" => "some picture",
|
||||
"title" => "some title"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, category_path(conn, :create), category: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update category" do
|
||||
setup [:create_category]
|
||||
|
||||
test "renders category when data is valid", %{
|
||||
conn: conn,
|
||||
category: %Category{id: id} = category,
|
||||
user: user
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, category_path(conn, :update, category), category: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, category_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"description" => "some updated description",
|
||||
"picture" => "some updated picture",
|
||||
"title" => "some updated title"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, category: category, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, category_path(conn, :update, category), category: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete category" do
|
||||
setup [:create_category]
|
||||
|
||||
test "deletes chosen category", %{conn: conn, category: category, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, category_path(conn, :delete, category))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, category_path(conn, :show, category))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_category(_) do
|
||||
category = fixture(:category)
|
||||
{:ok, category: category}
|
||||
end
|
||||
end
|
||||
@@ -1,96 +0,0 @@
|
||||
defmodule MobilizonWeb.CommentControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Comment
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
@create_attrs %{text: "some text"}
|
||||
@update_attrs %{text: "some updated text"}
|
||||
@invalid_attrs %{text: nil, url: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json"), user: user, actor: actor}
|
||||
end
|
||||
|
||||
describe "create comment" do
|
||||
test "renders comment when data is valid", %{conn: conn, user: user, actor: actor} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.merge(@create_attrs, %{actor_id: actor.id})
|
||||
conn = post(conn, comment_path(conn, :create), comment: attrs)
|
||||
assert %{"uuid" => uuid, "id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, comment_path(conn, :show, uuid))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"text" => "some text",
|
||||
"uuid" => uuid,
|
||||
"url" => "#{MobilizonWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, comment_path(conn, :create), comment: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update comment" do
|
||||
setup [:create_comment]
|
||||
|
||||
test "renders comment when data is valid", %{
|
||||
conn: conn,
|
||||
comment: %Comment{id: id, uuid: uuid} = comment,
|
||||
user: user,
|
||||
actor: actor
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.merge(@update_attrs, %{actor_id: actor.id})
|
||||
conn = put(conn, comment_path(conn, :update, uuid), comment: attrs)
|
||||
assert %{"uuid" => uuid, "id" => id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, comment_path(conn, :show, uuid))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"text" => "some updated text",
|
||||
"uuid" => uuid,
|
||||
"url" => "#{MobilizonWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, comment: comment, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, comment_path(conn, :update, comment.uuid), comment: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete comment" do
|
||||
setup [:create_comment]
|
||||
|
||||
test "deletes chosen comment", %{
|
||||
conn: conn,
|
||||
comment: %Comment{uuid: uuid} = comment,
|
||||
user: user
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, comment_path(conn, :delete, uuid))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, comment_path(conn, :show, uuid))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_comment(_) do
|
||||
comment = insert(:comment)
|
||||
{:ok, comment: comment}
|
||||
end
|
||||
end
|
||||
@@ -1,182 +0,0 @@
|
||||
defmodule MobilizonWeb.EventControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Export.ICalendar
|
||||
|
||||
@create_attrs %{
|
||||
begins_on: "2010-04-17 14:00:00.000000Z",
|
||||
description: "some description",
|
||||
ends_on: "2010-04-17 14:00:00.000000Z",
|
||||
title: "some title"
|
||||
}
|
||||
@update_attrs %{
|
||||
begins_on: "2011-05-18 15:01:01.000000Z",
|
||||
description: "some updated description",
|
||||
ends_on: "2011-05-18 15:01:01.000000Z",
|
||||
title: "some updated title"
|
||||
}
|
||||
@invalid_attrs %{begins_on: nil, description: nil, ends_on: nil, title: nil, address_id: nil}
|
||||
@create_address_attrs %{
|
||||
"addressCountry" => "some addressCountry",
|
||||
"addressLocality" => "some addressLocality",
|
||||
"addressRegion" => "some addressRegion",
|
||||
"description" => "some description",
|
||||
"floor" => "some floor",
|
||||
"postalCode" => "some postalCode",
|
||||
"streetAddress" => "some streetAddress",
|
||||
"geom" => %{"type" => :point, "data" => %{"latitude" => -20, "longitude" => 30}}
|
||||
}
|
||||
|
||||
def fixture(:event) do
|
||||
{:ok, event} = Events.create_event(@create_attrs)
|
||||
event
|
||||
end
|
||||
|
||||
def address_fixture do
|
||||
insert(:address)
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
{:ok, conn: conn, user: user, actor: actor}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all events", %{conn: conn} do
|
||||
conn = get(conn, event_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create event" do
|
||||
test "renders event when data is valid", %{conn: conn, user: user, actor: actor} do
|
||||
attrs = Map.put(@create_attrs, :organizer_actor_id, actor.id)
|
||||
attrs = Map.put(attrs, "physical_address", @create_address_attrs)
|
||||
|
||||
category = insert(:category)
|
||||
attrs = Map.put(attrs, :category_id, category.id)
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, event_path(conn, :create), event: attrs)
|
||||
assert %{"uuid" => uuid} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, event_path(conn, :show, uuid))
|
||||
|
||||
assert %{
|
||||
"begins_on" => "2010-04-17T14:00:00Z",
|
||||
"description" => "some description",
|
||||
"ends_on" => "2010-04-17T14:00:00Z",
|
||||
"title" => "some title",
|
||||
"participants" => [],
|
||||
"physical_address" => %{
|
||||
"addressCountry" => "some addressCountry",
|
||||
"addressLocality" => "some addressLocality",
|
||||
"addressRegion" => "some addressRegion",
|
||||
"floor" => "some floor",
|
||||
"geom" => %{
|
||||
"data" => %{"latitude" => -20.0, "longitude" => 30.0},
|
||||
"type" => "point"
|
||||
},
|
||||
"postalCode" => "some postalCode",
|
||||
"streetAddress" => "some streetAddress"
|
||||
}
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user, actor: actor} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :organizer_actor_id, actor.id)
|
||||
attrs = Map.put(attrs, :address, @create_address_attrs)
|
||||
conn = post(conn, event_path(conn, :create), event: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "export event" do
|
||||
setup [:create_event]
|
||||
|
||||
test "renders ics export of event", %{
|
||||
conn: conn,
|
||||
event: %Event{uuid: uuid} = event,
|
||||
user: user
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = get(conn, event_path(conn, :export_to_ics, uuid))
|
||||
exported_event = ICalendar.export_event(event)
|
||||
assert exported_event == response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "update event" do
|
||||
setup [:create_event]
|
||||
|
||||
test "renders event when data is valid", %{
|
||||
conn: conn,
|
||||
event: %Event{uuid: uuid} = event,
|
||||
user: user,
|
||||
actor: actor
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
address = address_fixture()
|
||||
attrs = Map.put(@update_attrs, :organizer_actor_id, actor.id)
|
||||
attrs = Map.put(attrs, :address_id, address.id)
|
||||
conn = put(conn, event_path(conn, :update, uuid), event: attrs)
|
||||
assert %{"uuid" => uuid} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, event_path(conn, :show, uuid))
|
||||
|
||||
assert %{
|
||||
"begins_on" => "2011-05-18T15:01:01Z",
|
||||
"description" => "some updated description",
|
||||
"ends_on" => "2011-05-18T15:01:01Z",
|
||||
"title" => "some updated title",
|
||||
"participants" => [],
|
||||
"physical_address" => %{
|
||||
"addressCountry" => "My Country",
|
||||
"addressLocality" => "My Locality",
|
||||
"addressRegion" => "My Region",
|
||||
"floor" => "Myfloor",
|
||||
"geom" => %{
|
||||
"data" => %{"latitude" => 30.0, "longitude" => -90.0},
|
||||
"type" => "point"
|
||||
},
|
||||
"postalCode" => "My Postal Code",
|
||||
"streetAddress" => "My Street Address"
|
||||
}
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{
|
||||
conn: conn,
|
||||
event: %Event{uuid: uuid} = event,
|
||||
user: user,
|
||||
actor: actor
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :organizer_actor_id, actor.id)
|
||||
conn = put(conn, event_path(conn, :update, uuid), event: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete event" do
|
||||
setup [:create_event]
|
||||
|
||||
test "deletes chosen event", %{conn: conn, event: %Event{uuid: uuid} = event, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, event_path(conn, :delete, uuid))
|
||||
assert response(conn, 204)
|
||||
conn = get(conn, event_path(conn, :show, uuid))
|
||||
assert response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_event(_) do
|
||||
actor = insert(:actor)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
{:ok, event: event, actor: actor}
|
||||
end
|
||||
end
|
||||
@@ -1,83 +0,0 @@
|
||||
defmodule MobilizonWeb.FollowerControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Follower
|
||||
import Mobilizon.Factory
|
||||
|
||||
@create_attrs %{approved: true, score: 42}
|
||||
@update_attrs %{approved: false, score: 43}
|
||||
@invalid_attrs %{approved: nil, score: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
target_actor = insert(:actor)
|
||||
|
||||
{:ok,
|
||||
conn: put_req_header(conn, "accept", "application/json"),
|
||||
actor: actor,
|
||||
target_actor: target_actor}
|
||||
end
|
||||
|
||||
describe "create follower" do
|
||||
test "renders follower when data is valid", %{
|
||||
conn: conn,
|
||||
actor: actor,
|
||||
target_actor: target_actor
|
||||
} do
|
||||
create_attrs =
|
||||
@create_attrs
|
||||
|> Map.put(:actor_id, actor.id)
|
||||
|> Map.put(:target_actor_id, target_actor.id)
|
||||
|
||||
conn = post(conn, follower_path(conn, :create), follower: create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, follower_path(conn, :show, id))
|
||||
assert json_response(conn, 200)["data"] == %{"id" => id, "approved" => true, "score" => 42}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, follower_path(conn, :create), follower: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update follower" do
|
||||
setup [:create_follower]
|
||||
|
||||
test "renders follower when data is valid", %{
|
||||
conn: conn,
|
||||
follower: %Follower{id: id} = follower
|
||||
} do
|
||||
conn = put(conn, follower_path(conn, :update, follower), follower: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, follower_path(conn, :show, id))
|
||||
assert json_response(conn, 200)["data"] == %{"id" => id, "approved" => false, "score" => 43}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, follower: follower} do
|
||||
conn = put(conn, follower_path(conn, :update, follower), follower: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete follower" do
|
||||
setup [:create_follower]
|
||||
|
||||
test "deletes chosen follower", %{conn: conn, follower: follower} do
|
||||
conn = delete(conn, follower_path(conn, :delete, follower))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, follower_path(conn, :show, follower))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_follower(%{actor: actor, target_actor: target_actor}) do
|
||||
follower = insert(:follower, actor: actor, target_actor: target_actor)
|
||||
[follower: follower]
|
||||
end
|
||||
end
|
||||
@@ -1,147 +0,0 @@
|
||||
defmodule MobilizonWeb.SessionControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Session
|
||||
|
||||
@create_attrs %{
|
||||
audios_urls: "some audios_urls",
|
||||
language: "some language",
|
||||
long_abstract: "some long_abstract",
|
||||
short_abstract: "some short_abstract",
|
||||
slides_url: "some slides_url",
|
||||
subtitle: "some subtitle",
|
||||
title: "some title",
|
||||
videos_urls: "some videos_urls"
|
||||
}
|
||||
@update_attrs %{
|
||||
audios_urls: "some updated audios_urls",
|
||||
language: "some updated language",
|
||||
long_abstract: "some updated long_abstract",
|
||||
short_abstract: "some updated short_abstract",
|
||||
slides_url: "some updated slides_url",
|
||||
subtitle: "some updated subtitle",
|
||||
title: "some updated title",
|
||||
videos_urls: "some updated videos_urls"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
audios_urls: nil,
|
||||
language: nil,
|
||||
long_abstract: nil,
|
||||
short_abstract: nil,
|
||||
slides_url: nil,
|
||||
subtitle: nil,
|
||||
title: nil,
|
||||
videos_urls: nil
|
||||
}
|
||||
|
||||
def fixture(:session) do
|
||||
{:ok, session} = Events.create_session(@create_attrs)
|
||||
session
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
{:ok, conn: conn, user: user, event: event}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all sessions", %{conn: conn} do
|
||||
conn = get(conn, session_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create session" do
|
||||
test "renders session when data is valid", %{conn: conn, user: user, event: event} do
|
||||
conn = auth_conn(conn, user)
|
||||
event_id = event.id
|
||||
attrs = Map.put(@create_attrs, :event_id, event_id)
|
||||
conn = post(conn, session_path(conn, :create), session: attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, session_path(conn, :show_sessions_for_event, event.uuid))
|
||||
assert hd(json_response(conn, 200)["data"])["id"] == id
|
||||
|
||||
conn = get(conn, session_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"audios_urls" => "some audios_urls",
|
||||
"language" => "some language",
|
||||
"long_abstract" => "some long_abstract",
|
||||
"short_abstract" => "some short_abstract",
|
||||
"slides_url" => "some slides_url",
|
||||
"subtitle" => "some subtitle",
|
||||
"title" => "some title",
|
||||
"videos_urls" => "some videos_urls"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user, event: event} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :event_id, event.id)
|
||||
conn = post(conn, session_path(conn, :create), session: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update session" do
|
||||
setup [:create_session]
|
||||
|
||||
test "renders session when data is valid", %{
|
||||
conn: conn,
|
||||
session: %Session{id: id} = session,
|
||||
user: user,
|
||||
event: event
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@update_attrs, :event_id, event.id)
|
||||
conn = patch(conn, session_path(conn, :update, session), session: attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, session_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"audios_urls" => "some updated audios_urls",
|
||||
"language" => "some updated language",
|
||||
"long_abstract" => "some updated long_abstract",
|
||||
"short_abstract" => "some updated short_abstract",
|
||||
"slides_url" => "some updated slides_url",
|
||||
"subtitle" => "some updated subtitle",
|
||||
"title" => "some updated title",
|
||||
"videos_urls" => "some updated videos_urls"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, session: session, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = patch(conn, session_path(conn, :update, session), session: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete session" do
|
||||
setup [:create_session]
|
||||
|
||||
test "deletes chosen session", %{conn: conn, session: session, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, session_path(conn, :delete, session))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, session_path(conn, :show, session))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_session(_) do
|
||||
session = insert(:session)
|
||||
{:ok, session: session}
|
||||
end
|
||||
end
|
||||
@@ -1,85 +0,0 @@
|
||||
defmodule MobilizonWeb.TagControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Tag
|
||||
|
||||
@create_attrs %{title: "some title"}
|
||||
@update_attrs %{title: "some updated title"}
|
||||
@invalid_attrs %{title: nil}
|
||||
|
||||
def fixture(:tag) do
|
||||
{:ok, tag} = Events.create_tag(@create_attrs)
|
||||
tag
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
{:ok, conn: conn, user: user}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all tags", %{conn: conn} do
|
||||
conn = get(conn, tag_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create tag" do
|
||||
test "renders tag when data is valid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, tag_path(conn, :create), tag: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, tag_path(conn, :show, id))
|
||||
assert json_response(conn, 200)["data"] == %{"id" => id, "title" => "some title"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = post(conn, tag_path(conn, :create), tag: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update tag" do
|
||||
setup [:create_tag]
|
||||
|
||||
test "renders tag when data is valid", %{conn: conn, tag: %Tag{id: id} = tag, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, tag_path(conn, :update, tag), tag: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, tag_path(conn, :show, id))
|
||||
assert json_response(conn, 200)["data"] == %{"id" => id, "title" => "some updated title"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, tag: tag, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = put(conn, tag_path(conn, :update, tag), tag: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete tag" do
|
||||
setup [:create_tag]
|
||||
|
||||
test "deletes chosen tag", %{conn: conn, tag: tag, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, tag_path(conn, :delete, tag))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, tag_path(conn, :show, tag))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_tag(_) do
|
||||
tag = fixture(:tag)
|
||||
{:ok, tag: tag}
|
||||
end
|
||||
end
|
||||
@@ -1,116 +0,0 @@
|
||||
defmodule MobilizonWeb.TrackControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Track
|
||||
|
||||
@create_attrs %{color: "some color", description: "some description", name: "some name"}
|
||||
@update_attrs %{
|
||||
color: "some updated color",
|
||||
description: "some updated description",
|
||||
name: "some updated name"
|
||||
}
|
||||
@invalid_attrs %{color: nil, description: nil, name: nil}
|
||||
|
||||
def fixture(:track) do
|
||||
{:ok, track} = Events.create_track(@create_attrs)
|
||||
track
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
{:ok, conn: conn, user: user, event: event}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all tracks", %{conn: conn} do
|
||||
conn = get(conn, track_path(conn, :index))
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create track" do
|
||||
test "renders track when data is valid", %{conn: conn, user: user, event: event} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@create_attrs, :event_id, event.id)
|
||||
conn = post(conn, track_path(conn, :create), track: attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, track_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"color" => "some color",
|
||||
"description" => "some description",
|
||||
"name" => "some name"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user, event: event} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :event_id, event.id)
|
||||
conn = post(conn, track_path(conn, :create), track: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update track" do
|
||||
setup [:create_track]
|
||||
|
||||
test "renders track when data is valid", %{
|
||||
conn: conn,
|
||||
track: %Track{id: id} = track,
|
||||
user: user,
|
||||
event: event
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@update_attrs, :event_id, event.id)
|
||||
conn = put(conn, track_path(conn, :update, track), track: attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, track_path(conn, :show, id))
|
||||
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"color" => "some updated color",
|
||||
"description" => "some updated description",
|
||||
"name" => "some updated name"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{
|
||||
conn: conn,
|
||||
track: track,
|
||||
user: user,
|
||||
event: event
|
||||
} do
|
||||
conn = auth_conn(conn, user)
|
||||
attrs = Map.put(@invalid_attrs, :event_id, event.id)
|
||||
conn = put(conn, track_path(conn, :update, track), track: attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete track" do
|
||||
setup [:create_track]
|
||||
|
||||
test "deletes chosen track", %{conn: conn, track: track, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, track_path(conn, :delete, track))
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent(404, fn ->
|
||||
get(conn, track_path(conn, :show, track))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_track(_) do
|
||||
track = insert(:track)
|
||||
{:ok, track: track}
|
||||
end
|
||||
end
|
||||
@@ -1,223 +0,0 @@
|
||||
defmodule MobilizonWeb.UserControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.User
|
||||
use Bamboo.Test
|
||||
|
||||
@create_attrs %{email: "foo@bar.tld", password: "some password_hash", username: "some username"}
|
||||
# @update_attrs %{email: "foo@fighters.tld", password: "some updated password_hash", username: "some updated username"}
|
||||
@invalid_attrs %{email: "not an email", password: nil, username: nil}
|
||||
|
||||
def fixture(:user) do
|
||||
{:ok, user} = Actors.create_user(@create_attrs)
|
||||
user
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
{:ok, conn: conn, user: user, actor: actor}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all users", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = get(conn, user_path(conn, :index))
|
||||
assert hd(json_response(conn, 200)["data"])["id"] == user.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "create user" do
|
||||
test "renders user when data is valid", %{conn: conn} do
|
||||
conn = post(conn, user_path(conn, :register), @create_attrs)
|
||||
assert %{"email" => "foo@bar.tld"} = json_response(conn, 201)
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(@create_attrs.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.confirmation_email(user))
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, user_path(conn, :register), @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
|
||||
test "renders user with avatar when email is valid", %{conn: conn} do
|
||||
attrs = %{
|
||||
email: "contact@framasoft.org",
|
||||
password: "some password_hash",
|
||||
username: "framasoft"
|
||||
}
|
||||
|
||||
conn = post(conn, user_path(conn, :register), attrs)
|
||||
assert %{"email" => "contact@framasoft.org"} = json_response(conn, 201)
|
||||
end
|
||||
end
|
||||
|
||||
describe "validating user" do
|
||||
test "validate user when token is valid", %{conn: conn} do
|
||||
conn = post(conn, user_path(conn, :create), @create_attrs)
|
||||
assert %{"email" => "foo@bar.tld"} = json_response(conn, 201)
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(@create_attrs.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.confirmation_email(user))
|
||||
|
||||
conn = get(conn, user_path(conn, :validate, user.confirmation_token))
|
||||
assert %{"user" => _, "token" => _} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "validate user when token is invalid", %{conn: conn} do
|
||||
conn = post(conn, user_path(conn, :create), @create_attrs)
|
||||
assert %{"email" => "foo@bar.tld"} = json_response(conn, 201)
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(@create_attrs.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.confirmation_email(user))
|
||||
|
||||
conn = get(conn, user_path(conn, :validate, "toto"))
|
||||
assert %{"error" => _} = json_response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "revalidating user" do
|
||||
test "ask to resend token to user when too soon", %{conn: conn} do
|
||||
conn = post(conn, user_path(conn, :create), @create_attrs)
|
||||
assert %{"email" => "foo@bar.tld"} = json_response(conn, 201)
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(@create_attrs.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.confirmation_email(user))
|
||||
|
||||
conn = post(conn, user_path(conn, :resend_confirmation), %{"email" => @create_attrs.email})
|
||||
assert %{"error" => _} = json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "ask to resend token to user when the time is right", %{conn: conn} do
|
||||
conn = post(conn, user_path(conn, :create), @create_attrs)
|
||||
|
||||
assert %{"email" => "foo@bar.tld"} = json_response(conn, 201)
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(@create_attrs.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.confirmation_email(user))
|
||||
|
||||
# Hammer time !
|
||||
{:ok, %User{} = user} =
|
||||
Mobilizon.Actors.update_user(user, %{
|
||||
confirmation_sent_at: Timex.shift(user.confirmation_sent_at, hours: -3)
|
||||
})
|
||||
|
||||
conn = post(conn, user_path(conn, :resend_confirmation), %{"email" => @create_attrs.email})
|
||||
assert_delivered_email(Mobilizon.Email.User.confirmation_email(user))
|
||||
assert %{"email" => "foo@bar.tld"} = json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "resetting user's password" do
|
||||
test "ask for reset", %{conn: conn, user: user} do
|
||||
user_email = user.email
|
||||
|
||||
# Send reset email
|
||||
conn = post(conn, user_path(conn, :send_reset_password), %{"email" => user_email})
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(user.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.reset_password_email(user))
|
||||
assert %{"email" => user_email} = json_response(conn, 200)
|
||||
|
||||
# Call reset route
|
||||
conn =
|
||||
post(conn, user_path(conn, :reset_password), %{
|
||||
"password" => "new password",
|
||||
"token" => user.reset_password_token
|
||||
})
|
||||
|
||||
user_id = user.id
|
||||
assert %{"user" => %{"id" => user_id}} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "ask twice for reset too soon", %{conn: conn, user: user} do
|
||||
user_email = user.email
|
||||
|
||||
# Send reset email
|
||||
conn = post(conn, user_path(conn, :send_reset_password), %{"email" => user.email})
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(user.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.reset_password_email(user))
|
||||
assert %{"email" => user_email} = json_response(conn, 200)
|
||||
|
||||
# Send reset email again
|
||||
conn = post(conn, user_path(conn, :send_reset_password), %{"email" => user.email})
|
||||
|
||||
assert %{"errors" => "You requested a new reset password too early"} =
|
||||
json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "ask twice for reset after a while", %{conn: conn, user: user} do
|
||||
user_email = user.email
|
||||
|
||||
# Send reset email
|
||||
conn = post(conn, user_path(conn, :send_reset_password), %{"email" => user.email})
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(user.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.reset_password_email(user))
|
||||
assert %{"email" => user_email} = json_response(conn, 200)
|
||||
|
||||
# Hammer time !
|
||||
{:ok, %User{} = user} =
|
||||
Mobilizon.Actors.update_user(user, %{
|
||||
reset_password_sent_at: Timex.shift(user.reset_password_sent_at, hours: -3)
|
||||
})
|
||||
|
||||
# Send reset email again
|
||||
conn = post(conn, user_path(conn, :send_reset_password), %{"email" => user.email})
|
||||
assert {:ok, %User{} = user} = Mobilizon.Actors.get_user_by_email(user.email)
|
||||
assert_delivered_email(Mobilizon.Email.User.reset_password_email(user))
|
||||
assert %{"email" => user_email} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "ask for reset with wrong address", %{conn: conn} do
|
||||
conn = post(conn, user_path(conn, :send_reset_password), %{"email" => "yolo@coucou"})
|
||||
assert %{"errors" => "Unable to find an user with this email"} = json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "calling reset route with wrong token", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, user_path(conn, :reset_password), %{
|
||||
"password" => "new password",
|
||||
"token" => "just wrong"
|
||||
})
|
||||
|
||||
assert %{"errors" => %{"token" => ["Wrong token for password reset"]}} =
|
||||
json_response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
# describe "update user" do
|
||||
# setup [:create_user]
|
||||
#
|
||||
# test "renders user when data is valid", %{conn: conn, user: %User{id: id} = user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = put conn, user_path(conn, :update, user), user: @update_attrs
|
||||
# assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
#
|
||||
# conn = get conn, user_path(conn, :show, id)
|
||||
# assert json_response(conn, 200)["data"] == %{
|
||||
# "id" => id,
|
||||
# "email" => "some updated email",
|
||||
# "password_hash" => "some updated password_hash",
|
||||
# "role" => 43}
|
||||
# end
|
||||
#
|
||||
# test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
# conn = auth_conn(conn, user)
|
||||
# conn = put conn, user_path(conn, :update, user), user: @invalid_attrs
|
||||
# assert json_response(conn, 422)["errors"] != %{}
|
||||
# end
|
||||
# end
|
||||
|
||||
describe "delete user" do
|
||||
setup [:create_user]
|
||||
|
||||
test "deletes chosen user", %{conn: conn, user: user} do
|
||||
conn = auth_conn(conn, user)
|
||||
conn = delete(conn, user_path(conn, :delete, user))
|
||||
assert response(conn, 204)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_user(_) do
|
||||
user = insert(:user)
|
||||
{:ok, user: user}
|
||||
end
|
||||
end
|
||||
BIN
test/fixtures/category_picture.png
vendored
Normal file
BIN
test/fixtures/category_picture.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
BIN
test/fixtures/category_picture_updated.png
vendored
Normal file
BIN
test/fixtures/category_picture_updated.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -59,6 +59,16 @@ defmodule Mobilizon.ActorsTest do
|
||||
assert actor_fetched = actor
|
||||
end
|
||||
|
||||
test "get_actor_for_user/1 returns the actor for an user", %{actor: %{user: user} = actor} do
|
||||
assert actor = Actors.get_actor_for_user(user)
|
||||
end
|
||||
|
||||
test "get_actor_for_user/1 returns the actor for an user with no default actor defined" do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
assert actor = Actors.get_actor_for_user(user)
|
||||
end
|
||||
|
||||
test "get_actor_with_everything!/1 returns the actor with it's organized events", %{
|
||||
actor: actor
|
||||
} do
|
||||
@@ -185,7 +195,6 @@ defmodule Mobilizon.ActorsTest do
|
||||
20_890_513_599_005_517_665_557_846_902_571_022_168_782_075_040_010_449_365_706_450_877_170_130_373_892_202_874_869_873_999_284_399_697_282_332_064_948_148_602_583_340_776_692_090_472_558_740_998_357_203_838_580_321_412_679_020_304_645_826_371_196_718_081_108_049_114_160_630_664_514_340_729_769_453_281_682_773_898_619_827_376_232_969_899_348_462_205_389_310_883_299_183_817_817_999_273_916_446_620_095_414_233_374_619_948_098_516_821_650_069_821_783_810_210_582_035_456_563_335_930_330_252_551_528_035_801_173_640_288_329_718_719_895_926_309_416_142_129_926_226_047_930_429_802_084_560_488_897_717_417_403_272_782_469_039_131_379_953_278_833_320_195_233_761_955_815_307_522_871_787_339_192_744_439_894_317_730_207_141_881_699_363_391_788_150_650_217_284_777_541_358_381_165_360_697_136_307_663_640_904_621_178_632_289_787,
|
||||
65537}
|
||||
test "test get_public_key_for_url/1 with remote actor" do
|
||||
require Logger
|
||||
assert Actor.get_public_key_for_url(@remote_account_url) == @remote_actor_key
|
||||
end
|
||||
|
||||
@@ -199,6 +208,10 @@ defmodule Mobilizon.ActorsTest do
|
||||
assert actor.preferred_username == "some username"
|
||||
end
|
||||
|
||||
test "create_actor/1 with empty data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Actors.create_actor()
|
||||
end
|
||||
|
||||
test "create_actor/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Actors.create_actor(@invalid_attrs)
|
||||
end
|
||||
@@ -264,7 +277,7 @@ defmodule Mobilizon.ActorsTest do
|
||||
|
||||
test "create_user/1 with valid data creates a user" do
|
||||
{:ok, %Actor{} = actor} = Actors.create_actor(@actor_valid_attrs)
|
||||
attrs = Map.put(@valid_attrs, :actor_id, actor.id)
|
||||
attrs = @valid_attrs |> Map.put(:actor_id, actor.id) |> Map.put(:default_actor_id, actor.id)
|
||||
assert {:ok, %User{} = user} = Actors.create_user(attrs)
|
||||
assert user.email == "foo@bar.tld"
|
||||
assert user.role == 42
|
||||
@@ -302,12 +315,42 @@ defmodule Mobilizon.ActorsTest do
|
||||
@email "email@domain.tld"
|
||||
@password "password"
|
||||
test "authenticate/1 checks the user's password" do
|
||||
{:ok, %User{} = user} = Actors.create_user(%{email: @email, password: @password})
|
||||
{:ok, %Actor{user: user} = _actor} =
|
||||
Actors.register(%{email: @email, password: @password, username: "yolo"})
|
||||
|
||||
assert {:ok, _, _} = Actors.authenticate(%{user: user, password: @password})
|
||||
|
||||
assert {:error, :unauthorized} ==
|
||||
Actors.authenticate(%{user: user, password: "bad password"})
|
||||
end
|
||||
|
||||
test "get_user_by_email/1 finds an user by it's email" do
|
||||
{:ok, %Actor{user: %User{email: email} = user} = _actor} =
|
||||
Actors.register(%{email: @email, password: @password, username: "yolo"})
|
||||
|
||||
assert email == @email
|
||||
{:ok, %User{id: id}} = Actors.get_user_by_email(@email)
|
||||
assert id == user.id
|
||||
assert {:error, :user_not_found} = Actors.get_user_by_email("no email")
|
||||
end
|
||||
|
||||
test "get_user_by_email/1 finds an activated user by it's email" do
|
||||
{:ok, %Actor{user: %User{email: email} = user} = _actor} =
|
||||
Actors.register(%{email: @email, password: @password, username: "yolo"})
|
||||
{:ok, %User{id: id}} = Actors.get_user_by_email(@email, false)
|
||||
assert id == user.id
|
||||
assert {:error, :user_not_found} = Actors.get_user_by_email(@email, true)
|
||||
|
||||
Actors.update_user(user, %{
|
||||
"confirmed_at" => DateTime.utc_now(),
|
||||
"confirmation_sent_at" => nil,
|
||||
"confirmation_token" => nil
|
||||
})
|
||||
|
||||
assert {:error, :user_not_found} = Actors.get_user_by_email(@email, false)
|
||||
{:ok, %User{id: id}} = Actors.get_user_by_email(@email, true)
|
||||
assert id == user.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "groups" do
|
||||
@@ -68,16 +68,18 @@ defmodule Mobilizon.EventsTest do
|
||||
assert Events.get_event_full!(event.id).participants == []
|
||||
end
|
||||
|
||||
test "find_events_by_name/1 returns events for a given name", %{event: event} do
|
||||
assert event.title == hd(Events.find_events_by_name(event.title)).title
|
||||
test "find_events_by_name/1 returns events for a given name", %{
|
||||
event: %Event{title: title} = event
|
||||
} do
|
||||
assert title == hd(Events.find_events_by_name(event.title)).title
|
||||
|
||||
event2 = insert(:event, title: "Special event")
|
||||
%Event{title: title2} = event2 = insert(:event, title: "Special event")
|
||||
assert event2.title == hd(Events.find_events_by_name("Special")).title
|
||||
|
||||
event2 = insert(:event, title: "Special event")
|
||||
assert event2.title == hd(Events.find_events_by_name(" Special ")).title
|
||||
|
||||
assert [] == Events.find_events_by_name("")
|
||||
assert title = hd(Events.find_events_by_name("")).title
|
||||
assert title2 = hd(tl(Events.find_events_by_name(""))).title
|
||||
end
|
||||
|
||||
test "create_event/1 with valid data creates a event" do
|
||||
@@ -168,10 +170,20 @@ defmodule Mobilizon.EventsTest do
|
||||
{:ok, category: category}
|
||||
end
|
||||
|
||||
@valid_attrs %{description: "some description", picture: "some picture", title: "some title"}
|
||||
@valid_attrs %{
|
||||
description: "some description",
|
||||
picture: %Plug.Upload{
|
||||
path: "test/fixtures/category_picture.png",
|
||||
filename: "category_picture.png"
|
||||
},
|
||||
title: "some title"
|
||||
}
|
||||
@update_attrs %{
|
||||
description: "some updated description",
|
||||
picture: "some updated picture",
|
||||
picture: %Plug.Upload{
|
||||
path: "test/fixtures/category_picture_updated.png",
|
||||
filename: "category_picture_updated.png"
|
||||
},
|
||||
title: "some updated title"
|
||||
}
|
||||
@invalid_attrs %{description: nil, picture: nil, title: nil}
|
||||
@@ -191,7 +203,7 @@ defmodule Mobilizon.EventsTest do
|
||||
test "create_category/1 with valid data creates a category" do
|
||||
assert {:ok, %Category{} = category} = Events.create_category(@valid_attrs)
|
||||
assert category.description == "some description"
|
||||
assert category.picture == "some picture"
|
||||
assert category.picture.file_name == @valid_attrs.picture.filename
|
||||
assert category.title == "some title"
|
||||
end
|
||||
|
||||
@@ -203,7 +215,7 @@ defmodule Mobilizon.EventsTest do
|
||||
assert {:ok, category} = Events.update_category(category, @update_attrs)
|
||||
assert %Category{} = category
|
||||
assert category.description == "some updated description"
|
||||
assert category.picture == "some updated picture"
|
||||
assert category.picture.file_name == @update_attrs.picture.filename
|
||||
assert category.title == "some updated title"
|
||||
end
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
defmodule MobilizonWeb.NodeinfoControllerTest do
|
||||
defmodule MobilizonWeb.NodeInfoControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
@instance Application.get_env(:mobilizon, :instance)
|
||||
|
||||
test "Get node info schemas", %{conn: conn} do
|
||||
conn = get(conn, nodeinfo_path(conn, :schemas))
|
||||
conn = get(conn, node_info_path(conn, :schemas))
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"links" => [
|
||||
%{
|
||||
"href" =>
|
||||
MobilizonWeb.Router.Helpers.nodeinfo_url(
|
||||
MobilizonWeb.Router.Helpers.node_info_url(
|
||||
MobilizonWeb.Endpoint,
|
||||
:nodeinfo,
|
||||
"2.0"
|
||||
@@ -22,7 +22,7 @@ defmodule MobilizonWeb.NodeinfoControllerTest do
|
||||
end
|
||||
|
||||
test "Get node info", %{conn: conn} do
|
||||
conn = get(conn, nodeinfo_path(conn, :nodeinfo, "2.0"))
|
||||
conn = get(conn, node_info_path(conn, :nodeinfo, "2.0"))
|
||||
|
||||
resp = json_response(conn, 200)
|
||||
|
||||
78
test/mobilizon_web/resolvers/actor_resolver_test.exs
Normal file
78
test/mobilizon_web/resolvers/actor_resolver_test.exs
Normal file
@@ -0,0 +1,78 @@
|
||||
defmodule MobilizonWeb.Resolvers.ActorResolverTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
alias Mobilizon.{Events, Actors}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
import Mobilizon.Factory
|
||||
|
||||
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
||||
@non_existent_username "nonexistent"
|
||||
|
||||
describe "Actor Resolver" do
|
||||
test "find_actor/3 returns an actor by it's username", context do
|
||||
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||
|
||||
query = """
|
||||
{
|
||||
actor(preferredUsername: "#{actor.preferred_username}") {
|
||||
preferredUsername,
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "actor"))
|
||||
|
||||
assert json_response(res, 200)["data"]["actor"]["preferredUsername"] ==
|
||||
actor.preferred_username
|
||||
|
||||
query = """
|
||||
{
|
||||
actor(preferredUsername: "#{@non_existent_username}") {
|
||||
preferredUsername,
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "actor"))
|
||||
|
||||
assert json_response(res, 200)["data"]["actor"] == nil
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"Actor with name #{@non_existent_username} not found"
|
||||
end
|
||||
|
||||
test "get_current_actor/3 returns the current logged-in actor", context do
|
||||
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||
|
||||
query = """
|
||||
{
|
||||
loggedActor {
|
||||
avatarUrl,
|
||||
preferredUsername,
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_actor"))
|
||||
|
||||
assert json_response(res, 200)["data"]["loggedActor"] == nil
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"You need to be logged-in to view current actor"
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> auth_conn(actor.user)
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_actor"))
|
||||
|
||||
assert json_response(res, 200)["data"]["loggedActor"]["preferredUsername"] ==
|
||||
actor.preferred_username
|
||||
end
|
||||
end
|
||||
end
|
||||
60
test/mobilizon_web/resolvers/category_resolver_test.exs
Normal file
60
test/mobilizon_web/resolvers/category_resolver_test.exs
Normal file
@@ -0,0 +1,60 @@
|
||||
defmodule MobilizonWeb.Resolvers.CategoryResolverTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
import Mobilizon.Factory
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, %Actor{} = actor} =
|
||||
Actors.register(%{email: "test@test.tld", password: "testest", username: "test"})
|
||||
|
||||
{:ok, conn: conn, actor: actor}
|
||||
end
|
||||
|
||||
describe "Category Resolver" do
|
||||
test "list_categories/3 returns the list of categories", context do
|
||||
insert(:category)
|
||||
insert(:category)
|
||||
|
||||
query = """
|
||||
{
|
||||
categories {
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
picture {
|
||||
url,
|
||||
},
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "categories"))
|
||||
|
||||
assert json_response(res, 200)["data"]["categories"] |> length == 2
|
||||
end
|
||||
|
||||
# We can't test an upload…yet?
|
||||
# test "create_category/3 creates a category", %{conn: conn, actor: actor} do
|
||||
# mutation = """
|
||||
# mutation {
|
||||
# createCategory(title: "my category", description: "my desc") {
|
||||
# id,
|
||||
# title,
|
||||
# description,
|
||||
# },
|
||||
# }
|
||||
# """
|
||||
|
||||
# res =
|
||||
# conn
|
||||
# |> auth_conn(actor.user)
|
||||
# |> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
# assert json_response(res, 200)["data"]["createCategory"]["title"] == "my category"
|
||||
# end
|
||||
end
|
||||
end
|
||||
167
test/mobilizon_web/resolvers/event_resolver_test.exs
Normal file
167
test/mobilizon_web/resolvers/event_resolver_test.exs
Normal file
@@ -0,0 +1,167 @@
|
||||
defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
alias Mobilizon.{Events, Actors}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
import Mobilizon.Factory
|
||||
|
||||
@event %{description: "some body", title: "some title", begins_on: Ecto.DateTime.utc()}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, %Actor{} = actor} =
|
||||
Actors.register(%{email: "test@test.tld", password: "testest", username: "test"})
|
||||
|
||||
{:ok, conn: conn, actor: actor}
|
||||
end
|
||||
|
||||
describe "Event Resolver" do
|
||||
test "find_event/3 returns an event", context do
|
||||
category = insert(:category)
|
||||
|
||||
event =
|
||||
@event
|
||||
|> Map.put(:organizer_actor_id, context.actor.id)
|
||||
|> Map.put(:category_id, category.id)
|
||||
|
||||
{:ok, event} = Events.create_event(event)
|
||||
|
||||
query = """
|
||||
{
|
||||
event(uuid: "#{event.uuid}") {
|
||||
uuid,
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
||||
|
||||
assert json_response(res, 200)["data"]["event"]["uuid"] == to_string(event.uuid)
|
||||
|
||||
query = """
|
||||
{
|
||||
event(uuid: "bad uuid") {
|
||||
uuid,
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
||||
|
||||
assert [%{"message" => "Argument \"uuid\" has invalid value \"bad uuid\"."}] =
|
||||
json_response(res, 400)["errors"]
|
||||
end
|
||||
|
||||
test "list_participants_for_event/3 returns participants for an event", context do
|
||||
# Plain event
|
||||
category = insert(:category)
|
||||
|
||||
event =
|
||||
@event
|
||||
|> Map.put(:organizer_actor_id, context.actor.id)
|
||||
|> Map.put(:category_id, category.id)
|
||||
|
||||
{:ok, event} = Events.create_event(event)
|
||||
|
||||
query = """
|
||||
{
|
||||
participants(uuid: "#{event.uuid}") {
|
||||
role,
|
||||
actor {
|
||||
preferredUsername
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
|
||||
|
||||
assert json_response(res, 200)["data"]["participants"] == [
|
||||
%{
|
||||
"actor" => %{"preferredUsername" => context.actor.preferred_username},
|
||||
"role" => 4
|
||||
}
|
||||
]
|
||||
|
||||
# Adding a participant
|
||||
actor2 = insert(:actor)
|
||||
participant = insert(:participant, event: event, actor: actor2)
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
|
||||
|
||||
assert json_response(res, 200)["data"]["participants"] == [
|
||||
%{
|
||||
"actor" => %{"preferredUsername" => context.actor.preferred_username},
|
||||
"role" => 4
|
||||
},
|
||||
%{
|
||||
"actor" => %{"preferredUsername" => participant.actor.preferred_username},
|
||||
"role" => 0
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
test "create_event/3 creates an event", %{conn: conn, actor: actor} do
|
||||
category = insert(:category)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
createEvent(
|
||||
title: "come to my event",
|
||||
description: "it will be fine",
|
||||
beginsOn: "#{DateTime.utc_now() |> DateTime.to_iso8601()}",
|
||||
organizer_actor_id: #{actor.id},
|
||||
category_id: #{category.id},
|
||||
addressType: #{"OTHER"}
|
||||
) {
|
||||
title,
|
||||
uuid
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(actor.user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["createEvent"]["title"] == "come to my event"
|
||||
end
|
||||
|
||||
test "search_events_and_actors/3 finds events and actors", %{conn: conn, actor: actor} do
|
||||
event = insert(:event, title: "test")
|
||||
|
||||
query = """
|
||||
{
|
||||
search(search: "test") {
|
||||
...on Event {
|
||||
title,
|
||||
uuid,
|
||||
__typename
|
||||
},
|
||||
...on Actor {
|
||||
preferredUsername,
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "search"))
|
||||
|
||||
assert hd(json_response(res, 200)["data"]["search"])["uuid"] == to_string(event.uuid)
|
||||
|
||||
assert hd(tl(json_response(res, 200)["data"]["search"]))["preferredUsername"] ==
|
||||
actor.preferred_username
|
||||
end
|
||||
end
|
||||
end
|
||||
239
test/mobilizon_web/resolvers/user_resolver_test.exs
Normal file
239
test/mobilizon_web/resolvers/user_resolver_test.exs
Normal file
@@ -0,0 +1,239 @@
|
||||
defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
alias Mobilizon.{Events, Actors}
|
||||
alias Mobilizon.Actors.{Actor, User}
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
import Mobilizon.Factory
|
||||
use Bamboo.Test
|
||||
|
||||
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
||||
@non_existent_username "nonexistent"
|
||||
|
||||
describe "User Resolver" do
|
||||
test "find_user/3 returns an user by it's id", context do
|
||||
user = insert(:user)
|
||||
|
||||
query = """
|
||||
{
|
||||
user(id: "#{user.id}") {
|
||||
email,
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "user"))
|
||||
|
||||
assert json_response(res, 200)["data"]["user"]["email"] == user.email
|
||||
|
||||
query = """
|
||||
{
|
||||
user(id: "#{0}") {
|
||||
email,
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "user"))
|
||||
|
||||
assert json_response(res, 200)["data"]["user"] == nil
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "User with ID #{0} not found"
|
||||
end
|
||||
|
||||
test "get_current_user/3 returns the current logged-in user", context do
|
||||
user = insert(:user)
|
||||
|
||||
query = """
|
||||
{
|
||||
loggedUser {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_user"))
|
||||
|
||||
assert json_response(res, 200)["data"]["loggedUser"] == nil
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"You need to be logged-in to view current user"
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> auth_conn(user)
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_user"))
|
||||
|
||||
assert json_response(res, 200)["data"]["loggedUser"]["id"] == to_string(user.id)
|
||||
end
|
||||
end
|
||||
|
||||
@account_creation %{email: "test@demo.tld", password: "long password", username: "test_account"}
|
||||
@account_creation_bad_email %{
|
||||
email: "y@l@",
|
||||
password: "long password",
|
||||
username: "test_account"
|
||||
}
|
||||
|
||||
test "test create_user_actor/3 creates an user", context do
|
||||
mutation = """
|
||||
mutation {
|
||||
createUser(
|
||||
email: "#{@account_creation.email}",
|
||||
password: "#{@account_creation.password}",
|
||||
username: "#{@account_creation.username}"
|
||||
) {
|
||||
preferred_username,
|
||||
user {
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["createUser"]["preferred_username"] ==
|
||||
@account_creation.username
|
||||
|
||||
assert json_response(res, 200)["data"]["createUser"]["user"]["email"] ==
|
||||
@account_creation.email
|
||||
end
|
||||
|
||||
test "test create_user_actor/3 doesn't create an user with bad email", context do
|
||||
mutation = """
|
||||
mutation {
|
||||
createUser(
|
||||
email: "#{@account_creation_bad_email.email}",
|
||||
password: "#{@account_creation.password}",
|
||||
username: "#{@account_creation.username}"
|
||||
) {
|
||||
preferred_username,
|
||||
user {
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "Email doesn't fit required format"
|
||||
end
|
||||
|
||||
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
||||
test "test validate_user/3 validates an user", context do
|
||||
|
||||
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
validateUser(
|
||||
token: "#{actor.user.confirmation_token}"
|
||||
) {
|
||||
token,
|
||||
user {
|
||||
id
|
||||
},
|
||||
actor {
|
||||
preferredUsername
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["validateUser"]["actor"]["preferredUsername"] == @valid_actor_params.username
|
||||
|
||||
|
||||
assert json_response(res, 200)["data"]["validateUser"]["user"]["id"] ==
|
||||
to_string(actor.user.id)
|
||||
end
|
||||
|
||||
test "test validate_user/3 with invalid token doesn't validate an user", context do
|
||||
|
||||
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
validateUser(
|
||||
token: "no pass"
|
||||
) {
|
||||
token,
|
||||
user {
|
||||
id
|
||||
},
|
||||
actor {
|
||||
preferredUsername
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "Invalid token"
|
||||
end
|
||||
|
||||
test "test resend_confirmation_email/3 with valid email resends an validation email", context do
|
||||
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
resendConfirmationEmail(
|
||||
email: "#{actor.user.email}"
|
||||
)
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "You requested again a confirmation email too soon"
|
||||
|
||||
# Hammer time !
|
||||
Mobilizon.Actors.update_user(actor.user, %{
|
||||
confirmation_sent_at: Timex.shift(actor.user.confirmation_sent_at, hours: -3)
|
||||
})
|
||||
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["resendConfirmationEmail"] == actor.user.email
|
||||
assert_delivered_email Mobilizon.Email.User.confirmation_email(actor.user)
|
||||
end
|
||||
|
||||
test "test resend_confirmation_email/3 with invalid email resends an validation email", context do
|
||||
{:ok, actor} = Actors.register(@valid_actor_params)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
resendConfirmationEmail(
|
||||
email: "oh no"
|
||||
)
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "No user to validate with this email was found"
|
||||
end
|
||||
end
|
||||
17
test/support/abinthe_helpers.ex
Normal file
17
test/support/abinthe_helpers.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule MobilizonWeb.AbsintheHelpers do
|
||||
def query_skeleton(query, query_name) do
|
||||
%{
|
||||
"operationName" => "#{query_name}",
|
||||
"query" => "query #{query_name} #{query}",
|
||||
"variables" => "{}"
|
||||
}
|
||||
end
|
||||
|
||||
def mutation_skeleton(query) do
|
||||
%{
|
||||
"operationName" => "",
|
||||
"query" => "#{query}",
|
||||
"variables" => ""
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -82,15 +82,16 @@ defmodule Mobilizon.Factory do
|
||||
actor = build(:actor)
|
||||
|
||||
%Mobilizon.Events.Event{
|
||||
title: sequence("MyEvent"),
|
||||
description: "My desc",
|
||||
title: sequence("Ceci est un événement"),
|
||||
description: "Ceci est une description avec une première phrase assez longue,
|
||||
puis sur une seconde ligne",
|
||||
begins_on: nil,
|
||||
ends_on: nil,
|
||||
organizer_actor: actor,
|
||||
category: build(:category),
|
||||
physical_address: build(:address),
|
||||
public: true,
|
||||
url: "#{MobilizonWeb.Endpoint.url()}/@#{actor.url}/#{Ecto.UUID.generate()}"
|
||||
url: "@#{actor.url}/#{Ecto.UUID.generate()}"
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user