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,
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,
);
final formattedJsonString = createJsonResponseTest(
pathTestPage,
featureName,
pageName,
apiName,
jsonResponse,
);
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() ?? '';
return result;
}