createModelUnitTest method
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,
- required String returnData,
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,
required String returnData,
}) {
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);
createDataModelBodyTest(
pathTestPage,
featureName,
pageName,
apiName,
jsonBody,
bodyVariable,
body is List,
);
final responseVariable = isReturnDataModel(returnData)
? getResponseVariableUnitTest(
apiName,
response,
'',
suffix: 'Response',
variable: 'response',
)
: '';
final entityVariable = isReturnDataModel(returnData)
? getResponseVariableUnitTest(
apiName,
response,
'',
suffix: 'Entity',
variable: 'entity',
)
: '';
final formattedJsonString = isReturnDataModel(returnData)
? createJsonResponseTest(
pathTestPage,
featureName,
pageName,
apiName,
jsonResponse,
)
: '';
if (isReturnDataModel(returnData)) {
createDataModelResponseTest(
pathTestPage,
featureName,
pageName,
apiName,
formattedJsonString,
responseVariable,
response is List,
);
}
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() ?? '';
result['returnData'] = returnData;
return result;
}