Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add member, [color, movie, series].members #563

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/graphql/types/color_type.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module Types
class ColorType < Types::BaseObject
field :color, String, null: false
field :girls, [Types::GirlType], null: true
field :girls, [Types::MemberType], null: true, deprecation_reason: "Cure Wing is a boy."
field :members, [Types::MemberType], null: true
def color
object.to_s
end
def girls
Precure.all_girls.select{|girl| girl.send(object.to_s + '?')}
end
def members
Precure.all_members.select{|member| member.send(object.to_s + '?')}
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Types
class GirlType < Types::BaseObject
field :girl_name, String, null: false, description: "Precure's symbol name"
class MemberType < Types::BaseObject
field :girl_name, String, null: false, description: "Precure's symbol name", deprecation_reason: "Cure Wing is a boy."
field :member_name, String, null: false, description: "Precure's symbol name"
field :human_name, String, null: false, description: "Precure's name before transformation"
field :human_full_name, String, null: true, description: "Precure's canonical name before transformation"
field :human_turnover_name, String, null: true, description: "Precure's turnovered name"
Expand All @@ -16,7 +17,7 @@ class GirlType < Types::BaseObject
field :transform_calls, [String], null: true, description: "Precure's transformation call"
field :full_name, String, null: false, description: "Precure's name before transformation(full name or human name)"
field :transform_styles, [String], null: true, description: "Transform styles(if present)"
field :pikarin_janken, String, null: true, description: "Pikarin janken(if girl is CurePeace)"
field :pikarin_janken, String, null: true, description: "Pikarin janken(if member is CurePeace)"
field :heisei, String, null: true, description: "Precure's first appearance is in Heisei era"
field :reiwa, String, null: true, description: "Precure's first appearance is in Reiwa era"
field :random_transform_words, [String], null: true, description: "Precure's random transform messages(if present)"
Expand All @@ -25,6 +26,10 @@ def girl_name
object.girl_name
end

def member_name
object.girl_name
end

def human_name
object.human_name
end
Expand Down
9 changes: 7 additions & 2 deletions app/graphql/types/movie_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ class MovieType < Types::BaseObject
field :title, String, null: false, description: "Movie's title"
field :started_date, String, null: false, description: "Movie's opening day"
field :name, String, null: false, description: "Movie's symbol"
field :girls, [Types::GirlType], null: false, description: "Girls apper in the movie"
field :girls, [Types::MemberType], null: false, description: "Girls apper in the movie", deprecation_reason: "Cure Wing is a boy."
field :members, [Types::MemberType], null: false, description: "Members apper in the movie"

def name
Rubicure::Movie.config.key(object)
end
def girls

def members
return Precure.dream_stars if (name == :dream_stars)
return Precure.super_stars if (name == :super_stars)
return Precure.miracle_universe if (name == :miracle_universe)
return Precure.miracle_leap if (name == :miracle_leap)
Precure.all_stars(Rubicure::Movie.config.key(object))
end

alias_method :girls, :members
end
end
27 changes: 17 additions & 10 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ class QueryType < Types::BaseObject
# Add root-level fields here.
# They will be entry points for queries on your schema.

field :girl, Types::GirlType, null: false, description: "Get a Precure" do
field :girl, Types::MemberType, null: false, description: "Get a Precure", deprecation_reason: "Cure Wing is a boy." do
argument :girl_name, String, required: true, description: "Precure's symbol"
end
def girl(girl_name:)
Rubicure::Girl.find(girl_name.intern)
end

field :member, Types::MemberType, null: false, description: "Get a Precure" do
argument :member_name, String, required: true, description: "Precure's symbol"
end
def member(member_name:)
Rubicure::Girl.find(member_name.intern)
end

field :movie, Types::MovieType, null: false, description: "Get information about a movie" do
argument :movie_name, String, required: true, description: "Movie's symbol"
end
Expand All @@ -33,7 +40,7 @@ def self.define_cure(name)
end

