Fix tests after category changes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-03-29 09:28:59 +02:00
parent 368911b58e
commit 4983f2d695
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 154 additions and 169 deletions

View file

@ -86,6 +86,10 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
$options: EventOptionsInput, $options: EventOptionsInput,
$draft: Boolean, $draft: Boolean,
$language: String $language: String
$picture: MediaInput
$tags: [String]
$physicalAddress: AddressInput
$category: EventCategory
) { ) {
createEvent( createEvent(
title: $title, title: $title,
@ -99,7 +103,11 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
online_address: $online_address, online_address: $online_address,
options: $options, options: $options,
draft: $draft, draft: $draft,
picture: $picture
language: $language language: $language
physicalAddress: $physicalAddress
category: $category
tags: $tags
) { ) {
id, id,
uuid, uuid,
@ -115,6 +123,12 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
attributed_to { attributed_to {
id id
}, },
physicalAddress {
id,
url,
geom,
street
}
online_address, online_address,
phone_address, phone_address,
category, category,
@ -125,6 +139,14 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
showRemainingAttendeeCapacity, showRemainingAttendeeCapacity,
showEndTime showEndTime
} }
picture {
url
name
}
tags {
slug
title
}
} }
} }
""" """
@ -451,39 +473,32 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
end end
test "create_event/3 creates an event with tags", %{conn: conn, actor: actor, user: user} do test "create_event/3 creates an event with tags", %{conn: conn, actor: actor, user: user} do
mutation = """
mutation {
createEvent(
title: "my event is referenced",
description: "with tags!",
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
organizer_actor_id: "#{actor.id}",
category: "birthday",
tags: ["nicolas", "birthday", "bad tag"]
) {
title,
uuid,
tags {
title,
slug
}
}
}
"""
res = res =
conn conn
|> auth_conn(user) |> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) |> AbsintheHelpers.graphql_query(
query: @create_event_mutation,
variables: %{
title: "my event is referenced",
description: "with tags!",
begins_on:
"#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
organizer_actor_id: "#{actor.id}",
category: "PARTY",
tags: ["nicolas", "birthday", "bad tag"]
}
)
assert json_response(res, 200)["errors"] == nil assert res["errors"] == nil
assert json_response(res, 200)["data"]["createEvent"]["title"] == "my event is referenced" assert res["data"]["createEvent"]["title"] == "my event is referenced"
assert json_response(res, 200)["data"]["createEvent"]["tags"] == [ assert res["data"]["createEvent"]["tags"] == [
%{"slug" => "nicolas", "title" => "nicolas"}, %{"slug" => "nicolas", "title" => "nicolas"},
%{"slug" => "birthday", "title" => "birthday"}, %{"slug" => "birthday", "title" => "birthday"},
%{"slug" => "bad-tag", "title" => "bad tag"} %{"slug" => "bad-tag", "title" => "bad tag"}
] ]
assert res["data"]["createEvent"]["category"] == "PARTY"
end end
test "create_event/3 creates an event with an address", %{ test "create_event/3 creates an event with an address", %{
@ -493,86 +508,64 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
} do } do
address = %{street: "I am a street, please believe me", locality: "Where ever"} address = %{street: "I am a street, please believe me", locality: "Where ever"}
mutation = """ res =
mutation { conn
createEvent( |> auth_conn(user)
title: "my event is referenced", |> AbsintheHelpers.graphql_query(
description: "with tags!", query: @create_event_mutation,
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}", variables: %{
organizer_actor_id: "#{actor.id}", title: "my event is referenced",
category: "birthday", description: "with tags!",
physical_address: { begins_on:
street: "#{address.street}", "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
locality: "#{address.locality}" organizer_actor_id: "#{actor.id}",
} category: "PARTY",
) { physicalAddress: %{
title, street: "#{address.street}",
uuid, locality: "#{address.locality}"
physicalAddress {
id,
url,
geom,
street
}
}
} }
""" }
)
assert res["errors"] == nil
assert res["data"]["createEvent"]["title"] == "my event is referenced"
assert res["data"]["createEvent"]["physicalAddress"]["street"] ==
address.street
address_url = res["data"]["createEvent"]["physicalAddress"]["url"]
address_id = res["data"]["createEvent"]["physicalAddress"]["id"]
res = res =
conn conn
|> auth_conn(user) |> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) |> AbsintheHelpers.graphql_query(
query: @create_event_mutation,
assert json_response(res, 200)["errors"] == nil variables: %{
title: "my event is referenced",
assert json_response(res, 200)["data"]["createEvent"]["title"] == "my event is referenced" description: "with tags!",
begins_on:
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["street"] == "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
address.street organizer_actor_id: "#{actor.id}",
category: "PARTY",
address_url = json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["url"] physicalAddress: %{
address_id = json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["id"] id: "#{address_id}"
mutation = """
mutation {
createEvent(
title: "my event is referenced",
description: "with tags!",
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
organizer_actor_id: "#{actor.id}",
category: "birthday",
physical_address: {
id: "#{address_id}"
}
) {
title,
uuid,
physicalAddress {
id,
url,
geom,
street
}
}
} }
""" }
)
res = assert res["errors"] == nil
conn
|> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert json_response(res, 200)["errors"] == nil assert res["data"]["createEvent"]["title"] == "my event is referenced"
assert json_response(res, 200)["data"]["createEvent"]["title"] == "my event is referenced" assert res["data"]["createEvent"]["physicalAddress"]["street"] ==
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["street"] ==
address.street address.street
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["id"] == assert res["data"]["createEvent"]["physicalAddress"]["id"] ==
address_id address_id
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["url"] == assert res["data"]["createEvent"]["physicalAddress"]["url"] ==
address_url address_url
end end
@ -581,35 +574,24 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
actor: actor, actor: actor,
user: user user: user
} do } do
mutation = """
mutation {
createEvent(
title: "come to my event",
description: "it will be fine",
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
organizer_actor_id: "#{actor.id}",
category: "birthday",
picture: {
media: {
name: "picture for my event",
alt: "A very sunny landscape",
file: "event.jpg",
actor_id: #{actor.id}
}
}
) {
title,
uuid,
picture {
name,
url
}
}
}
"""
map = %{ map = %{
"query" => mutation, "query" => @create_event_mutation,
"variables" => %{
title: "come to my event",
description: "it will be fine",
begins_on:
"#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
organizer_actor_id: "#{actor.id}",
category: "PARTY",
picture: %{
media: %{
name: "picture for my event",
alt: "A very sunny landscape",
file: "event.jpg",
actor_id: actor.id
}
}
},
"event.jpg" => %Plug.Upload{ "event.jpg" => %Plug.Upload{
path: "test/fixtures/picture.png", path: "test/fixtures/picture.png",
filename: "event.jpg" filename: "event.jpg"
@ -620,14 +602,34 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
conn conn
|> auth_conn(user) |> auth_conn(user)
|> put_req_header("content-type", "multipart/form-data") |> put_req_header("content-type", "multipart/form-data")
|> post("/api", map) |> post(
"/api",
map
)
|> json_response(200)
assert json_response(res, 200)["data"]["createEvent"]["title"] == "come to my event" assert res["data"]["createEvent"]["title"] == "come to my event"
assert json_response(res, 200)["data"]["createEvent"]["picture"]["name"] == assert res["data"]["createEvent"]["picture"]["name"] ==
"picture for my event" "picture for my event"
end end
@upload_media_mutation """
mutation UploadMedia($name: String!, $alt: String, $file: Upload!) {
uploadMedia(
name: $name
alt: $alt
file: $file
) {
id
url
name
content_type
size
}
}
"""
test "create_event/3 creates an event with an picture ID", %{ test "create_event/3 creates an event with an picture ID", %{
conn: conn, conn: conn,
actor: actor, actor: actor,
@ -635,21 +637,9 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
} do } do
media = %{name: "my pic", alt: "represents something", file: "picture.png"} media = %{name: "my pic", alt: "represents something", file: "picture.png"}
mutation = """
mutation { uploadMedia (
name: "#{media.name}",
alt: "#{media.alt}",
file: "#{media.file}"
) {
id,
url,
name
}
}
"""
map = %{ map = %{
"query" => mutation, "query" => @upload_media_mutation,
"variables" => media,
media.file => %Plug.Upload{ media.file => %Plug.Upload{
path: "test/fixtures/picture.png", path: "test/fixtures/picture.png",
filename: media.file filename: media.file
@ -664,42 +654,37 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
"/api", "/api",
map map
) )
|> json_response(200)
assert json_response(res, 200)["data"]["uploadMedia"]["name"] == media.name assert res["errors"] == nil
media_id = json_response(res, 200)["data"]["uploadMedia"]["id"] assert res["data"]["uploadMedia"]["name"] == media.name
media_id = res["data"]["uploadMedia"]["id"]
mutation = """ assert media_id !== "" and not is_nil(media_id)
mutation {
createEvent(
title: "come to my event",
description: "it will be fine",
begins_on: "#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
organizer_actor_id: "#{actor.id}",
category: "birthday",
picture: {
media_id: "#{media_id}"
}
) {
title,
uuid,
picture {
name,
url
}
}
}
"""
res = res =
conn conn
|> auth_conn(user) |> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) |> AbsintheHelpers.graphql_query(
query: @create_event_mutation,
variables: %{
title: "come to my event",
description: "it will be fine",
begins_on:
"#{DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()}",
organizer_actor_id: "#{actor.id}",
category: "PARTY",
picture: %{
media_id: "#{media_id}"
}
}
)
assert json_response(res, 200)["data"]["createEvent"]["title"] == "come to my event" assert res["errors"] == nil
assert res["data"]["createEvent"]["title"] == "come to my event"
assert json_response(res, 200)["data"]["createEvent"]["picture"]["name"] == media.name assert res["data"]["createEvent"]["picture"]["name"] == media.name
assert json_response(res, 200)["data"]["createEvent"]["picture"]["url"] assert res["data"]["createEvent"]["picture"]["url"]
end end
test "create_event/3 creates an event with detected language", %{ test "create_event/3 creates an event with detected language", %{
@ -842,7 +827,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
$phoneAddress: String $phoneAddress: String
$organizerActorId: ID $organizerActorId: ID
$attributedToId: ID $attributedToId: ID
$category: String $category: EventCategory
$physicalAddress: AddressInput $physicalAddress: AddressInput
$options: EventOptionsInput $options: EventOptionsInput
$contacts: [Contact] $contacts: [Contact]
@ -1023,7 +1008,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
tags: ["tag1_updated", "tag2_updated"], tags: ["tag1_updated", "tag2_updated"],
onlineAddress: "toto@example.com", onlineAddress: "toto@example.com",
phoneAddress: "0000000000", phoneAddress: "0000000000",
category: "birthday", category: "PARTY",
options: %{ options: %{
maximumAttendeeCapacity: 30, maximumAttendeeCapacity: 30,
showRemainingAttendeeCapacity: true showRemainingAttendeeCapacity: true
@ -1046,7 +1031,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
assert event_res["status"] == "TENTATIVE" assert event_res["status"] == "TENTATIVE"
assert event_res["online_address"] == "toto@example.com" assert event_res["online_address"] == "toto@example.com"
assert event_res["phone_address"] == "0000000000" assert event_res["phone_address"] == "0000000000"
assert event_res["category"] == "birthday" assert event_res["category"] == "PARTY"
assert event_res["options"]["maximumAttendeeCapacity"] == 30 assert event_res["options"]["maximumAttendeeCapacity"] == 30
assert event_res["options"]["showRemainingAttendeeCapacity"] == true assert event_res["options"]["showRemainingAttendeeCapacity"] == true
@ -1141,7 +1126,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
title: "my event updated", title: "my event updated",
description: "description updated", description: "description updated",
beginsOn: "#{begins_on}", beginsOn: "#{begins_on}",
category: "birthday", category: "PARTY",
picture: %{ picture: %{
media: %{ media: %{
name: "picture for my event", name: "picture for my event",

View file

@ -191,7 +191,7 @@ defmodule Mobilizon.Factory do
ends_on: Timex.shift(start, hours: 2), ends_on: Timex.shift(start, hours: 2),
organizer_actor: actor, organizer_actor: actor,
attributed_to: nil, attributed_to: nil,
category: sequence("something"), category: "PARTY",
physical_address: build(:address), physical_address: build(:address),
visibility: :public, visibility: :public,
tags: build_list(3, :tag), tags: build_list(3, :tag),