Skip to content

Commit 31954c0

Browse files
committed
#135: added extra tests
1 parent 4ae632d commit 31954c0

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

Diff for: lib/config/yml_generator_config.dart

+10
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ class YmlGeneratorConfig {
121121
final String name = propertyKey;
122122

123123
if (propertyValue is YamlMap) {
124+
final deprecatedValue = propertyValue['value'];
125+
if (deprecatedValue != null) {
126+
throw Exception(
127+
'"value" in model $key on property $name is not longer supported, the way enums are defined has been updated in v7.0.0. Follow the migration');
128+
}
129+
130+
if (propertyValue['type'] == null) {
131+
throw Exception(
132+
'The required key "Type" is required in model $key on property $name');
133+
}
124134
type = propertyValue['type'];
125135
isJsonvalue = propertyValue['is_json_value'] == true;
126136
defaultValue = propertyValue['default_value']?.toString();

Diff for: test/writer/enum_model_reader_test.dart

+41
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,47 @@ DoubleStatus:
315315
status_1:
316316
status_2:
317317
status_3:
318+
""",
319+
));
320+
test(
321+
'Value no longer supported',
322+
() => testEnumError(
323+
expectedError:
324+
'Exception: "value" in model DoubleStatus on property status_0 is not longer supported, the way enums are defined has been updated in v7.0.0. Follow the migration',
325+
enumYml: """
326+
DoubleStatus:
327+
path: status
328+
type: enum
329+
properties:
330+
status_0:
331+
value: true
332+
status_1:
333+
value: true
334+
status_2:
335+
value: true
336+
status_3:
337+
value: true
338+
""",
339+
));
340+
test(
341+
'type required',
342+
() => testEnumError(
343+
expectedError:
344+
'Exception: The required key "Type" is required in model Gender on property isMale',
345+
enumYml: """
346+
Gender:
347+
path: user/person/
348+
type: enum
349+
properties:
350+
isMale:
351+
is_json_key: true
352+
values:
353+
MALE:
354+
properties:
355+
isMale: hello
356+
FEMALE:
357+
properties:
358+
isMale: hello
318359
""",
319360
));
320361
});

Diff for: tool/test_coverage_create_helper.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import 'dart:io';
33
const packageName = 'model_generator';
44

55
void main() {
6-
Logger.debug('First create a file with all other files imported so flutter test coverage uses all files');
6+
Logger.debug(
7+
'First create a file with all other files imported so flutter test coverage uses all files');
78
final imports = Directory('lib').listSync(recursive: true).where((element) {
89
if (Directory(element.path).existsSync()) return false;
910
if (!element.path.endsWith('.dart')) return false;

0 commit comments

Comments
 (0)