Skip to content

Commit

Permalink
test(schema): add tests for enableNestedFields property
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul OGGERO committed Mar 21, 2024
1 parent e80ab72 commit f61ea28
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions test/models/schema_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ void main() {

setUp(() {
s1 = Schema(
'companies',
{
Field('company_name', type: Type.string),
Field('num_employees', type: Type.int32),
Field('country', type: Type.string, isFacetable: true),
},
defaultSortingField: Field('num_employees'),
documentCount: 0,
);
'companies',
{
Field('company_name', type: Type.string),
Field('num_employees', type: Type.int32),
Field('country', type: Type.string, isFacetable: true),
},
defaultSortingField: Field('num_employees'),
documentCount: 0,
enableNestedFields: true);
s2 = Schema.fromMap({
"name": "companies",
"fields": [
Expand All @@ -25,6 +25,7 @@ void main() {
],
"default_sorting_field": "num_employees",
"num_documents": 0,
"enable_nested_fields": true,
});
});

Expand Down Expand Up @@ -54,6 +55,10 @@ void main() {
expect(s2.defaultSortingField,
equals(Field('num_employees', type: Type.int32)));
});
test('has a enableNestedFields field', () {
expect(s1.enableNestedFields, equals(true));
expect(s2.enableNestedFields, equals(true));
});
test('has a toMap method', () {
final map = {
"name": "companies",
Expand All @@ -64,6 +69,7 @@ void main() {
],
"default_sorting_field": "num_employees",
"num_documents": 0,
"enable_nested_fields": true,
};

expect(s1.toMap(), equals(map));
Expand Down Expand Up @@ -151,6 +157,32 @@ void main() {
),
);
});
test("with null/empty enableNestedFields is successful", () {
var schema = Schema.fromMap({
"name": "companies",
"fields": [
{"name": "company_name", "type": "string"},
{"name": "num_employees", "type": "int32"},
{"name": "country", "type": "string", "facet": true}
],
"default_sorting_field": "",
"num_documents": 0,
});
expect(schema.name, equals('companies'));
expect(schema.enableNestedFields, isNull);

schema = Schema.fromMap({
"name": "companies",
"fields": [
{"name": "company_name", "type": "string"},
{"name": "num_employees", "type": "int32"},
{"name": "country", "type": "string", "facet": true}
],
"num_documents": 0,
});
expect(schema.name, equals('companies'));
expect(schema.enableNestedFields, isNull);
});
});

group('UpdateSchema', () {
Expand Down

0 comments on commit f61ea28

Please sign in to comment.