Skip to content

Commit aba7756

Browse files
authored
Cover warehouse factory extension no-block paths (#1260)
## Summary - Remove coverage exclusions around optional-yield guards in the warehouse factory extension. - Add focused unit coverage for schema elements created without customization blocks. Keep the enum and union fixtures valid when CI validates generated schemas. ## Validation - `script/lint` - `script/type_check` - `VALIDATE_SCHEMA_ARTIFACTS=1 script/run_gem_specs elasticgraph-warehouse`
1 parent 5eeb3e6 commit aba7756

2 files changed

Lines changed: 66 additions & 10 deletions

File tree

‎elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ module FactoryExtension
2828
def new_enum_type(name)
2929
super(name) do |type|
3030
type.extend EnumTypeExtension
31-
# simplecov:disable -- currently all invocations have a block
3231
yield type if block_given?
33-
# simplecov:enable
3432
end
3533
end
3634

@@ -59,9 +57,7 @@ def new_index(name, settings, type, &block)
5957
def new_interface_type(name)
6058
super(name) do |type|
6159
type.extend ObjectInterfaceAndUnionExtension
62-
# simplecov:disable -- currently all invocations have a block
6360
yield type if block_given?
64-
# simplecov:enable
6561
end
6662
end
6763

@@ -73,9 +69,7 @@ def new_interface_type(name)
7369
def new_object_type(name)
7470
super(name) do |type|
7571
type.extend ObjectInterfaceAndUnionExtension
76-
# simplecov:disable -- currently all invocations have a block
7772
yield type if block_given?
78-
# simplecov:enable
7973
end
8074
end
8175

@@ -87,9 +81,7 @@ def new_object_type(name)
8781
def new_scalar_type(name)
8882
super(name) do |type|
8983
type.extend ScalarTypeExtension
90-
# simplecov:disable -- currently all invocations have a block
9184
yield type if block_given?
92-
# simplecov:enable
9385
end
9486
end
9587

@@ -101,9 +93,7 @@ def new_scalar_type(name)
10193
def new_union_type(name)
10294
super(name) do |type|
10395
type.extend ObjectInterfaceAndUnionExtension
104-
# simplecov:disable -- currently all invocations have a block
10596
yield type if block_given?
106-
# simplecov:enable
10797
end
10898
end
10999

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2024 - 2026 Block, Inc.
2+
#
3+
# Use of this source code is governed by an MIT-style
4+
# license that can be found in the LICENSE file or at
5+
# https://opensource.org/licenses/MIT.
6+
#
7+
# frozen_string_literal: true
8+
9+
require "elastic_graph/spec_support/schema_definition_helpers"
10+
require "elastic_graph/warehouse/schema_definition/api_extension"
11+
12+
module ElasticGraph
13+
module Warehouse
14+
module SchemaDefinition
15+
RSpec.describe FactoryExtension do
16+
include_context "SchemaDefinitionHelpers"
17+
18+
it "extends enum types created without customization blocks" do
19+
define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api|
20+
api.enum_type "Status"
21+
api.state.enum_types_by_name.fetch("Status").values "ACTIVE"
22+
23+
expect(api.state.enum_types_by_name.fetch("Status")).to be_a(EnumTypeExtension)
24+
end
25+
end
26+
27+
it "extends interface types created without customization blocks" do
28+
define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api|
29+
api.interface_type "Identifiable"
30+
31+
expect(api.state.object_types_by_name.fetch("Identifiable")).to be_a(ObjectInterfaceAndUnionExtension)
32+
end
33+
end
34+
35+
it "extends object types created without customization blocks" do
36+
define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api|
37+
api.object_type "Widget"
38+
39+
expect(api.state.object_types_by_name.fetch("Widget")).to be_a(ObjectInterfaceAndUnionExtension)
40+
end
41+
end
42+
43+
it "allows scalar type validation to fail normally without a customization block" do
44+
define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api|
45+
expect {
46+
api.scalar_type "Money"
47+
}.to raise_error(Errors::SchemaError, a_string_including("Scalar types require `mapping` to be configured"))
48+
end
49+
end
50+
51+
it "extends union types created without customization blocks" do
52+
define_schema(schema_element_name_form: "snake_case", extension_modules: [APIExtension]) do |api|
53+
api.object_type "Widget" do |type|
54+
type.field "id", "ID!"
55+
end
56+
57+
api.union_type "SearchResult"
58+
api.state.object_types_by_name.fetch("SearchResult").subtypes "Widget"
59+
60+
expect(api.state.object_types_by_name.fetch("SearchResult")).to be_a(ObjectInterfaceAndUnionExtension)
61+
end
62+
end
63+
end
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)