Skip to content

Commit 898d197

Browse files
committed
Address review feedback on JSON ingestion spec migration
- Trim the JSON-schema-versioning scenarios from the core `rake_tasks_spec` that are now covered by `schema_artifact_manager_extension_spec` in `elasticgraph-json_ingestion`, and remove the helpers that only those scenarios used. - Replace the core coverage those scenarios provided with focused unit specs: the `deleted_type`/`deleted_field`/`renamed_from` registration DSL, `FieldPath#fully_qualified_path_in_index`, and the test-support behavior when a schema sets its own JSON schema version. - Make `doc_comment` load-bearing in the wrapper equality specs by adding cases that differ only in `doc_comment`. - Assert on observable behavior instead of `singleton_class.ancestors` in the blockless-element extension spec. - Explain why `unresolved_type_ref` uses a stand-in.
1 parent 7a66830 commit 898d197

6 files changed

Lines changed: 135 additions & 519 deletions

File tree

elasticgraph-json_ingestion/spec/unit/elastic_graph/json_ingestion/schema_definition/indexing/wrappers_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ module Indexing
3232
json_schema_customizations: {maxLength: 10},
3333
doc_comment: reference.doc_comment
3434
)
35+
different_doc_reference = FieldReference.new(
36+
reference.__getobj__,
37+
json_schema_layers: reference.json_schema_layers,
38+
json_schema_customizations: reference.json_schema_customizations,
39+
doc_comment: "alternate docs"
40+
)
3541

3642
expect(reference).to eq(matching_reference)
3743
expect(reference.eql?(matching_reference)).to eq(true)
3844
expect(reference.hash).to eq(matching_reference.hash)
3945
expect(reference).not_to eq(different_reference)
46+
expect(reference).not_to eq(different_doc_reference)
4047
expect(reference == reference.__getobj__).to eq(true)
4148
end
4249

@@ -73,11 +80,18 @@ module Indexing
7380
json_schema_customizations: {maxLength: 10},
7481
doc_comment: field.doc_comment
7582
)
83+
different_doc_field = Field.new(
84+
field.__getobj__,
85+
json_schema_layers: field.json_schema_layers,
86+
json_schema_customizations: field.json_schema_customizations,
87+
doc_comment: "alternate docs"
88+
)
7689

7790
expect(field).to eq(matching_field)
7891
expect(field.eql?(matching_field)).to eq(true)
7992
expect(field.hash).to eq(matching_field.hash)
8093
expect(field).not_to eq(different_field)
94+
expect(field).not_to eq(different_doc_field)
8195
expect(field == field.__getobj__).to eq(true)
8296
end
8397

@@ -89,11 +103,16 @@ module Indexing
89103
different_object_field_type = FieldType::Object.new(object_field_type.__getobj__).tap do |field_type|
90104
field_type.json_schema_options = {type: "object"}
91105
end
106+
different_doc_object_field_type = FieldType::Object.new(object_field_type.__getobj__).tap do |field_type|
107+
field_type.json_schema_options = object_field_type.json_schema_options
108+
field_type.doc_comment = "alternate docs"
109+
end
92110

93111
expect(object_field_type).to eq(matching_object_field_type)
94112
expect(object_field_type.eql?(matching_object_field_type)).to eq(true)
95113
expect(object_field_type.hash).to eq(matching_object_field_type.hash)
96114
expect(object_field_type).not_to eq(different_object_field_type)
115+
expect(object_field_type).not_to eq(different_doc_object_field_type)
97116
expect(object_field_type == object_field_type.__getobj__).to eq(true)
98117
end
99118

@@ -120,6 +139,9 @@ def widget_type
120139
end.state.object_types_by_name.fetch("Widget")
121140
end
122141

142+
# A minimal stand-in for a `SchemaElements::TypeReference` that never resolves. References to
143+
# not-yet-defined types resolve to `nil` mid-definition; a stand-in lets us exercise that path
144+
# directly instead of relying on the timing of a partially-defined schema.
123145
def unresolved_type_ref
124146
Class.new do
125147
def fully_unwrapped

elasticgraph-json_ingestion/spec/unit/elastic_graph/json_ingestion/schema_definition/schema_elements/scalar_type_extension_spec.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,20 @@ module SchemaElements
3939
field_factory: api.factory.method(:new_field)
4040
)
4141

42-
expect(api.state.enum_types_by_name.fetch("EmptyEnum").singleton_class.ancestors).to include(EnumTypeExtension)
43-
expect(api.state.object_types_by_name.fetch("EmptyInterface").__getobj__.singleton_class.ancestors).to include(TypeWithSubfieldsExtension)
44-
expect(direct_type_with_subfields.singleton_class.ancestors).to include(TypeWithSubfieldsExtension)
42+
# An enum's derived GraphQL types are built from a derived scalar twin, which can only be
43+
# built if `EnumTypeExtension` configured the twin's `json_schema`; otherwise building it
44+
# raises a "lacks `json_schema`" error.
45+
expect {
46+
api.state.enum_types_by_name.fetch("EmptyEnum").derived_graphql_types
47+
}.not_to raise_error
48+
49+
# `json_schema` is only available on types extended with `TypeWithSubfieldsExtension`.
50+
interface_type = api.state.object_types_by_name.fetch("EmptyInterface")
51+
interface_type.json_schema minProperties: 1
52+
expect(interface_type.json_schema_options).to eq({minProperties: 1})
53+
54+
direct_type_with_subfields.json_schema minProperties: 2
55+
expect(direct_type_with_subfields.json_schema_options).to eq({minProperties: 2})
4556

4657
expect {
4758
build_api.scalar_type "BigInt"

0 commit comments

Comments
 (0)