Skip to content

Commit 466aa66

Browse files
committed
Add some test cases
1 parent 9b1c7c0 commit 466aa66

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed
Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
11
require "spec_helper"
22

33
describe GraphQL::Execution::Typecast do
4+
let(:milk_value) { MILKS[1] }
5+
let(:cheese_value) { CHEESES[1] }
46

57
let(:schema) { DummySchema }
68
let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: nil) }
79

10+
def compatible?(*args)
11+
GraphQL::Execution::Typecast.compatible?(*args)
12+
end
813
it "resolves correctly when both types are the same" do
9-
assert GraphQL::Execution::Typecast.compatible?(MILKS[1], MilkType, MilkType, context)
14+
assert compatible?(milk_value, MilkType, MilkType, context)
15+
assert !compatible?(milk_value, MilkType, CheeseType, context)
1016
end
1117

12-
it "resolves correcty when current type is UnionType and value resolves to potential type" do
13-
assert GraphQL::Execution::Typecast.compatible?(MILKS[1], DairyProductUnion, MilkType, context)
18+
it "resolves a union type to a matching member" do
19+
assert compatible?(milk_value, DairyProductUnion, MilkType, context)
20+
assert compatible?(cheese_value, DairyProductUnion, CheeseType, context)
21+
22+
assert !compatible?(cheese_value, DairyProductUnion, MilkType, context)
23+
assert !compatible?(nil, DairyProductUnion, MilkType, context)
1424
end
1525

1626
it "resolves correcty when potential type is UnionType and current type is a member of that union" do
17-
assert GraphQL::Execution::Typecast.compatible?(MILKS[1], MilkType, DairyProductUnion, context)
18-
end
27+
assert compatible?(milk_value, MilkType, DairyProductUnion, context)
28+
assert compatible?(cheese_value, CheeseType, DairyProductUnion, context)
1929

20-
it "resolve correctly when current type is an Interface and it resolves to potential type" do
21-
assert GraphQL::Execution::Typecast.compatible?(MILKS[1], CheeseType, EdibleInterface, context)
30+
# assert !compatible?(nil, CheeseType, DairyProductUnion, context)
31+
# assert !compatible?(cheese_value, MilkType, DairyProductUnion, context)
2232
end
2333

24-
it "resolve correctly when potential type is an Interface and current type implements it" do
25-
assert GraphQL::Execution::Typecast.compatible?(CHEESES[1], EdibleInterface, CheeseType, context)
26-
end
34+
it "resolves an object type to one of its interfaces" do
35+
assert compatible?(cheese_value, CheeseType, EdibleInterface, context)
36+
assert compatible?(milk_value, MilkType, EdibleInterface, context)
2737

28-
it "resolve correctly when potential type is an Interface and current type implements it" do
29-
assert GraphQL::Execution::Typecast.compatible?(MILKS[1], EdibleInterface, CheeseType, context)
38+
# assert !compatible?(nil, MilkType, EdibleInterface, context)
39+
# assert !compatible?(milk_value, CheeseType, EdibleInterface, context)
3040
end
3141

42+
it "resolves an interface to a matching member" do
43+
assert compatible?(cheese_value, EdibleInterface, CheeseType, context)
44+
assert compatible?(milk_value, EdibleInterface, MilkType, context)
45+
46+
assert !compatible?(nil, EdibleInterface, MilkType, context)
47+
assert !compatible?(cheese_value, EdibleInterface, MilkType, context)
48+
end
3249
end

0 commit comments

Comments
 (0)