Precure.all_girls.map(&:girl_name).each do |girl|
field girl.intern, Types::GirlType, null: false
field girl.intern, Types::MemberType, null: false
# define method dynamically
define_cure girl.intern
end
Expand All @@ -45,35 +52,35 @@ def series(series_name:)
Precure.send(series_name)
end

field :precure_all_stars, [Types::GirlType], null: false, description: "Get Precure All Stars" do
field :precure_all_stars, [Types::MemberType], null: false, description: "Get Precure All Stars" do
argument :series, String, required: false, description: "Prescribe which series from Precure All Stars(if absent, prescribes 'Futari wa Pretty Cure' to 'Maho Girls Precure')"
end
def precure_all_stars(series:)
return Precure.all_stars(series.intern) if series.present?
Precure.all_stars
end

field :precure_dream_stars, [Types::GirlType], null: false, description: "Get Precure seen in 'Precure Dream Stars'"
field :precure_dream_stars, [Types::MemberType], null: false, description: "Get Precure seen in 'Precure Dream Stars'"
def precure_dream_stars
Precure.dream_stars
end

field :precure_super_stars, [Types::GirlType], null: false, description: "Get Precure seen in 'Precure Super Stars'"
field :precure_super_stars, [Types::MemberType], null: false, description: "Get Precure seen in 'Precure Super Stars'"
def precure_super_stars
Precure.super_stars
end

field :precure_miracle_leap, [Types::GirlType], null: false, description: "Get Precure seen in 'Precure Miracle Leap'"
field :precure_miracle_leap, [Types::MemberType], null: false, description: "Get Precure seen in 'Precure Miracle Leap'"
def precure_miracle_leap
Precure.miracle_leap
end

field :precure_all_girls, [Types::GirlType], null: false, description: "Get all Precure"
field :precure_all_girls, [Types::MemberType], null: false, description: "Get all Precure", deprecation_reason: "Cure Wing is a boy."
def precure_all_girls
precure_all
end

field :precure_all, [Types::GirlType], null: false, description: "Get all Precure"
field :precure_all, [Types::MemberType], null: false, description: "Get all Precure"
def precure_all
Precure.all
end
Expand All @@ -83,12 +90,12 @@ def all_series
Precure
end

field :colors, [Types::ColorType], null: false, description: "Get colors and girls"
field :colors, [Types::ColorType], null: false, description: "Get colors and members"
def colors
Rubicure::Girl.colors
end

field :color, Types::ColorType, null: false, description: "Get color and girls specified color" do
field :color, Types::ColorType, null: false, description: "Get color and members specified color" do
argument :color, String, required: true, description: "Specified color"
end
def color(color:)
Expand Down
14 changes: 12 additions & 2 deletions app/graphql/types/series_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ class SeriesType < Types::BaseObject
field :title, String, null: false
field :started_date, String, null: true
field :ended_date, String, null: true
field :girls, [Types::GirlType], null: true
field :girls_count, Integer, null: false
field :girls, [Types::MemberType], null: true, deprecation_reason: "Cure Wing is a boy."
field :girls_count, Integer, null: false, deprecation_reason: "Cure Wing is a boy."
field :members, [Types::MemberType], null: true
field :members_count, Integer, null: false
field :heisei, String, null: true
field :reiwa, String, null: true

Expand All @@ -17,6 +19,14 @@ def girls_count
object.girls.count
end

def members
object.members
end

def members_count
object.members.count
end

def heisei
object.heisei?
end
Expand Down
9 changes: 9 additions & 0 deletions spec/graphql/types/color_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
girls {
girlName
}
members
{
memberName
}
}
}
QUERYSTRING
Expand All @@ -43,5 +47,10 @@
it { expect(result["data"]["color"]["girls"].count).to eq Precure.all_girls.select(&:pink?).count }
it { expect(result["data"]["color"]["girls"].map{|e| e["girlName"]}).to eq Precure.all_girls.select(&:pink?).map(&:girl_name) }
end

context "has members and it" do
it { expect(result["data"]["color"]["members"].count).to eq Precure.all_members.select(&:pink?).count }
it { expect(result["data"]["color"]["members"].map{|e| e["memberName"]}).to eq Precure.all_members.select(&:pink?).map(&:girl_name) }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe Types::GirlType do
RSpec.describe Types::MemberType do
let(:context) { {} }
let(:variables) { {} }

