From da3e088b68c0ccaa52c842472c1e56fcf08000b3 Mon Sep 17 00:00:00 2001 From: Fellmonkey <90258055+Fellmonkey@users.noreply.github.com> Date: Wed, 5 Nov 2025 00:30:35 +0300 Subject: [PATCH 1/4] Handle enum string properties in test data generation Updates Dart test template to use the first enum value for string properties with enums when generating test data, instead of always using the example value. This ensures generated test data is valid for properties with restricted enum values. --- templates/dart/test/services/service_test.dart.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/dart/test/services/service_test.dart.twig b/templates/dart/test/services/service_test.dart.twig index c61fe4a4d0..32f3c09c03 100644 --- a/templates/dart/test/services/service_test.dart.twig +++ b/templates/dart/test/services/service_test.dart.twig @@ -1,6 +1,6 @@ {% macro sub_schema(definitions, property) %}{% if property.sub_schema %}{% if property.type == 'array' %}List<>{% else %}{ {% if definitions[property.sub_schema] %}{% for property in definitions[property.sub_schema].properties | filter(p => p.required) %} - '{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}{% if property.sub_schema and (property.sub_schema != 'prefs' and property.sub_schema != 'preferences') %}{{_self.sub_schema(spec.definitions, property)}}{% else %}{}{% endif %}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{property.example | escapeDollarSign}}'{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %}, + '{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}{% if property.sub_schema and (property.sub_schema != 'prefs' and property.sub_schema != 'preferences') %}{{_self.sub_schema(spec.definitions, property)}}{% else %}{}{% endif %}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}{% if property.enum %}'{{property.enum[0]}}'{% else %}'{{property.example | escapeDollarSign}}'{% endif %}{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %}, {% endfor %}{% endif %}}{% endif %}{% else %}{% if property.type == 'object' and property.additionalProperties %}Map{% else %}{{property | typeName}}{% endif %}{% endif %}{% endmacro %} {% import 'flutter/base/utils.twig' as utils %} {% if 'dart' in language.params.packageName %} @@ -69,7 +69,7 @@ void main() { {%~ if method.responseModel and method.responseModel != 'any' ~%} final Map data = { {%- for definition in spec.definitions ~%}{%~ if definition.name == method.responseModel -%}{%~ for property in definition.properties | filter((param) => param.required) ~%} - '{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}{% if property.sub_schema and (property.sub_schema != 'prefs' and property.sub_schema != 'preferences') %}{{_self.sub_schema(spec.definitions, property)}}{% else %}{}{% endif %}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{property.example | escapeDollarSign}}'{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%} + '{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}{% if property.sub_schema and (property.sub_schema != 'prefs' and property.sub_schema != 'preferences') %}{{_self.sub_schema(spec.definitions, property)}}{% else %}{}{% endif %}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}{% if property.enum %}'{{property.enum[0]}}'{% else %}'{{property.example | escapeDollarSign}}'{% endif %}{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%} }; {%~ else ~%} From e1193b77f1ee69d1a520bb3c920e962f64b98414 Mon Sep 17 00:00:00 2001 From: Fellmonkey <90258055+Fellmonkey@users.noreply.github.com> Date: Sun, 18 Jan 2026 16:22:11 +0300 Subject: [PATCH 2/4] Remove Dart channel test and fix Flutter account test --- templates/dart/test/channel_test.dart.twig | 158 ------------------ .../flutter/test/src/channel_test.dart.twig | 2 +- 2 files changed, 1 insertion(+), 159 deletions(-) delete mode 100644 templates/dart/test/channel_test.dart.twig diff --git a/templates/dart/test/channel_test.dart.twig b/templates/dart/test/channel_test.dart.twig deleted file mode 100644 index 0e67e33923..0000000000 --- a/templates/dart/test/channel_test.dart.twig +++ /dev/null @@ -1,158 +0,0 @@ -import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart'; -{% if 'dart' in language.params.packageName %} -import 'package:test/test.dart'; -{% else %} -import 'package:flutter_test/flutter_test.dart'; -{% endif %} - -void main() { - group('database()', () { - test('returns database channel builder', () { - final builder = Channel.database(); - expect(builder.channel, 'databases.*'); - }); - - test('returns database channel with specific ID', () { - final builder = Channel.database('db1'); - expect(builder.channel, 'databases.db1'); - }); - - test('returns database channel with collection and document', () { - final channel = Channel.database('db1').collection('col1').document('doc1'); - expect(channel.channel, 'databases.db1.collections.col1.documents.doc1'); - }); - - test('returns database channel with action', () { - final channel = Channel.database('db1').collection('col1').document('doc1').create(); - expect(channel.toString(), 'databases.db1.collections.col1.documents.doc1.create'); - }); - }); - - group('tablesdb()', () { - test('returns tablesdb channel builder', () { - final builder = Channel.tablesdb(); - expect(builder.channel, 'tablesdb.*'); - }); - - test('returns tablesdb channel with specific ID', () { - final builder = Channel.tablesdb('db1'); - expect(builder.channel, 'tablesdb.db1'); - }); - - test('returns tablesdb channel with table and row', () { - final channel = Channel.tablesdb('db1').table('table1').row('row1'); - expect(channel.channel, 'tablesdb.db1.tables.table1.rows.row1'); - }); - - test('returns tablesdb channel with action', () { - final channel = Channel.tablesdb('db1').table('table1').row('row1').update(); - expect(channel.toString(), 'tablesdb.db1.tables.table1.rows.row1.update'); - }); - }); - - group('account()', () { - test('returns account channel with default', () { - expect(Channel.account(), 'account'); - }); - - test('returns account channel with specific user ID', () { - expect(Channel.account('user123'), 'account.user123'); - }); - }); - - group('bucket()', () { - test('returns buckets channel builder', () { - final builder = Channel.bucket(); - expect(builder.channel, 'buckets.*'); - }); - - test('returns buckets channel with specific ID', () { - final builder = Channel.bucket('bucket1'); - expect(builder.channel, 'buckets.bucket1'); - }); - - test('returns buckets channel with file', () { - final channel = Channel.bucket('bucket1').file('file1'); - expect(channel.channel, 'buckets.bucket1.files.file1'); - }); - - test('returns buckets channel with action', () { - final channel = Channel.bucket('bucket1').file('file1').delete(); - expect(channel.toString(), 'buckets.bucket1.files.file1.delete'); - }); - }); - - group('functions()', () { - test('returns functions channel builder', () { - final builder = Channel.function(); - expect(builder.channel, 'functions.*'); - }); - - test('returns functions channel with specific ID', () { - final builder = Channel.function('func1'); - expect(builder.channel, 'functions.func1'); - }); - - test('returns functions channel with execution', () { - final channel = Channel.function('func1').execution('exec1'); - expect(channel.channel, 'functions.func1.executions.exec1'); - }); - - test('returns functions channel with action', () { - final channel = Channel.function('func1').execution('exec1').create(); - expect(channel.toString(), 'functions.func1.executions.exec1.create'); - }); - }); - - group('teams()', () { - test('returns teams channel builder', () { - final builder = Channel.team(); - expect(builder.channel, 'teams.*'); - }); - - test('returns teams channel with specific team ID', () { - final builder = Channel.team('team1'); - expect(builder.channel, 'teams.team1'); - }); - - test('returns teams channel with action', () { - final channel = Channel.team('team1').create(); - expect(channel.toString(), 'teams.team1.create'); - }); - }); - - group('memberships()', () { - test('returns memberships channel builder', () { - final builder = Channel.membership(); - expect(builder.channel, 'memberships.*'); - }); - - test('returns memberships channel with specific membership ID', () { - final builder = Channel.membership('membership1'); - expect(builder.channel, 'memberships.membership1'); - }); - - test('returns memberships channel with action', () { - final channel = Channel.membership('membership1').update(); - expect(channel.toString(), 'memberships.membership1.update'); - }); - }); - - group('global events', () { - test('returns documents channel', () { - expect(Channel.documents, 'documents'); - }); - - test('returns rows channel', () { - expect(Channel.rows, 'rows'); - }); - - test('returns files channel', () { - expect(Channel.files, 'files'); - }); - - test('returns executions channel', () { - expect(Channel.executions, 'executions'); - }); - }); -} \ No newline at end of file diff --git a/templates/flutter/test/src/channel_test.dart.twig b/templates/flutter/test/src/channel_test.dart.twig index 968b67a827..e518298c04 100644 --- a/templates/flutter/test/src/channel_test.dart.twig +++ b/templates/flutter/test/src/channel_test.dart.twig @@ -36,7 +36,7 @@ void main() { group('account()', () { test('returns account channel with default', () { - expect(Channel.account(), 'account.*'); + expect(Channel.account(), 'account'); }); test('returns account channel with specific user ID', () { From c18bb9c60d7a4fe67060b4daf9548627246e62fe Mon Sep 17 00:00:00 2001 From: Fellmonkey <90258055+Fellmonkey@users.noreply.github.com> Date: Sun, 18 Jan 2026 16:25:52 +0300 Subject: [PATCH 3/4] Handle multiple response models in service test template Updated the Dart service test template to check for Map when multiple response models are present, improving test accuracy for methods with multiple possible response types. --- templates/dart/test/services/service_test.dart.twig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/templates/dart/test/services/service_test.dart.twig b/templates/dart/test/services/service_test.dart.twig index 32f3c09c03..5df69e56f7 100644 --- a/templates/dart/test/services/service_test.dart.twig +++ b/templates/dart/test/services/service_test.dart.twig @@ -102,7 +102,11 @@ void main() { {%- if method.type == 'location' ~%} expect(response, isA()); {%~ endif ~%}{%~ if method.responseModel and method.responseModel != 'any' ~%} + {% if method.responseModels|length > 1 %} + expect(response, isA>()); + {% else %} expect(response, isA()); + {% endif %} {%~ endif ~%} }); From 7f4efb61a40bbc888b02551445a04966bbe04de4 Mon Sep 17 00:00:00 2001 From: Fellmonkey <90258055+Fellmonkey@users.noreply.github.com> Date: Sat, 14 Feb 2026 13:33:03 +0300 Subject: [PATCH 4/4] Use example for string enums in Dart templates Previously, the examples for the messaging service were invalid, but now everything is fine, I have restored the logic. --- templates/dart/test/services/service_test.dart.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/dart/test/services/service_test.dart.twig b/templates/dart/test/services/service_test.dart.twig index 58dbd5deae..f01a391b96 100644 --- a/templates/dart/test/services/service_test.dart.twig +++ b/templates/dart/test/services/service_test.dart.twig @@ -1,6 +1,6 @@ {% macro sub_schema(definitions, property) %}{% if property.sub_schema %}{% if property.type == 'array' %}List<>{% else %}{ {% if definitions[property.sub_schema] %}{% for property in definitions[property.sub_schema].properties | filter(p => p.required) %} - '{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}{% if property.sub_schema and (property.sub_schema != 'prefs' and property.sub_schema != 'preferences') %}{{_self.sub_schema(spec.definitions, property)}}{% else %}{}{% endif %}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}{% if property.enum %}'{{property.enum[0]}}'{% else %}'{{property.example | escapeDollarSign}}'{% endif %}{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %}, + '{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}{% if property.sub_schema and (property.sub_schema != 'prefs' and property.sub_schema != 'preferences') %}{{_self.sub_schema(spec.definitions, property)}}{% else %}{}{% endif %}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{property.example | escapeDollarSign}}'{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %}, {% endfor %}{% endif %}}{% endif %}{% else %}{% if property.type == 'object' and property.additionalProperties %}Map{% else %}{{property | typeName}}{% endif %}{% endif %}{% endmacro %} {% import 'flutter/base/utils.twig' as utils %} {% if 'dart' in language.params.packageName %} @@ -69,7 +69,7 @@ void main() { {%~ if method.responseModel and method.responseModel != 'any' ~%} final Map data = { {%- for definition in spec.definitions ~%}{%~ if definition.name == method.responseModel -%}{%~ for property in definition.properties | filter((param) => param.required) ~%} - '{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}{% if property.sub_schema and (property.sub_schema != 'prefs' and property.sub_schema != 'preferences') %}{{_self.sub_schema(spec.definitions, property)}}{% else %}{}{% endif %}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}{% if property.enum %}'{{property.enum[0]}}'{% else %}'{{property.example | escapeDollarSign}}'{% endif %}{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%} + '{{property.name | escapeDollarSign}}': {% if property.type == 'object' %}{% if property.sub_schema and (property.sub_schema != 'prefs' and property.sub_schema != 'preferences') %}{{_self.sub_schema(spec.definitions, property)}}{% else %}{}{% endif %}{% elseif property.type == 'array' %}[]{% elseif property.type == 'string' %}'{{property.example | escapeDollarSign}}'{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%} }; {%~ else ~%}