|
| 1 | +import 'package:openapi_generator_annotations/openapi_generator_annotations.dart'; |
| 2 | +import 'package:test/test.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('AdditionalProperties', () { |
| 6 | + test('defaults', () { |
| 7 | + final props = AdditionalProperties(); |
| 8 | + expect(props.wrapper, Wrapper.none); |
| 9 | + expect(props.allowUnicodeIdentifiers, isFalse); |
| 10 | + expect(props.ensureUniqueParams, isTrue); |
| 11 | + expect(props.useEnumExtension, isFalse); |
| 12 | + expect(props.prependFormOrBodyParameters, isFalse); |
| 13 | + expect(props.legacyDiscriminatorBehavior, isTrue); |
| 14 | + expect(props.sortModelPropertiesByRequiredFlag, isTrue); |
| 15 | + expect(props.sortParamsByRequiredFlag, isTrue); |
| 16 | + // Default null props |
| 17 | + [ |
| 18 | + props.pubVersion, |
| 19 | + props.pubName, |
| 20 | + props.pubHomepage, |
| 21 | + props.pubDescription, |
| 22 | + props.pubAuthor, |
| 23 | + props.pubAuthorEmail, |
| 24 | + props.sourceFolder |
| 25 | + ].forEach((element) => expect(element, isNull)); |
| 26 | + }); |
| 27 | + test('toMap', () { |
| 28 | + final props = AdditionalProperties(); |
| 29 | + final map = props.toMap(); |
| 30 | + expect(map['wrapper'], 'none'); |
| 31 | + expect(map['allowUnicodeIdentifiers'], isFalse); |
| 32 | + expect(map['ensureUniqueParams'], isTrue); |
| 33 | + expect(map['useEnumExtension'], isFalse); |
| 34 | + expect(map['prependFormOrBodyParameters'], isFalse); |
| 35 | + expect(map['legacyDiscriminatorBehavior'], isTrue); |
| 36 | + expect(map['sortModelPropertiesByRequiredFlag'], isTrue); |
| 37 | + expect(map['sortParamsByRequiredFlag'], isTrue); |
| 38 | + |
| 39 | + // Doesn't include null fields |
| 40 | + [ |
| 41 | + 'pubVersion', |
| 42 | + 'pubName', |
| 43 | + 'pubHomepage', |
| 44 | + 'pubDescription', |
| 45 | + 'pubAuthor', |
| 46 | + 'pubAuthorEmail', |
| 47 | + 'sourceFolder' |
| 48 | + ].forEach((element) => expect(map.containsKey(element), isFalse)); |
| 49 | + }); |
| 50 | + test('fromMap', () { |
| 51 | + final props = AdditionalProperties( |
| 52 | + pubVersion: '1.0.0', |
| 53 | + pubName: 'test', |
| 54 | + pubHomepage: 'test', |
| 55 | + pubDescription: 'test', |
| 56 | + pubAuthorEmail : '[email protected]', |
| 57 | + pubAuthor: 'test'); |
| 58 | + final map = { |
| 59 | + 'allowUnicodeIdentifiers': props.allowUnicodeIdentifiers, |
| 60 | + 'ensureUniqueParams': props.ensureUniqueParams, |
| 61 | + 'useEnumExtension': props.useEnumExtension, |
| 62 | + 'prependFormOrBodyParameters': props.prependFormOrBodyParameters, |
| 63 | + 'pubAuthor': props.pubAuthor, |
| 64 | + 'pubAuthorEmail': props.pubAuthorEmail, |
| 65 | + 'pubDescription': props.pubDescription, |
| 66 | + 'pubHomepage': props.pubHomepage, |
| 67 | + 'pubName': props.pubName, |
| 68 | + 'pubVersion': props.pubVersion, |
| 69 | + 'legacyDiscriminatorBehavior': props.legacyDiscriminatorBehavior, |
| 70 | + 'sortModelPropertiesByRequiredFlag': |
| 71 | + props.sortModelPropertiesByRequiredFlag, |
| 72 | + 'sortParamsByRequiredFlag': props.sortParamsByRequiredFlag, |
| 73 | + 'sourceFolder': props.sourceFolder, |
| 74 | + 'wrapper': 'none', |
| 75 | + }; |
| 76 | + final actual = AdditionalProperties.fromMap(map); |
| 77 | + expect(actual.wrapper, props.wrapper); |
| 78 | + expect(actual.allowUnicodeIdentifiers, props.allowUnicodeIdentifiers); |
| 79 | + expect(actual.ensureUniqueParams, props.ensureUniqueParams); |
| 80 | + expect(actual.useEnumExtension, props.useEnumExtension); |
| 81 | + expect(actual.prependFormOrBodyParameters, |
| 82 | + props.prependFormOrBodyParameters); |
| 83 | + expect(actual.legacyDiscriminatorBehavior, |
| 84 | + props.legacyDiscriminatorBehavior); |
| 85 | + expect(actual.sortModelPropertiesByRequiredFlag, |
| 86 | + props.sortModelPropertiesByRequiredFlag); |
| 87 | + expect(actual.sortParamsByRequiredFlag, props.sortParamsByRequiredFlag); |
| 88 | + expect(actual.pubVersion, props.pubVersion); |
| 89 | + expect(actual.pubName, props.pubName); |
| 90 | + expect(actual.pubHomepage, props.pubHomepage); |
| 91 | + expect(actual.pubDescription, props.pubDescription); |
| 92 | + expect(actual.pubAuthor, props.pubAuthor); |
| 93 | + expect(actual.pubAuthorEmail, props.pubAuthorEmail); |
| 94 | + expect(actual.sourceFolder, props.sourceFolder); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + group('DioProperties', () { |
| 99 | + test('defaults', () { |
| 100 | + final props = DioProperties(); |
| 101 | + expect(props.wrapper, Wrapper.none); |
| 102 | + expect(props.allowUnicodeIdentifiers, isFalse); |
| 103 | + expect(props.ensureUniqueParams, isTrue); |
| 104 | + expect(props.useEnumExtension, isTrue); |
| 105 | + expect(props.prependFormOrBodyParameters, isFalse); |
| 106 | + expect(props.legacyDiscriminatorBehavior, isTrue); |
| 107 | + expect(props.sortModelPropertiesByRequiredFlag, isTrue); |
| 108 | + expect(props.sortParamsByRequiredFlag, isTrue); |
| 109 | + // Default null props |
| 110 | + [ |
| 111 | + props.pubVersion, |
| 112 | + props.pubName, |
| 113 | + props.pubHomepage, |
| 114 | + props.pubDescription, |
| 115 | + props.pubAuthor, |
| 116 | + props.pubAuthorEmail, |
| 117 | + props.sourceFolder, |
| 118 | + props.nullableFields, |
| 119 | + props.serializationLibrary, |
| 120 | + props.dateLibrary, |
| 121 | + ].forEach((element) => expect(element, isNull)); |
| 122 | + }); |
| 123 | + test('toMap', () { |
| 124 | + final props = DioProperties(); |
| 125 | + final map = props.toMap(); |
| 126 | + expect(map['wrapper'], 'none'); |
| 127 | + expect(map['allowUnicodeIdentifiers'], isFalse); |
| 128 | + expect(map['ensureUniqueParams'], isTrue); |
| 129 | + expect(map['useEnumExtension'], isTrue); |
| 130 | + expect(map['prependFormOrBodyParameters'], isFalse); |
| 131 | + expect(map['legacyDiscriminatorBehavior'], isTrue); |
| 132 | + expect(map['sortModelPropertiesByRequiredFlag'], isTrue); |
| 133 | + expect(map['sortParamsByRequiredFlag'], isTrue); |
| 134 | + |
| 135 | + // Doesn't include null fields |
| 136 | + [ |
| 137 | + 'pubVersion', |
| 138 | + 'pubName', |
| 139 | + 'pubHomepage', |
| 140 | + 'pubDescription', |
| 141 | + 'pubAuthor', |
| 142 | + 'pubAuthorEmail', |
| 143 | + 'sourceFolder' |
| 144 | + 'dateLibrary', |
| 145 | + 'nullableFields', |
| 146 | + 'serializationLibrary' |
| 147 | + ].forEach((element) => expect(map.containsKey(element), isFalse)); |
| 148 | + }); |
| 149 | + test('fromMap', () { |
| 150 | + final props = DioProperties( |
| 151 | + pubVersion: '1.0.0', |
| 152 | + pubName: 'test', |
| 153 | + pubHomepage: 'test', |
| 154 | + pubDescription: 'test', |
| 155 | + pubAuthorEmail : '[email protected]', |
| 156 | + pubAuthor: 'test', |
| 157 | + nullableFields: true, |
| 158 | + dateLibrary: DioDateLibrary.core, |
| 159 | + serializationLibrary: DioSerializationLibrary.json_serializable, |
| 160 | + ); |
| 161 | + final map = { |
| 162 | + 'allowUnicodeIdentifiers': props.allowUnicodeIdentifiers, |
| 163 | + 'ensureUniqueParams': props.ensureUniqueParams, |
| 164 | + 'useEnumExtension': props.useEnumExtension, |
| 165 | + 'prependFormOrBodyParameters': props.prependFormOrBodyParameters, |
| 166 | + 'pubAuthor': props.pubAuthor, |
| 167 | + 'pubAuthorEmail': props.pubAuthorEmail, |
| 168 | + 'pubDescription': props.pubDescription, |
| 169 | + 'pubHomepage': props.pubHomepage, |
| 170 | + 'pubName': props.pubName, |
| 171 | + 'pubVersion': props.pubVersion, |
| 172 | + 'legacyDiscriminatorBehavior': props.legacyDiscriminatorBehavior, |
| 173 | + 'sortModelPropertiesByRequiredFlag': |
| 174 | + props.sortModelPropertiesByRequiredFlag, |
| 175 | + 'sortParamsByRequiredFlag': props.sortParamsByRequiredFlag, |
| 176 | + 'sourceFolder': props.sourceFolder, |
| 177 | + 'wrapper': 'none', |
| 178 | + 'nullableFields': props.nullableFields, |
| 179 | + 'dateLibrary': 'core', |
| 180 | + 'serializationLibrary': 'json_serializable', |
| 181 | + }; |
| 182 | + final actual = DioProperties.fromMap(map); |
| 183 | + expect(actual.wrapper, props.wrapper); |
| 184 | + expect(actual.allowUnicodeIdentifiers, props.allowUnicodeIdentifiers); |
| 185 | + expect(actual.ensureUniqueParams, props.ensureUniqueParams); |
| 186 | + expect(actual.useEnumExtension, props.useEnumExtension); |
| 187 | + expect(actual.prependFormOrBodyParameters, |
| 188 | + props.prependFormOrBodyParameters); |
| 189 | + expect(actual.legacyDiscriminatorBehavior, |
| 190 | + props.legacyDiscriminatorBehavior); |
| 191 | + expect(actual.sortModelPropertiesByRequiredFlag, |
| 192 | + props.sortModelPropertiesByRequiredFlag); |
| 193 | + expect(actual.sortParamsByRequiredFlag, props.sortParamsByRequiredFlag); |
| 194 | + expect(actual.pubVersion, props.pubVersion); |
| 195 | + expect(actual.pubName, props.pubName); |
| 196 | + expect(actual.pubHomepage, props.pubHomepage); |
| 197 | + expect(actual.pubDescription, props.pubDescription); |
| 198 | + expect(actual.pubAuthor, props.pubAuthor); |
| 199 | + expect(actual.pubAuthorEmail, props.pubAuthorEmail); |
| 200 | + expect(actual.sourceFolder, props.sourceFolder); |
| 201 | + expect(actual.nullableFields, props.nullableFields); |
| 202 | + expect(actual.dateLibrary, props.dateLibrary); |
| 203 | + expect(actual.serializationLibrary, props.serializationLibrary); |
| 204 | + }); |
| 205 | + }); |
| 206 | + group('DioAltProperties', () { |
| 207 | + test('defaults', () { |
| 208 | + final props = DioAltProperties(); |
| 209 | + expect(props.wrapper, Wrapper.none); |
| 210 | + expect(props.allowUnicodeIdentifiers, isFalse); |
| 211 | + expect(props.ensureUniqueParams, isTrue); |
| 212 | + expect(props.useEnumExtension, isTrue); |
| 213 | + expect(props.prependFormOrBodyParameters, isFalse); |
| 214 | + expect(props.legacyDiscriminatorBehavior, isTrue); |
| 215 | + expect(props.sortModelPropertiesByRequiredFlag, isTrue); |
| 216 | + expect(props.sortParamsByRequiredFlag, isTrue); |
| 217 | + // Default null props |
| 218 | + [ |
| 219 | + props.pubVersion, |
| 220 | + props.pubName, |
| 221 | + props.pubHomepage, |
| 222 | + props.pubDescription, |
| 223 | + props.pubAuthor, |
| 224 | + props.pubAuthorEmail, |
| 225 | + props.sourceFolder, |
| 226 | + props.nullSafe, |
| 227 | + props.nullSafeArrayDefault, |
| 228 | + props.listAnyOf, |
| 229 | + props.pubspecDevDependencies, |
| 230 | + props.pubspecDependencies |
| 231 | + ].forEach((element) => expect(element, isNull)); |
| 232 | + }); |
| 233 | + test('toMap', () { |
| 234 | + final props = DioAltProperties(); |
| 235 | + final map = props.toMap(); |
| 236 | + expect(map['wrapper'], 'none'); |
| 237 | + expect(map['allowUnicodeIdentifiers'], isFalse); |
| 238 | + expect(map['ensureUniqueParams'], isTrue); |
| 239 | + expect(map['useEnumExtension'], isTrue); |
| 240 | + expect(map['prependFormOrBodyParameters'], isFalse); |
| 241 | + expect(map['legacyDiscriminatorBehavior'], isTrue); |
| 242 | + expect(map['sortModelPropertiesByRequiredFlag'], isTrue); |
| 243 | + expect(map['sortParamsByRequiredFlag'], isTrue); |
| 244 | + |
| 245 | + // Doesn't include null fields |
| 246 | + [ |
| 247 | + 'pubVersion', |
| 248 | + 'pubName', |
| 249 | + 'pubHomepage', |
| 250 | + 'pubDescription', |
| 251 | + 'pubAuthor', |
| 252 | + 'pubAuthorEmail', |
| 253 | + 'sourceFolder' |
| 254 | + 'nullSafe,' |
| 255 | + 'nullSafeArrayDefault,' |
| 256 | + 'listAnyOf,' |
| 257 | + 'pubspecDevDependencies,' |
| 258 | + 'pubspecDependencies' |
| 259 | + ].forEach((element) => expect(map.containsKey(element), isFalse)); |
| 260 | + }); |
| 261 | + test('fromMap', () { |
| 262 | + final props = DioAltProperties( |
| 263 | + pubVersion: '1.0.0', |
| 264 | + pubName: 'test', |
| 265 | + pubHomepage: 'test', |
| 266 | + pubDescription: 'test', |
| 267 | + pubAuthorEmail : '[email protected]', |
| 268 | + pubAuthor: 'test', |
| 269 | + nullSafe: true, |
| 270 | + nullSafeArrayDefault: true, |
| 271 | + listAnyOf: false, |
| 272 | + pubspecDevDependencies: 'something', |
| 273 | + pubspecDependencies: 'test', |
| 274 | + ); |
| 275 | + final map = { |
| 276 | + 'allowUnicodeIdentifiers': props.allowUnicodeIdentifiers, |
| 277 | + 'ensureUniqueParams': props.ensureUniqueParams, |
| 278 | + 'useEnumExtension': props.useEnumExtension, |
| 279 | + 'prependFormOrBodyParameters': props.prependFormOrBodyParameters, |
| 280 | + 'pubAuthor': props.pubAuthor, |
| 281 | + 'pubAuthorEmail': props.pubAuthorEmail, |
| 282 | + 'pubDescription': props.pubDescription, |
| 283 | + 'pubHomepage': props.pubHomepage, |
| 284 | + 'pubName': props.pubName, |
| 285 | + 'pubVersion': props.pubVersion, |
| 286 | + 'legacyDiscriminatorBehavior': props.legacyDiscriminatorBehavior, |
| 287 | + 'sortModelPropertiesByRequiredFlag': |
| 288 | + props.sortModelPropertiesByRequiredFlag, |
| 289 | + 'sortParamsByRequiredFlag': props.sortParamsByRequiredFlag, |
| 290 | + 'sourceFolder': props.sourceFolder, |
| 291 | + 'wrapper': 'none', |
| 292 | + 'nullSafe': props.nullSafe, |
| 293 | + 'nullSafeArrayDefault': props.nullSafeArrayDefault, |
| 294 | + 'listAnyOf': props.listAnyOf, |
| 295 | + 'pubspecDevDependencies': props.pubspecDevDependencies, |
| 296 | + 'pubspecDependencies': props.pubspecDependencies, |
| 297 | + }; |
| 298 | + final actual = DioAltProperties.fromMap(map); |
| 299 | + expect(actual.wrapper, props.wrapper); |
| 300 | + expect(actual.allowUnicodeIdentifiers, props.allowUnicodeIdentifiers); |
| 301 | + expect(actual.ensureUniqueParams, props.ensureUniqueParams); |
| 302 | + expect(actual.useEnumExtension, props.useEnumExtension); |
| 303 | + expect(actual.prependFormOrBodyParameters, |
| 304 | + props.prependFormOrBodyParameters); |
| 305 | + expect(actual.legacyDiscriminatorBehavior, |
| 306 | + props.legacyDiscriminatorBehavior); |
| 307 | + expect(actual.sortModelPropertiesByRequiredFlag, |
| 308 | + props.sortModelPropertiesByRequiredFlag); |
| 309 | + expect(actual.sortParamsByRequiredFlag, props.sortParamsByRequiredFlag); |
| 310 | + expect(actual.pubVersion, props.pubVersion); |
| 311 | + expect(actual.pubName, props.pubName); |
| 312 | + expect(actual.pubHomepage, props.pubHomepage); |
| 313 | + expect(actual.pubDescription, props.pubDescription); |
| 314 | + expect(actual.pubAuthor, props.pubAuthor); |
| 315 | + expect(actual.pubAuthorEmail, props.pubAuthorEmail); |
| 316 | + expect(actual.sourceFolder, props.sourceFolder); |
| 317 | + expect(actual.nullSafe, props.nullSafe); |
| 318 | + expect(actual.nullSafeArrayDefault, props.nullSafeArrayDefault); |
| 319 | + expect(actual.listAnyOf, props.listAnyOf); |
| 320 | + expect(actual.pubspecDevDependencies, props.pubspecDevDependencies); |
| 321 | + expect(actual.pubspecDependencies, props.pubspecDependencies); |
| 322 | + }); |
| 323 | + }); |
| 324 | +} |
0 commit comments