createModelUnitTest method

Map<String, String> createModelUnitTest({
  1. required String pathTestPage,
  2. required String appsName,
  3. required String featureName,
  4. required String pageName,
  5. required String pathPage,
  6. required String apiName,
  7. required dynamic jsonBody,
  8. required dynamic jsonResponse,
  9. required dynamic body,
  10. required dynamic response,
  11. required String method,
  12. required List<String> paramPath,
  13. required String? pathHeader,
  14. required String? cacheStrategy,
  15. required int? ttl,
  16. required bool? keepExpiredCache,
})

Implementation

Map<String, String> createModelUnitTest({
  required String pathTestPage,
  required String appsName,
  required String featureName,
  required String pageName,
  required String pathPage,
  required String apiName,
  required dynamic jsonBody,
  required dynamic jsonResponse,
  required dynamic body,
  required dynamic response,
  required String method,
  required List<String> paramPath,
  required String? pathHeader,
  required String? cacheStrategy,
  required int? ttl,
  required bool? keepExpiredCache,
}) {
  Map<String, String> result = {};

  final endpoint =
      'final url${apiName.pascalCase} = ${projectName.pascalCase}Endpoints.${apiName.camelCase}${appsName.pascalCase}${paramPath.isEmpty ? '' : '(${paramPath.map((e) => "'$e',").join()})'};';

  final bodyVariable = getBodyVariableUnitTest(apiName, body, '', paramPath);
  final responseVariable = getResponseVariableUnitTest(
    apiName,
    response,
    '',
    suffix: 'Response',
    variable: 'response',
  );
  final entityVariable = getResponseVariableUnitTest(
    apiName,
    response,
    '',
    suffix: 'Entity',
    variable: 'entity',
  );

  createDataModelBodyTest(
    pathTestPage,
    featureName,
    pageName,
    apiName,
    jsonBody,
    bodyVariable,
    body is List,
  );

  createDataModelResponseTest(
    pathTestPage,
    featureName,
    pageName,
    apiName,
    jsonResponse,
    responseVariable,
    response is List,
  );

  createJsonTest(pathTestPage, featureName, pageName, apiName, jsonResponse);

  String? headers;
  if (pathHeader != null && exists(pathHeader)) {
    try {
      headers = File(pathHeader).readAsStringSync();
    } catch (e) {
      StatusHelper.warning(e.toString());
    }
  }

  if (headers != null) {
    headers =
        ',headers: $headers.map((key, value) => MapEntry(key, value.toString())),';
  }

  result['apiName'] = apiName;
  result['body'] = bodyVariable;
  result['response'] = responseVariable;
  result['entity'] = entityVariable;
  result['jsonBody'] = jsonBody;
  result['jsonResponse'] = jsonResponse;
  result['method'] = method;
  result['endpoint'] = endpoint;
  result['header'] = headers ?? '';
  result['isBodyList'] = body is List ? 'true' : 'false';
  result['isResponseList'] = response is List ? 'true' : 'false';
  result['cacheStrategy'] = cacheStrategy ?? '';
  result['ttl'] = ttl?.toString() ?? '';
  result['keepExpiredCache'] = keepExpiredCache?.toString() ?? '';

  return result;
}