|
1 | 1 | require "spec_helper"
|
2 | 2 |
|
3 | 3 | describe GraphQL::Execution::Typecast do
|
| 4 | + let(:milk_value) { MILKS[1] } |
| 5 | + let(:cheese_value) { CHEESES[1] } |
4 | 6 |
|
5 | 7 | let(:schema) { DummySchema }
|
6 | 8 | let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: nil) }
|
7 | 9 |
|
| 10 | + def compatible?(*args) |
| 11 | + GraphQL::Execution::Typecast.compatible?(*args) |
| 12 | + end |
8 | 13 | 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) |
10 | 16 | end
|
11 | 17 |
|
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) |
14 | 24 | end
|
15 | 25 |
|
16 | 26 | 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) |
19 | 29 |
|
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) |
22 | 32 | end
|
23 | 33 |
|
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) |
27 | 37 |
|
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) |
30 | 40 | end
|
31 | 41 |
|
| 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 |
32 | 49 | end
|
0 commit comments