diff --git a/elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb b/elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb index 72d4cf033..3d95d4cd7 100644 --- a/elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb +++ b/elasticgraph-warehouse/lib/elastic_graph/warehouse/schema_definition/factory_extension.rb @@ -28,9 +28,7 @@ module FactoryExtension def new_enum_type(name) super(name) do |type| type.extend EnumTypeExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end @@ -59,9 +57,7 @@ def new_index(name, settings, type, &block) def new_interface_type(name) super(name) do |type| type.extend ObjectInterfaceAndUnionExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end @@ -73,9 +69,7 @@ def new_interface_type(name) def new_object_type(name) super(name) do |type| type.extend ObjectInterfaceAndUnionExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end @@ -87,9 +81,7 @@ def new_object_type(name) def new_scalar_type(name) super(name) do |type| type.extend ScalarTypeExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end @@ -101,9 +93,7 @@ def new_scalar_type(name) def new_union_type(name) super(name) do |type| type.extend ObjectInterfaceAndUnionExtension - # :nocov: -- currently all invocations have a block yield type if block_given? - # :nocov: end end diff --git a/elasticgraph-warehouse/spec/unit/elastic_graph/warehouse/schema_definition/factory_extension_spec.rb b/elasticgraph-warehouse/spec/unit/elastic_graph/warehouse/schema_definition/factory_extension_spec.rb new file mode 100644 index 000000000..b0034ef39 --- /dev/null +++ b/elasticgraph-warehouse/spec/unit/elastic_graph/warehouse/schema_definition/factory_extension_spec.rb @@ -0,0 +1,66 @@ +# Copyright 2024 - 2026 Block, Inc. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. +# +# frozen_string_literal: true + +require "elastic_graph/spec_support/schema_definition_helpers" +require "elastic_graph/warehouse/schema_definition/api_extension" + +module ElasticGraph + module Warehouse + module SchemaDefinition + RSpec.describe FactoryExtension do + include_context "SchemaDefinitionHelpers" + + it "extends enum types created without customization blocks" do + api = build_api + api.enum_type "Status" + + expect(api.state.enum_types_by_name.fetch("Status")).to be_a(EnumTypeExtension) + end + + it "extends interface types created without customization blocks" do + api = build_api + api.interface_type "Identifiable" + + expect(api.state.object_types_by_name.fetch("Identifiable")).to be_a(ObjectInterfaceAndUnionExtension) + end + + it "extends object types created without customization blocks" do + api = build_api + api.object_type "Widget" + + expect(api.state.object_types_by_name.fetch("Widget")).to be_a(ObjectInterfaceAndUnionExtension) + end + + it "allows scalar type validation to fail normally without a customization block" do + api = build_api + + expect { + api.scalar_type "Money" + }.to raise_error(Errors::SchemaError, a_string_including("Scalar types require `mapping` to be configured")) + end + + it "extends union types created without customization blocks" do + api = build_api + api.union_type "SearchResult" + + expect(api.state.object_types_by_name.fetch("SearchResult")).to be_a(ObjectInterfaceAndUnionExtension) + end + + def build_api + schema_elements = SchemaArtifacts::RuntimeMetadata::SchemaElementNames.new(form: "snake_case") + ElasticGraph::SchemaDefinition::API.new( + schema_elements, + true, + extension_modules: [APIExtension], + output: log_device + ) + end + end + end + end +end