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

refactor(spec) put test schemas in namespaces #487

Merged
merged 1 commit into from
Jan 16, 2017
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
30 changes: 15 additions & 15 deletions spec/graphql/analysis/analyze_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def call(memo, visit_type, irep_node)
let(:analyzers) { [type_collector, node_counter] }
let(:reduce_result) { GraphQL::Analysis.analyze_query(query, analyzers) }
let(:variables) { {} }
let(:query) { GraphQL::Query.new(DummySchema, query_string, variables: variables) }
let(:query) { GraphQL::Query.new(Dummy::Schema, query_string, variables: variables) }
let(:query_string) {%|
{
cheese(id: 1) {
Expand All @@ -40,7 +40,7 @@ def call(memo, visit_type, irep_node)

it "calls the defined analyzers" do
collected_types, node_counts = reduce_result
expected_visited_types = [DairyAppQueryType, CheeseType, GraphQL::INT_TYPE, GraphQL::STRING_TYPE]
expected_visited_types = [Dummy::DairyAppQueryType, Dummy::CheeseType, GraphQL::INT_TYPE, GraphQL::STRING_TYPE]
assert_equal expected_visited_types, collected_types
expected_node_counts = {
GraphQL::Language::Nodes::OperationDefinition => 1,
Expand All @@ -61,14 +61,14 @@ def call(memo, visit_type, irep_node)
let(:variable_accessor) { ->(memo, visit_type, irep_node) { query.variables["cheeseId"] } }

before do
@previous_query_analyzers = DummySchema.query_analyzers.dup
DummySchema.query_analyzers.clear
DummySchema.query_analyzers << variable_accessor
@previous_query_analyzers = Dummy::Schema.query_analyzers.dup
Dummy::Schema.query_analyzers.clear
Dummy::Schema.query_analyzers << variable_accessor
end

after do
DummySchema.query_analyzers.clear
DummySchema.query_analyzers.push(*@previous_query_analyzers)
Dummy::Schema.query_analyzers.clear
Dummy::Schema.query_analyzers.push(*@previous_query_analyzers)
end

it "returns an error" do
Expand Down Expand Up @@ -97,7 +97,7 @@ def call(memo, visit_type, irep_node)
}
let(:analyzers) { [connection_counter] }
let(:reduce_result) { GraphQL::Analysis.analyze_query(query, analyzers) }
let(:query) { GraphQL::Query.new(StarWarsSchema, query_string, variables: variables) }
let(:query) { GraphQL::Query.new(StarWars::Schema, query_string, variables: variables) }
let(:query_string) {%|
query getBases {
empire {
Expand Down Expand Up @@ -155,7 +155,7 @@ def final_value(memo)
let(:flavor_catcher) { FlavorCatcher.new }
let(:analyzers) { [id_catcher, flavor_catcher] }
let(:reduce_result) { GraphQL::Analysis.analyze_query(query, analyzers) }
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
let(:query) { GraphQL::Query.new(Dummy::Schema, query_string) }
let(:query_string) {%|
{
cheese(id: 1) {
Expand All @@ -164,7 +164,7 @@ def final_value(memo)
}
}
|}
let(:schema) { DummySchema }
let(:schema) { Dummy::Schema }
let(:result) { schema.execute(query_string) }
let(:query_string) {%|
{
Expand All @@ -176,14 +176,14 @@ def final_value(memo)
|}

before do
@previous_query_analyzers = DummySchema.query_analyzers.dup
DummySchema.query_analyzers.clear
DummySchema.query_analyzers << id_catcher << flavor_catcher
@previous_query_analyzers = Dummy::Schema.query_analyzers.dup
Dummy::Schema.query_analyzers.clear
Dummy::Schema.query_analyzers << id_catcher << flavor_catcher
end

after do
DummySchema.query_analyzers.clear
DummySchema.query_analyzers.push(*@previous_query_analyzers)
Dummy::Schema.query_analyzers.clear
Dummy::Schema.query_analyzers.push(*@previous_query_analyzers)
end

it "groups all errors together" do
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/analysis/field_usage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:result) { [] }
let(:field_usage_analyzer) { GraphQL::Analysis::FieldUsage.new { |query, used_fields, used_deprecated_fields| result << query << used_fields << used_deprecated_fields } }
let(:reduce_result) { GraphQL::Analysis.analyze_query(query, [field_usage_analyzer]) }
let(:query) { GraphQL::Query.new(DummySchema, query_string, variables: variables) }
let(:query) { GraphQL::Query.new(Dummy::Schema, query_string, variables: variables) }
let(:variables) { {} }

describe "query with deprecated fields" do
Expand Down
16 changes: 8 additions & 8 deletions spec/graphql/analysis/max_query_complexity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

describe GraphQL::Analysis::MaxQueryComplexity do
before do
@prev_max_complexity = DummySchema.max_complexity
@prev_max_complexity = Dummy::Schema.max_complexity
end

after do
DummySchema.max_complexity = @prev_max_complexity
Dummy::Schema.max_complexity = @prev_max_complexity
end


let(:result) { DummySchema.execute(query_string) }
let(:result) { Dummy::Schema.execute(query_string) }
let(:query_string) {%|
{
a: cheese(id: 1) { id }
Expand All @@ -24,7 +24,7 @@

describe "when a query goes over max complexity" do
before do
DummySchema.max_complexity = 9
Dummy::Schema.max_complexity = 9
end

it "returns an error" do
Expand All @@ -34,7 +34,7 @@

describe "when there is no max complexity" do
before do
DummySchema.max_complexity = nil
Dummy::Schema.max_complexity = nil
end
it "doesn't error" do
assert_equal nil, result["errors"]
Expand All @@ -43,7 +43,7 @@

describe "when the query is less than the max complexity" do
before do
DummySchema.max_complexity = 99
Dummy::Schema.max_complexity = 99
end
it "doesn't error" do
assert_equal nil, result["errors"]
Expand All @@ -52,9 +52,9 @@

describe "when complexity is overriden at query-level" do
before do
DummySchema.max_complexity = 100
Dummy::Schema.max_complexity = 100
end
let(:result) { DummySchema.execute(query_string, max_complexity: 7) }
let(:result) { Dummy::Schema.execute(query_string, max_complexity: 7) }

it "is applied" do
assert_equal "Query has complexity of 10, which exceeds max complexity of 7", result["errors"][0]["message"]
Expand Down
14 changes: 7 additions & 7 deletions spec/graphql/analysis/max_query_depth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

describe GraphQL::Analysis::MaxQueryDepth do
before do
@prev_max_depth = DummySchema.max_depth
@prev_max_depth = Dummy::Schema.max_depth
end

after do
DummySchema.max_depth = @prev_max_depth
Dummy::Schema.max_depth = @prev_max_depth
end

let(:result) { DummySchema.execute(query_string) }
let(:result) { Dummy::Schema.execute(query_string) }
let(:query_string) { "
{
cheese(id: 1) {
Expand All @@ -36,7 +36,7 @@
end

describe "when the query specifies a different max_depth" do
let(:result) { DummySchema.execute(query_string, max_depth: 100) }
let(:result) { Dummy::Schema.execute(query_string, max_depth: 100) }

it "obeys that max_depth" do
assert_equal nil, result["errors"]
Expand All @@ -45,7 +45,7 @@

describe "When the query is not deeper than max_depth" do
before do
DummySchema.max_depth = 100
Dummy::Schema.max_depth = 100
end

it "doesn't add an error" do
Expand All @@ -55,7 +55,7 @@

describe "when the max depth isn't set" do
before do
DummySchema.max_depth = nil
Dummy::Schema.max_depth = nil
end

it "doesn't add an error message" do
Expand All @@ -65,7 +65,7 @@

describe "when a fragment exceeds max depth" do
before do
DummySchema.max_depth = 4
Dummy::Schema.max_depth = 4
end

let(:query_string) { "
Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/analysis/query_complexity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:query_complexity) { GraphQL::Analysis::QueryComplexity.new { |this_query, complexity| complexities << this_query << complexity } }
let(:reduce_result) { GraphQL::Analysis.analyze_query(query, [query_complexity]) }
let(:variables) { {} }
let(:query) { GraphQL::Query.new(DummySchema, query_string, variables: variables) }
let(:query) { GraphQL::Query.new(Dummy::Schema, query_string, variables: variables) }

describe "simple queries" do
let(:query_string) {%|
Expand Down Expand Up @@ -189,7 +189,7 @@
end

describe "relay types" do
let(:query) { GraphQL::Query.new(StarWarsSchema, query_string) }
let(:query) { GraphQL::Query.new(StarWars::Schema, query_string) }
let(:query_string) {%|
{
rebels {
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/analysis/query_depth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:depths) { [] }
let(:query_depth) { GraphQL::Analysis::QueryDepth.new { |query, max_depth| depths << query << max_depth } }
let(:reduce_result) { GraphQL::Analysis.analyze_query(query, [query_depth]) }
let(:query) { GraphQL::Query.new(DummySchema, query_string, variables: variables) }
let(:query) { GraphQL::Query.new(Dummy::Schema, query_string, variables: variables) }
let(:variables) { {} }

describe "simple queries" do
Expand Down
30 changes: 19 additions & 11 deletions spec/graphql/base_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,39 @@
end

it "can be compared" do
obj_type = Dummy::MilkType
assert_equal(!GraphQL::INT_TYPE, !GraphQL::INT_TYPE)
refute_equal(!GraphQL::FLOAT_TYPE, GraphQL::FLOAT_TYPE)
assert_equal(
GraphQL::ListType.new(of_type: MilkType),
GraphQL::ListType.new(of_type: MilkType)
GraphQL::ListType.new(of_type: obj_type),
GraphQL::ListType.new(of_type: obj_type)
)
refute_equal(
GraphQL::ListType.new(of_type: MilkType),
GraphQL::ListType.new(of_type: !MilkType)
GraphQL::ListType.new(of_type: obj_type),
GraphQL::ListType.new(of_type: !obj_type)
)
end

it "Accepts arbitrary metadata" do
assert_equal ["Cheese"], CheeseType.metadata[:class_names]
assert_equal ["Cheese"], Dummy::CheeseType.metadata[:class_names]
end

describe "#dup" do
let(:obj_type) {
GraphQL::ObjectType.define do
name "SomeObject"
field :id, types.Int
end
}

it "resets connection types" do
# Make sure the defaults have been calculated
cheese_edge = CheeseType.edge_type
cheese_conn = CheeseType.connection_type
cheese_2 = CheeseType.dup
cheese_2.name = "Cheese2"
refute_equal cheese_edge, cheese_2.edge_type
refute_equal cheese_conn, cheese_2.connection_type
obj_edge = obj_type.edge_type
obj_conn = obj_type.connection_type
obj_2 = obj_type.dup
obj_2.name = "Cheese2"
refute_equal obj_edge, obj_2.edge_type
refute_equal obj_edge, obj_2.connection_type
end
end
end
2 changes: 1 addition & 1 deletion spec/graphql/directive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe GraphQL::Directive do
let(:variables) { {"t" => true, "f" => false} }
let(:result) { DummySchema.execute(query_string, variables: variables) }
let(:result) { Dummy::Schema.execute(query_string, variables: variables) }
describe "on fields" do
let(:query_string) { %|query directives($t: Boolean!, $f: Boolean!) {
cheese(id: 1) {
Expand Down
4 changes: 2 additions & 2 deletions spec/graphql/enum_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "spec_helper"

describe GraphQL::EnumType do
let(:enum) { DairyAnimalEnum }
let(:enum) { Dummy::DairyAnimalEnum }

it "coerces names to underlying values" do
assert_equal("YAK", enum.coerce_input("YAK"))
Expand Down Expand Up @@ -72,7 +72,7 @@
end

describe "validate_input with bad input" do
let(:result) { DairyAnimalEnum.validate_input("bad enum", PermissiveWarden) }
let(:result) { enum.validate_input("bad enum", PermissiveWarden) }

it "returns an invalid result" do
assert(!result.valid?)
Expand Down
38 changes: 19 additions & 19 deletions spec/graphql/execution/typecast_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,48 @@
let(:milk_value) { MILKS[1] }
let(:cheese_value) { CHEESES[1] }

let(:schema) { DummySchema }
let(:schema) { Dummy::Schema }
let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: nil) }

def compatible?(*args)
GraphQL::Execution::Typecast.compatible?(*args)
end

it "resolves correctly when both types are the same" do
assert compatible?(MilkType, MilkType, context)
assert compatible?(Dummy::MilkType, Dummy::MilkType, context)

assert !compatible?(MilkType, CheeseType, context)
assert !compatible?(Dummy::MilkType, Dummy::CheeseType, context)
end

it "resolves a union type to a matching member" do
assert compatible?(DairyProductUnion, MilkType, context)
assert compatible?(DairyProductUnion, CheeseType, context)
assert compatible?(Dummy::DairyProductUnion, Dummy::MilkType, context)
assert compatible?(Dummy::DairyProductUnion, Dummy::CheeseType, context)

assert !compatible?(DairyProductUnion, GraphQL::INT_TYPE, context)
assert !compatible?(DairyProductUnion, HoneyType, context)
assert !compatible?(Dummy::DairyProductUnion, GraphQL::INT_TYPE, context)
assert !compatible?(Dummy::DairyProductUnion, Dummy::HoneyType, context)
end

it "resolves correcty when potential type is UnionType and current type is a member of that union" do
assert compatible?(MilkType, DairyProductUnion, context)
assert compatible?(CheeseType, DairyProductUnion, context)
assert compatible?(Dummy::MilkType, Dummy::DairyProductUnion, context)
assert compatible?(Dummy::CheeseType, Dummy::DairyProductUnion, context)

assert !compatible?(QueryType, DairyProductUnion, context)
assert !compatible?(EdibleInterface, DairyProductUnion, context)
assert !compatible?(Dummy::DairyAppQueryType, Dummy::DairyProductUnion, context)
assert !compatible?(Dummy::EdibleInterface, Dummy::DairyProductUnion, context)
end

it "resolves an object type to one of its interfaces" do
assert compatible?(CheeseType, EdibleInterface, context)
assert compatible?(MilkType, EdibleInterface, context)
assert compatible?(Dummy::CheeseType, Dummy::EdibleInterface, context)
assert compatible?(Dummy::MilkType, Dummy::EdibleInterface, context)

assert !compatible?(QueryType, EdibleInterface, context)
assert !compatible?(LocalProductInterface, EdibleInterface, context)
assert !compatible?(Dummy::DairyAppQueryType, Dummy::EdibleInterface, context)
assert !compatible?(Dummy::LocalProductInterface, Dummy::EdibleInterface, context)
end

it "resolves an interface to a matching member" do
assert compatible?(EdibleInterface, CheeseType, context)
assert compatible?(EdibleInterface, MilkType, context)
assert compatible?(Dummy::EdibleInterface, Dummy::CheeseType, context)
assert compatible?(Dummy::EdibleInterface, Dummy::MilkType, context)

assert !compatible?(EdibleInterface, GraphQL::STRING_TYPE, context)
assert !compatible?(EdibleInterface, DairyProductInputType, context)
assert !compatible?(Dummy::EdibleInterface, GraphQL::STRING_TYPE, context)
assert !compatible?(Dummy::EdibleInterface, Dummy::DairyProductInputType, context)
end
end
2 changes: 1 addition & 1 deletion spec/graphql/execution_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "spec_helper"

describe GraphQL::ExecutionError do
let(:result) { DummySchema.execute(query_string) }
let(:result) { Dummy::Schema.execute(query_string) }
describe "when returned from a field" do
let(:query_string) {%|
{
Expand Down
Loading