createMapperTest method

void createMapperTest(
  1. String pathTestPage,
  2. String featureName,
  3. String pageName,
  4. List<Map<String, String>> resultModelUnitTest,
)

Implementation

void createMapperTest(
  String pathTestPage,
  String featureName,
  String pageName,
  List<Map<String, String>> resultModelUnitTest,
) {
  final path = pathTestPage;
  DirectoryHelper.createDir(path, recursive: true);
  join(path, 'mapper_test.dart').write(
      '''// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables

import 'package:$featureName/$pageName/mapper.dart';
${resultModelUnitTest.map((e) => '''import 'package:$featureName/$pageName/data/models/response/${e['apiName']?.snakeCase}_response.dart' as response_${e['apiName']?.snakeCase};
import 'package:$featureName/$pageName/domain/entities/${e['apiName']?.snakeCase}_entity.dart' as entity_${e['apiName']?.snakeCase};''').join('\n')}
import 'package:flutter_test/flutter_test.dart';

void main() {
${resultModelUnitTest.map((e) {
    final className = e['apiName']?.pascalCase;
    final isResponseList = e['isResponseList'] == 'true';

    return '''test('mapper response model to entity $className', () {
  ${getConstOrFinalValue(e['response'] ?? '')} response${e['apiName']?.pascalCase} = ${e['response']}
  ${getConstOrFinalValue(e['entity'] ?? '')} entity${e['apiName']?.pascalCase} = ${e['entity']}

  ${isResponseList ? 'expect(response$className.map((e) => e.toEntity()).toList(), entity$className);' : 'expect(response$className.toEntity(), entity$className);'}
});

test('mapper entity to response model $className', () {
  ${getConstOrFinalValue(e['response'] ?? '')} response${e['apiName']?.pascalCase} = ${e['response']}
  ${getConstOrFinalValue(e['entity'] ?? '')} entity${e['apiName']?.pascalCase} = ${e['entity']}

  ${isResponseList ? 'expect(entity$className.map((e) => e.toResponse()).toList(), response$className);' : 'expect(entity$className.toResponse(), response$className);'}
});
''';
  }).join('\n')}
}''');

  StatusHelper.generated(join(path, 'mapper_test.dart'));
}