Expand Down Expand Up @@ -384,4 +384,42 @@
it { expect(result["data"]["cureLamer"]["transformMessages"].map{|e| e["transformMessage"].include?("${random_transform_word}")}).to eq [false] }
end
end

describe "cureWing" do
let(:query_string) do
<<QUERYSTRING
query {
cureWing
{
memberName
}
}
QUERYSTRING
end

context "has memberName and it" do
it { expect(result["data"]["cureWing"]["memberName"]).to eq Cure.wing.girl_name }
end
end

describe "member(memberName: \"wing\") between cureWing" do
let(:query_string) do
<<QUERYSTRING
query {
member(memberName: "wing")
{
memberName
}
cureWing
{
memberName
}
}
QUERYSTRING
end

context "are" do
it { expect(result["data"]["member"]).to eq result["data"]["cureWing"] }
end
end
end
27 changes: 27 additions & 0 deletions spec/graphql/types/movie_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
{
girlName
}
members
{
memberName
}
}
}
QUERYSTRING
Expand All @@ -52,6 +56,11 @@
it { expect(result["data"]["movie"]["girls"].count).to eq Precure.all_stars(:stmm).count }
it { expect(result["data"]["movie"]["girls"].map{|e| e["girlName"]}).to eq Precure.all_stars(:stmm).map(&:girl_name) }
end

context "has members and it" do
it { expect(result["data"]["movie"]["members"].count).to eq Precure.all_stars(:stmm).count }
it { expect(result["data"]["movie"]["members"].map{|e| e["memberName"]}).to eq Precure.all_stars(:stmm).map(&:girl_name) }
end
end

describe "miracle_universe" do
Expand All @@ -67,6 +76,10 @@
{
girlName
}
members
{
memberName
}
}
}
QUERYSTRING
Expand All @@ -88,6 +101,11 @@
it { expect(result["data"]["movie"]["girls"].count).to eq Precure.miracle_universe.count }
it { expect(result["data"]["movie"]["girls"].map{|e| e["girlName"]}).to eq Precure.miracle_universe.map(&:girl_name) }
end

context "has members and it" do
it { expect(result["data"]["movie"]["members"].count).to eq Precure.miracle_universe.count }
it { expect(result["data"]["movie"]["members"].map{|e| e["memberName"]}).to eq Precure.miracle_universe.map(&:girl_name) }
end
end

describe "miracle_leap" do
Expand All @@ -103,6 +121,10 @@
{
girlName
}
members
{
memberName
}
}
}
QUERYSTRING
Expand All @@ -124,5 +146,10 @@
it { expect(result["data"]["movie"]["girls"].count).to eq Precure.miracle_leap.count }
it { expect(result["data"]["movie"]["girls"].map{|e| e["girlName"]}).to eq Precure.miracle_leap.map(&:girl_name) }
end

context "has members and it" do
it { expect(result["data"]["movie"]["members"].count).to eq Precure.miracle_leap.count }
it { expect(result["data"]["movie"]["members"].map{|e| e["memberName"]}).to eq Precure.miracle_leap.map(&:girl_name) }
end
end
end
13 changes: 13 additions & 0 deletions spec/graphql/types/series_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
{
girlName
}
membersCount
members
{
memberName
}
heisei
reiwa
}
Expand Down Expand Up @@ -63,6 +68,14 @@
it { expect(result["data"]["series"]["girls"].map{|e| e["girlName"]}).to eq Precure.maho_girls.girls.map(&:girl_name) }
end

context "has membersCount and it" do
it { expect(result["data"]["series"]["membersCount"]).to eq Precure.maho_girls.members.count }
end

context "has members and it" do
it { expect(result["data"]["series"]["members"].map{|e| e["memberName"]}).to eq Precure.maho_girls.members.map(&:girl_name) }
end

context "has heisei and it" do
it { expect(result["data"]["series"]["heisei"]).to eq Precure.maho_girls.heisei?.to_s }
end
Expand Down