Skip to content

Commit cde9378

Browse files
authored
Followups from #1176: improve tests a bit. (#1183)
- Refocus a mapping test at the indices named in the mappings instead of just the `widgets` index mapping. - Rename `namespace_spec.rb` -> `namespace_type_spec.rb` for consistency. - Verify `widget_derived_types` has multiple entries as expected.
1 parent 8832246 commit cde9378

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/datastore_config/index_definition_spec_support.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,30 @@ module SchemaDefinition
1313
::RSpec.shared_context "IndexDefinitionSpecSupport" do
1414
include_context "SchemaDefinitionHelpers"
1515

16-
def index_configs_for(*index_names, index_document_sizes: false, schema_element_name_form: "snake_case", &schema_definition)
17-
config = define_schema(
16+
def build_datastore_config(index_document_sizes: false, schema_element_name_form: "snake_case", &schema_definition)
17+
define_schema(
1818
index_document_sizes: index_document_sizes,
1919
schema_element_name_form: schema_element_name_form,
2020
&schema_definition
2121
).datastore_config
22+
end
23+
24+
def index_configs_for(*index_names, index_document_sizes: false, schema_element_name_form: "snake_case", &schema_definition)
25+
config = build_datastore_config(
26+
index_document_sizes: index_document_sizes,
27+
schema_element_name_form: schema_element_name_form,
28+
&schema_definition
29+
)
2230

2331
index_names.map { |i| config.fetch("indices").fetch(i) }
2432
end
2533

2634
def index_template_configs_for(*index_names, index_document_sizes: false, schema_element_name_form: "snake_case", &schema_definition)
27-
config = define_schema(
35+
config = build_datastore_config(
2836
index_document_sizes: index_document_sizes,
2937
schema_element_name_form: schema_element_name_form,
3038
&schema_definition
31-
).datastore_config
39+
)
3240

3341
index_names.map { |i| config.fetch("index_templates").fetch(i) }
3442
end

elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/datastore_config/index_mappings/namespace_type_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module SchemaDefinition
1414
include_context "IndexMappingsSpecSupport"
1515

1616
it "does not generate an index mapping for a namespace type since it has no backing data to index" do
17-
index_configs = index_configs_for "widgets" do |s|
17+
datastore_config = build_datastore_config do |s|
1818
s.object_type "Widget" do |t|
1919
t.field "id", "ID!"
2020
t.index "widgets"
@@ -23,9 +23,8 @@ module SchemaDefinition
2323
s.namespace_type "OlapQuery"
2424
end
2525

26-
# Only the `widgets` index mapping is generated (no namespace type mapping).
27-
widget_mapping = index_configs.first.fetch("mappings")
28-
expect(widget_mapping.dig("properties")).to include("id" => {"type" => "keyword"})
26+
expect(datastore_config.fetch("indices").keys).to contain_exactly("widgets")
27+
expect(datastore_config.fetch("index_templates").keys).to be_empty
2928
end
3029

3130
it "omits fields that reference a namespace type from the index mapping of an indexed type" do

elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/graphql_schema/namespace_spec.rb renamed to elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/graphql_schema/namespace_type_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ module SchemaDefinition
101101

102102
# But it doesn't appear on any derived type of `Widget`.
103103
widget_derived_types = types_defined_in(result).grep(/\AWidget/) - ["Widget"]
104+
expect(widget_derived_types.size).to be >= 5
105+
104106
widget_derived_types.each do |derived_type_name|
105107
derived_type_sdl = type_def_from(result, derived_type_name)
106108
expect(derived_type_sdl).not_to include("olap"),

0 commit comments

Comments
 (0)