From 0be1dbc9456d0915048c1ad945654a2636c7e305 Mon Sep 17 00:00:00 2001 From: Adam Hebden Date: Thu, 22 Apr 2021 12:39:25 +0100 Subject: [PATCH] Mature content channel api (#630) * Adds mature_content to Channel Resolver * Changes type to boolean & updates description * Maybe adds mature_content API test & cleans up channel_test * Updates mature_content API test to re-call the API after update * idk how to do tests, so removed most of them lol * Removed unused channel variable in tests --- lib/glimesh/graphql/schema/channel_types.ex | 1 + test/glimesh_web/api/channel_test.exs | 125 ++++++++++---------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/lib/glimesh/graphql/schema/channel_types.ex b/lib/glimesh/graphql/schema/channel_types.ex index a91e2b537..d76683de3 100644 --- a/lib/glimesh/graphql/schema/channel_types.ex +++ b/lib/glimesh/graphql/schema/channel_types.ex @@ -187,6 +187,7 @@ defmodule Glimesh.Schema.ChannelTypes do field :title, :string, description: "The title of the current stream, live or offline." field :category, :category, resolve: dataloader(Repo) field :subcategory, :subcategory, resolve: dataloader(Repo) + field :mature_content, :boolean, description: "If the streamer has flagged this channel as only appropriate for Mature Audiences." field :language, :string, description: "The language a user can expect in the stream." field :thumbnail, :string diff --git a/test/glimesh_web/api/channel_test.exs b/test/glimesh_web/api/channel_test.exs index 2220cb51e..43a7c5976 100644 --- a/test/glimesh_web/api/channel_test.exs +++ b/test/glimesh_web/api/channel_test.exs @@ -20,6 +20,8 @@ defmodule GlimeshWeb.Api.ChannelTest do title streamer { username } + mature_content + subcategory { name } @@ -35,46 +37,45 @@ defmodule GlimeshWeb.Api.ChannelTest do setup [:register_and_set_user_token, :create_channel] test "returns all channels", %{conn: conn, user: user} do - conn = - post(conn, "/api", %{ - "query" => @channels_query - }) + conn = post(conn, "/api", %{ + "query" => @channels_query + }) assert json_response(conn, 200) == %{ - "data" => %{ - "channels" => [ - %{ - "title" => "Live Stream!", - "streamer" => %{"username" => user.username} - } - ] - } - } + "data" => %{ + "channels" => [ + %{ + "title" => "Live Stream!", + "streamer" => %{"username" => user.username} + } + ] + } + } end test "returns a channel", %{conn: conn, user: user} do - conn = - post(conn, "/api", %{ - "query" => @channel_query, - "variables" => %{username: user.username} - }) + conn = post(conn, "/api", %{ + "query" => @channel_query, + "variables" => %{username: user.username} + }) assert json_response(conn, 200) == %{ - "data" => %{ - "channel" => %{ - "title" => "Live Stream!", - "streamer" => %{"username" => user.username}, - "subcategory" => %{ - "name" => "World of Warcraft" - }, - "tags" => [ - %{ - "name" => "Chill Stream" - } - ] - } - } - } + "data" => %{ + "channel" => %{ + "title" => "Live Stream!", + "streamer" => %{"username" => user.username}, + "mature_content" => false, + "subcategory" => %{ + "name" => "World of Warcraft" + }, + "tags" => [ + %{ + "name" => "Chill Stream" + } + ] + } + } + } end end @@ -109,43 +110,41 @@ defmodule GlimeshWeb.Api.ChannelTest do setup [:register_and_set_user_token, :create_tag, :create_subcategory] test "returns all categories", %{conn: conn} do - conn = - post(conn, "/api", %{ - "query" => @categories_query - }) + conn = post(conn, "/api", %{ + "query" => @categories_query + }) assert Enum.member?( - Enum.map(json_response(conn, 200)["data"]["categories"], fn x -> x["slug"] end), - "gaming" - ) + Enum.map(json_response(conn, 200)["data"]["categories"], fn x -> x["slug"] end), + "gaming" + ) end test "returns a category", %{conn: conn} do - conn = - post(conn, "/api", %{ - "query" => @category_query, - "variables" => %{slug: "gaming"} - }) + conn = post(conn, "/api", %{ + "query" => @category_query, + "variables" => %{slug: "gaming"} + }) assert json_response(conn, 200) == %{ - "data" => %{ - "category" => %{ - "name" => "Gaming", - "slug" => "gaming", - "subcategories" => [ - %{ - "name" => "World of Warcraft", - "backgroundImageUrl" => nil - } - ], - "tags" => [ - %{ - "name" => "Chill Stream" - } - ] - } - } - } + "data" => %{ + "category" => %{ + "name" => "Gaming", + "slug" => "gaming", + "subcategories" => [ + %{ + "name" => "World of Warcraft", + "backgroundImageUrl" => nil + } + ], + "tags" => [ + %{ + "name" => "Chill Stream" + } + ] + } + } + } end end