getResponseVariableUnitTest method

String getResponseVariableUnitTest(
  1. String apiName,
  2. dynamic body,
  3. String parent, {
  4. String suffix = 'Response',
  5. String variable = 'response',
})

Implementation

String getResponseVariableUnitTest(
  String apiName,
  dynamic body,
  String parent, {
  String suffix = 'Response',
  String variable = 'response',
}) {
  final List<Map> data = [];
  if (body is List) {
    for (var element in body) {
      data.add(element);
    }
  } else if (body is Map) {
    data.add(body);
  }

  List<String> result = [];
  listClassNameUnitTest.clear();

  for (var element in data) {
    final keys = element.keys;
    listClassNameUnitTest.clear();
    final variables = keys
        .map((e) => getValueUnitTest(e.toString(), element[e],
            apiName.pascalCase, '', '${variable}_${apiName.snakeCase}'))
        .join(',');
    result.add(
        '${variable}_${apiName.snakeCase}.${apiName.pascalCase}$suffix($variables${variables.isNotEmpty ? ',' : ''})');
  }

  if (result.length > 1) {
    return '[${result.join(',')}];';
  } else {
    return '${result.join(',')};';
  }
}