mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
apidash_core: networking contents removed & platform-wide changes made
This commit is contained in:
@@ -2,6 +2,6 @@
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:better_networking/better_networking.dart';
|
||||
|
||||
void main() {}
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('Testing MapExtensions', () {
|
||||
group('Testing hasKeyContentType()', () {
|
||||
test('Content-Type present should return true', () {
|
||||
Map<String, String> mapEx = {"Content-Type": "x", "Agent": "Test"};
|
||||
expect(mapEx.hasKeyContentType(), true);
|
||||
});
|
||||
|
||||
test('content-Type present should return true', () {
|
||||
Map<String, String> mapEx = {"content-Type": "x", "Agent": "Test"};
|
||||
expect(mapEx.hasKeyContentType(), true);
|
||||
});
|
||||
|
||||
test('empty should return false', () {
|
||||
Map<String, String> mapEx = {};
|
||||
expect(mapEx.hasKeyContentType(), false);
|
||||
});
|
||||
|
||||
test('No content-type present should return false', () {
|
||||
Map<String, String> mapEx = {"Agent": "Test"};
|
||||
expect(mapEx.hasKeyContentType(), false);
|
||||
});
|
||||
|
||||
test('Different datatype should return false', () {
|
||||
Map mapEx = {1: "Test"};
|
||||
expect(mapEx.hasKeyContentType(), false);
|
||||
});
|
||||
|
||||
test('Mixed datatype but should return true', () {
|
||||
Map mapEx = {1: "Test", "content-type": "x"};
|
||||
expect(mapEx.hasKeyContentType(), true);
|
||||
});
|
||||
});
|
||||
|
||||
group('Testing getKeyContentType()', () {
|
||||
test('Content-Type present', () {
|
||||
Map<String, String> mapEx = {"Agent": "Test", "Content-Type": "x"};
|
||||
expect(mapEx.getKeyContentType(), "Content-Type");
|
||||
});
|
||||
|
||||
test('content-Type present', () {
|
||||
Map<String, String> mapEx = {"Agent": "Test", "content-Type": "x"};
|
||||
expect(mapEx.getKeyContentType(), "content-Type");
|
||||
});
|
||||
|
||||
test('empty should return null', () {
|
||||
Map<String, String> mapEx = {};
|
||||
expect(mapEx.getKeyContentType(), null);
|
||||
});
|
||||
|
||||
test('No content-type present should return null', () {
|
||||
Map<String, String> mapEx = {"Agent": "Test"};
|
||||
expect(mapEx.getKeyContentType(), null);
|
||||
});
|
||||
|
||||
test('Different datatype should return null', () {
|
||||
Map mapEx = {1: "Test"};
|
||||
expect(mapEx.getKeyContentType(), null);
|
||||
});
|
||||
|
||||
test('Mixed datatype but should return content-type', () {
|
||||
Map mapEx = {1: "Test", "content-type": "x"};
|
||||
expect(mapEx.getKeyContentType(), "content-type");
|
||||
});
|
||||
|
||||
test('Multiple occurence should return first', () {
|
||||
Map mapEx = {1: "Test", "content-Type": "y", "content-type": "x"};
|
||||
expect(mapEx.getKeyContentType(), "content-Type");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('Testing getValueContentType()', () {
|
||||
test('Content-Type present', () {
|
||||
Map<String, String> mapEx = {"Agent": "Test", "Content-Type": "x"};
|
||||
expect(mapEx.getValueContentType(), "x");
|
||||
});
|
||||
|
||||
test('content-Type present', () {
|
||||
Map<String, String> mapEx = {"Agent": "Test", "content-Type": "x"};
|
||||
expect(mapEx.getValueContentType(), "x");
|
||||
});
|
||||
|
||||
test('empty should return null', () {
|
||||
Map<String, String> mapEx = {};
|
||||
expect(mapEx.getValueContentType(), null);
|
||||
});
|
||||
|
||||
test('No content-type present should return null', () {
|
||||
Map<String, String> mapEx = {"Agent": "Test"};
|
||||
expect(mapEx.getValueContentType(), null);
|
||||
});
|
||||
|
||||
test('Different datatype should return null', () {
|
||||
Map mapEx = {1: "Test"};
|
||||
expect(mapEx.getValueContentType(), null);
|
||||
});
|
||||
|
||||
test('Mixed datatype but should return x', () {
|
||||
Map mapEx = {1: "Test", "content-type": "x"};
|
||||
expect(mapEx.getValueContentType(), "x");
|
||||
});
|
||||
|
||||
test('Multiple occurence should return first', () {
|
||||
Map mapEx = {1: "Test", "content-Type": "y", "content-type": "x"};
|
||||
expect(mapEx.getValueContentType(), "y");
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing ?.getValueContentType() function", () {
|
||||
test('Testing ?.getValueContentType() for header1', () {
|
||||
Map<String, String> header1 = {
|
||||
"content-type": "application/json",
|
||||
};
|
||||
String contentType1Expected = "application/json";
|
||||
expect(header1.getValueContentType(), contentType1Expected);
|
||||
});
|
||||
test('Testing ?.getValueContentType() when header keys are in header case',
|
||||
() {
|
||||
Map<String, String> header2 = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
expect(header2.getValueContentType(), "application/json");
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:better_networking/better_networking.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('CurlFileImport Tests', () {
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
import 'package:apidash_core/utils/http_request_utils.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('Testing RemoveJsonComments', () {
|
||||
test('Removes single-line comments', () {
|
||||
String input = '''
|
||||
{
|
||||
// This is a single-line comment
|
||||
"key": "value"
|
||||
}
|
||||
''';
|
||||
|
||||
String expected = '''{
|
||||
"key": "value"
|
||||
}''';
|
||||
expect(removeJsonComments(input), expected);
|
||||
});
|
||||
|
||||
test('Removes multi-line comments', () {
|
||||
String input = '''
|
||||
{
|
||||
/*
|
||||
This is a multi-line comment
|
||||
*/
|
||||
"key": "value"
|
||||
}
|
||||
''';
|
||||
|
||||
String expected = '''{
|
||||
"key": "value"
|
||||
}''';
|
||||
expect(removeJsonComments(input), expected);
|
||||
});
|
||||
|
||||
test('Handles valid JSON without comments', () {
|
||||
String input = '{"key":"value"}';
|
||||
String expected = '''{
|
||||
"key": "value"
|
||||
}''';
|
||||
expect(removeJsonComments(input), expected);
|
||||
});
|
||||
|
||||
test('Returns original string if invalid JSON', () {
|
||||
String input = '{key: value}';
|
||||
String expected = '{key: value}';
|
||||
expect(removeJsonComments(input), expected);
|
||||
});
|
||||
|
||||
test('Removes trailing commas', () {
|
||||
String input = '''
|
||||
{
|
||||
"key1": "value1",
|
||||
"key2": "value2", // trailing comma
|
||||
}
|
||||
''';
|
||||
|
||||
String expected = '''{
|
||||
"key1": "value1",
|
||||
"key2": "value2"
|
||||
}''';
|
||||
expect(removeJsonComments(input), expected);
|
||||
});
|
||||
|
||||
test('Test blank json', () {
|
||||
String input = '''
|
||||
{}
|
||||
''';
|
||||
|
||||
String expected = '{}';
|
||||
expect(removeJsonComments(input), expected);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
import 'package:apidash_core/utils/utils.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('Testing getMediaTypeFromContentType function', () {
|
||||
test('Testing getMediaTypeFromContentType for json type', () {
|
||||
String contentType1 = "application/json";
|
||||
MediaType mediaType1Expected = MediaType("application", "json");
|
||||
expect(getMediaTypeFromContentType(contentType1).toString(),
|
||||
mediaType1Expected.toString());
|
||||
});
|
||||
test('Testing getMediaTypeFromContentType for null', () {
|
||||
expect(getMediaTypeFromContentType(null), null);
|
||||
});
|
||||
test('Testing getMediaTypeFromContentType for image svg+xml type', () {
|
||||
String contentType3 = "image/svg+xml";
|
||||
MediaType mediaType3Expected = MediaType("image", "svg+xml");
|
||||
expect(getMediaTypeFromContentType(contentType3).toString(),
|
||||
mediaType3Expected.toString());
|
||||
});
|
||||
test('Testing getMediaTypeFromContentType for incorrect content type', () {
|
||||
String contentType4 = "text/html : charset=utf-8";
|
||||
expect(getMediaTypeFromContentType(contentType4), null);
|
||||
});
|
||||
test('Testing getMediaTypeFromContentType for text/css type', () {
|
||||
String contentType5 = "text/css; charset=utf-8";
|
||||
MediaType mediaType5Expected =
|
||||
MediaType("text", "css", {"charset": "utf-8"});
|
||||
expect(getMediaTypeFromContentType(contentType5).toString(),
|
||||
mediaType5Expected.toString());
|
||||
});
|
||||
test('Testing getMediaTypeFromContentType for incorrect with double ;', () {
|
||||
String contentType6 =
|
||||
"application/xml; charset=utf-16be ; date=21/03/2023";
|
||||
expect(getMediaTypeFromContentType(contentType6), null);
|
||||
});
|
||||
test('Testing getMediaTypeFromContentType for empty content type', () {
|
||||
expect(getMediaTypeFromContentType(""), null);
|
||||
});
|
||||
test('Testing getMediaTypeFromContentType for missing subtype', () {
|
||||
String contentType7 = "audio";
|
||||
expect(getMediaTypeFromContentType(contentType7), null);
|
||||
});
|
||||
test('Testing getMediaTypeFromContentType for missing Type', () {
|
||||
String contentType8 = "/html";
|
||||
expect(getMediaTypeFromContentType(contentType8), null);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing getMediaTypeFromHeaders", () {
|
||||
test('Testing getMediaTypeFromHeaders for basic case', () {
|
||||
Map<String, String> header1 = {
|
||||
"content-length": "4506",
|
||||
"cache-control": "private",
|
||||
"content-type": "application/json"
|
||||
};
|
||||
MediaType mediaType1Expected = MediaType("application", "json");
|
||||
expect(getMediaTypeFromHeaders(header1).toString(),
|
||||
mediaType1Expected.toString());
|
||||
});
|
||||
test('Testing getMediaTypeFromHeaders for null header', () {
|
||||
expect(getMediaTypeFromHeaders(null), null);
|
||||
});
|
||||
test('Testing getMediaTypeFromHeaders for incomplete header value', () {
|
||||
Map<String, String> header2 = {"content-length": "4506"};
|
||||
expect(getMediaTypeFromHeaders(header2), null);
|
||||
});
|
||||
test('Testing getMediaTypeFromHeaders for empty header value', () {
|
||||
Map<String, String> header3 = {"content-type": ""};
|
||||
expect(getMediaTypeFromHeaders(header3), null);
|
||||
});
|
||||
test(
|
||||
'Testing getMediaTypeFromHeaders for erroneous header value - missing type',
|
||||
() {
|
||||
Map<String, String> header4 = {"content-type": "/json"};
|
||||
expect(getMediaTypeFromHeaders(header4), null);
|
||||
});
|
||||
test(
|
||||
'Testing getMediaTypeFromHeaders for erroneous header value - missing subtype',
|
||||
() {
|
||||
Map<String, String> header5 = {"content-type": "application"};
|
||||
expect(getMediaTypeFromHeaders(header5), null);
|
||||
});
|
||||
test('Testing getMediaTypeFromHeaders for header6', () {
|
||||
Map<String, String> header6 = {"content-type": "image/svg+xml"};
|
||||
MediaType mediaType6Expected = MediaType("image", "svg+xml");
|
||||
expect(getMediaTypeFromHeaders(header6).toString(),
|
||||
mediaType6Expected.toString());
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing formatBody", () {
|
||||
test('Testing formatBody for null values', () {
|
||||
expect(formatBody(null, null), null);
|
||||
});
|
||||
test('Testing formatBody for null body values', () {
|
||||
MediaType mediaType1 = MediaType("application", "xml");
|
||||
expect(formatBody(null, mediaType1), null);
|
||||
});
|
||||
test('Testing formatBody for null MediaType values', () {
|
||||
String body1 = '''
|
||||
{
|
||||
"text":"The Chosen One";
|
||||
}
|
||||
''';
|
||||
expect(formatBody(body1, null), null);
|
||||
});
|
||||
test('Testing formatBody for json subtype values', () {
|
||||
String body2 = '''{"data":{"area":9831510.0,"population":331893745}}''';
|
||||
MediaType mediaType2 = MediaType("application", "json");
|
||||
String result2Expected = '''{
|
||||
"data": {
|
||||
"area": 9831510.0,
|
||||
"population": 331893745
|
||||
}
|
||||
}''';
|
||||
expect(formatBody(body2, mediaType2), result2Expected);
|
||||
});
|
||||
test('Testing formatBody for xml subtype values', () {
|
||||
String body3 = '''
|
||||
<breakfast_menu>
|
||||
<food>
|
||||
<name>Belgian Waffles</name>
|
||||
<price>5.95 USD</price>
|
||||
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
|
||||
<calories>650</calories>
|
||||
</food>
|
||||
</breakfast_menu>
|
||||
''';
|
||||
MediaType mediaType3 = MediaType("application", "xml");
|
||||
String result3Expected = '''<breakfast_menu>
|
||||
<food>
|
||||
<name>Belgian Waffles</name>
|
||||
<price>5.95 USD</price>
|
||||
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
|
||||
<calories>650</calories>
|
||||
</food>
|
||||
</breakfast_menu>''';
|
||||
expect(formatBody(body3, mediaType3), result3Expected);
|
||||
});
|
||||
group("Testing formatBody for html", () {
|
||||
MediaType mediaTypeHtml = MediaType("text", "html");
|
||||
test('Testing formatBody for html subtype values', () {
|
||||
String body4 = '''<html>
|
||||
<body>
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
</body>
|
||||
</html>''';
|
||||
expect(formatBody(body4, mediaTypeHtml), body4);
|
||||
});
|
||||
|
||||
test('Testing formatBody for html subtype values with random values', () {
|
||||
String body5 =
|
||||
'''<html>${RandomStringGenerator.getRandomStringLines(100, 10000)}</html>''';
|
||||
expect(formatBody(body5, mediaTypeHtml), null);
|
||||
});
|
||||
test(
|
||||
'Testing formatBody for html subtype values with random values within limit',
|
||||
() {
|
||||
String body6 =
|
||||
'''<html>${RandomStringGenerator.getRandomStringLines(100, 190)}</html>''';
|
||||
expect(formatBody(body6, mediaTypeHtml), body6);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
import 'package:apidash_core/utils/uri_utils.dart';
|
||||
import 'package:seed/seed.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group("Testing getUriScheme", () {
|
||||
test('Testing getUriScheme for https', () {
|
||||
Uri uri1 = Uri(
|
||||
scheme: 'https',
|
||||
host: 'dart.dev',
|
||||
path: 'guides/libraries/library-tour',
|
||||
fragment: 'numbers');
|
||||
String uriScheme1Expected = 'https';
|
||||
expect(getUriScheme(uri1), (uriScheme1Expected, true));
|
||||
});
|
||||
test('Testing getUriScheme for mailto scheme value', () {
|
||||
Uri uri2 = Uri(scheme: 'mailto');
|
||||
String uriScheme2Expected = 'mailto';
|
||||
expect(getUriScheme(uri2), (uriScheme2Expected, false));
|
||||
});
|
||||
test('Testing getUriScheme for empty scheme value', () {
|
||||
Uri uri3 = Uri(scheme: '');
|
||||
expect(getUriScheme(uri3), (null, false));
|
||||
});
|
||||
test('Testing getUriScheme for null scheme value', () {
|
||||
Uri uri4 = Uri(scheme: null);
|
||||
expect(getUriScheme(uri4), (null, false));
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing getValidRequestUri", () {
|
||||
test('Testing getValidRequestUri with localhost URL without port or path',
|
||||
() {
|
||||
String url1 = "localhost";
|
||||
Uri uri1Expected = Uri(scheme: 'http', host: 'localhost');
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with localhost URL with port', () {
|
||||
String url1 = "localhost:8080";
|
||||
Uri uri1Expected = Uri(scheme: 'http', host: 'localhost', port: 8080);
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with localhost URL with port and path',
|
||||
() {
|
||||
String url1 = "localhost:8080/hello";
|
||||
Uri uri1Expected =
|
||||
Uri(scheme: 'http', host: 'localhost', port: 8080, path: '/hello');
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with localhost URL with http prefix', () {
|
||||
String url1 = "http://localhost:3080";
|
||||
Uri uri1Expected = Uri(scheme: 'http', host: 'localhost', port: 3080);
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with localhost URL with https prefix', () {
|
||||
String url1 = "https://localhost:8080";
|
||||
Uri uri1Expected = Uri(scheme: 'https', host: 'localhost', port: 8080);
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with IP URL without port or path', () {
|
||||
String url1 = "8.8.8.8";
|
||||
Uri uri1Expected = Uri(scheme: 'http', host: '8.8.8.8');
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with IP URL with port', () {
|
||||
String url1 = "8.8.8.8:8080";
|
||||
Uri uri1Expected = Uri(scheme: 'http', host: '8.8.8.8', port: 8080);
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with IP URL with port and path', () {
|
||||
String url1 = "8.8.8.8:8080/hello";
|
||||
Uri uri1Expected =
|
||||
Uri(scheme: 'http', host: '8.8.8.8', port: 8080, path: '/hello');
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with IP URL with http prefix', () {
|
||||
String url1 = "http://8.8.8.8:3080";
|
||||
Uri uri1Expected = Uri(scheme: 'http', host: '8.8.8.8', port: 3080);
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri with IP URL with https prefix', () {
|
||||
String url1 = "https://8.8.8.8:8080";
|
||||
Uri uri1Expected = Uri(scheme: 'https', host: '8.8.8.8', port: 8080);
|
||||
expect(getValidRequestUri(url1, []), (uri1Expected, null));
|
||||
});
|
||||
|
||||
test('Testing getValidRequestUri for normal values', () {
|
||||
String url1 = "https://api.apidash.dev/country/data";
|
||||
const kvRow1 = NameValueModel(name: "code", value: "US");
|
||||
Uri uri1Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.apidash.dev',
|
||||
path: 'country/data',
|
||||
queryParameters: {'code': 'US'});
|
||||
expect(getValidRequestUri(url1, [kvRow1]), (uri1Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri for null url value', () {
|
||||
const kvRow2 = NameValueModel(name: "code", value: "US");
|
||||
expect(getValidRequestUri(null, [kvRow2]), (null, "URL is missing!"));
|
||||
});
|
||||
test('Testing getValidRequestUri for empty url value', () {
|
||||
const kvRow3 = NameValueModel(name: "", value: "");
|
||||
expect(getValidRequestUri("", [kvRow3]), (null, "URL is missing!"));
|
||||
});
|
||||
test('Testing getValidRequestUri when https is not provided in url', () {
|
||||
String url4 = "api.apidash.dev/country/data";
|
||||
const kvRow4 = NameValueModel(name: "code", value: "US");
|
||||
Uri uri4Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.apidash.dev',
|
||||
path: 'country/data',
|
||||
queryParameters: {'code': 'US'});
|
||||
expect(getValidRequestUri(url4, [kvRow4]), (uri4Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri when url has fragment', () {
|
||||
String url5 = "https://dart.dev/guides/libraries/library-tour#numbers";
|
||||
Uri uri5Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'dart.dev',
|
||||
path: '/guides/libraries/library-tour');
|
||||
expect(getValidRequestUri(url5, null), (uri5Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri when uri scheme is not supported', () {
|
||||
String url5 = "mailto:someone@example.com";
|
||||
expect(getValidRequestUri(url5, null),
|
||||
(null, "Unsupported URL Scheme (mailto)"));
|
||||
});
|
||||
test('Testing getValidRequestUri when query params in both url and kvrow',
|
||||
() {
|
||||
String url6 = "api.apidash.dev/country/data?code=IND";
|
||||
const kvRow6 = NameValueModel(name: "code", value: "US");
|
||||
Uri uri6Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.apidash.dev',
|
||||
path: 'country/data',
|
||||
queryParameters: {'code': 'US'});
|
||||
expect(getValidRequestUri(url6, [kvRow6]), (uri6Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri when kvrow is null', () {
|
||||
String url7 = "api.apidash.dev/country/data?code=US";
|
||||
Uri uri7Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.apidash.dev',
|
||||
path: 'country/data',
|
||||
queryParameters: {'code': 'US'});
|
||||
expect(getValidRequestUri(url7, null), (uri7Expected, null));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user