mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 18:57:05 +08:00
freezed NameValueModel
This commit is contained in:
@@ -2,16 +2,16 @@ import 'package:test/test.dart';
|
||||
import 'package:apidash/models/name_value_model.dart';
|
||||
|
||||
void main() {
|
||||
const kvRow1 = NameValueModel("harry", 23);
|
||||
const kvRow1 = NameValueModel(name: "harry", value: 23);
|
||||
String kvRow1Expected = "{harry: 23}";
|
||||
|
||||
test('Testing toString()', () {
|
||||
expect(kvRow1.toString(), kvRow1Expected);
|
||||
});
|
||||
|
||||
const kvRow2Expected = NameValueModel("winter", "26");
|
||||
const kvRow2Expected = NameValueModel(name: "winter", value: "26");
|
||||
test('Testing copyWith()', () {
|
||||
expect(kvRow1.copyWith(k: "winter", v: "26"), kvRow2Expected);
|
||||
expect(kvRow1.copyWith(name: "winter", value: "26"), kvRow2Expected);
|
||||
});
|
||||
|
||||
test('Testing hashcode', () {
|
||||
|
||||
@@ -55,8 +55,9 @@ void main() {
|
||||
url: 'api.foss42.com/case/lower',
|
||||
name: 'foss42 api',
|
||||
requestHeaders: const [
|
||||
NameValueModel('content-length', '18'),
|
||||
NameValueModel('content-type', 'application/json; charset=utf-8')
|
||||
NameValueModel(name: 'content-length', value: '18'),
|
||||
NameValueModel(
|
||||
name: 'content-type', value: 'application/json; charset=utf-8')
|
||||
],
|
||||
requestBodyContentType: ContentType.json,
|
||||
requestBody: '''{
|
||||
@@ -71,8 +72,9 @@ void main() {
|
||||
url: 'api.foss42.com/case/lower',
|
||||
name: 'foss42 api',
|
||||
requestHeaders: [
|
||||
NameValueModel('content-length', '18'),
|
||||
NameValueModel('content-type', 'application/json; charset=utf-8')
|
||||
NameValueModel(name: 'content-length', value: '18'),
|
||||
NameValueModel(
|
||||
name: 'content-type', value: 'application/json; charset=utf-8')
|
||||
],
|
||||
requestBodyContentType: ContentType.json,
|
||||
requestBody: '''{
|
||||
|
||||
@@ -14,7 +14,7 @@ const requestModelGet2 = RequestModel(
|
||||
url: 'https://api.foss42.com/country/data',
|
||||
method: HTTPVerb.get,
|
||||
requestParams: [
|
||||
NameValueModel('code', 'US'),
|
||||
NameValueModel(name: 'code', value: 'US'),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -24,7 +24,7 @@ const requestModelGet3 = RequestModel(
|
||||
url: 'https://api.foss42.com/country/data?code=US',
|
||||
method: HTTPVerb.get,
|
||||
requestParams: [
|
||||
NameValueModel('code', 'IND'),
|
||||
NameValueModel(name: 'code', value: 'IND'),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -34,11 +34,11 @@ const requestModelGet4 = RequestModel(
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
method: HTTPVerb.get,
|
||||
requestParams: [
|
||||
NameValueModel('num', '8700000'),
|
||||
NameValueModel('digits', '3'),
|
||||
NameValueModel('system', 'SS'),
|
||||
NameValueModel('add_space', 'true'),
|
||||
NameValueModel('trailing_zeros', 'true'),
|
||||
NameValueModel(name: 'num', value: '8700000'),
|
||||
NameValueModel(name: 'digits', value: '3'),
|
||||
NameValueModel(name: 'system', value: 'SS'),
|
||||
NameValueModel(name: 'add_space', value: 'true'),
|
||||
NameValueModel(name: 'trailing_zeros', value: 'true'),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -48,7 +48,7 @@ const requestModelGet5 = RequestModel(
|
||||
url: 'https://api.github.com/repos/foss42/apidash',
|
||||
method: HTTPVerb.get,
|
||||
requestHeaders: [
|
||||
NameValueModel('Authorization', 'Bearer XYZ'),
|
||||
NameValueModel(name: 'Authorization', value: 'Bearer XYZ'),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -58,10 +58,10 @@ const requestModelGet6 = RequestModel(
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
method: HTTPVerb.get,
|
||||
requestHeaders: [
|
||||
NameValueModel('Authorization', 'Bearer XYZ'),
|
||||
NameValueModel(name: 'Authorization', value: 'Bearer XYZ'),
|
||||
],
|
||||
requestParams: [
|
||||
NameValueModel('raw', 'true'),
|
||||
NameValueModel(name: 'raw', value: 'true'),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -73,18 +73,18 @@ void main() {
|
||||
expect(rowsToMap(null), null);
|
||||
});
|
||||
test('Testing for string KVRow values', () {
|
||||
const kvRow1 = NameValueModel("code", "IN");
|
||||
const kvRow1 = NameValueModel(name: "code", value: "IN");
|
||||
expect(rowsToMap([kvRow1]), {"code": "IN"});
|
||||
});
|
||||
test('Testing when header is True', () {
|
||||
const kvRow2 = NameValueModel("Text", "ABC");
|
||||
const kvRow2 = NameValueModel(name: "Text", value: "ABC");
|
||||
expect(rowsToMap([kvRow2], isHeader: true), {"text": "ABC"});
|
||||
});
|
||||
test('Testing when header is false and key is in upper case', () {
|
||||
const kvRow3 = <NameValueModel>[
|
||||
NameValueModel("TEXT", "ABC"),
|
||||
NameValueModel("version", 0.1),
|
||||
NameValueModel("month", 4),
|
||||
NameValueModel(name: "TEXT", value: "ABC"),
|
||||
NameValueModel(name: "version", value: 0.1),
|
||||
NameValueModel(name: "month", value: 4),
|
||||
];
|
||||
expect(
|
||||
rowsToMap(kvRow3), {"TEXT": "ABC", "version": "0.1", "month": "4"});
|
||||
@@ -98,9 +98,9 @@ void main() {
|
||||
test('Testing with a map value', () {
|
||||
Map<String, String> value1 = {"text": "abc", "lang": "eng", "code": "1"};
|
||||
const result1Expected = <NameValueModel>[
|
||||
NameValueModel("text", "abc"),
|
||||
NameValueModel("lang", "eng"),
|
||||
NameValueModel("code", "1")
|
||||
NameValueModel(name: "text", value: "abc"),
|
||||
NameValueModel(name: "lang", value: "eng"),
|
||||
NameValueModel(name: "code", value: "1")
|
||||
];
|
||||
expect(mapToRows(value1), result1Expected);
|
||||
});
|
||||
|
||||
@@ -176,7 +176,7 @@ void main() {
|
||||
group("Testing getValidRequestUri", () {
|
||||
test('Testing getValidRequestUri for normal values', () {
|
||||
String url1 = "https://api.foss42.com/country/data";
|
||||
const kvRow1 = NameValueModel("code", "US");
|
||||
const kvRow1 = NameValueModel(name: "code", value: "US");
|
||||
Uri uri1Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.foss42.com',
|
||||
@@ -185,16 +185,16 @@ void main() {
|
||||
expect(getValidRequestUri(url1, [kvRow1]), (uri1Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri for null url value', () {
|
||||
const kvRow2 = NameValueModel("code", "US");
|
||||
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("", "");
|
||||
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.foss42.com/country/data";
|
||||
const kvRow4 = NameValueModel("code", "US");
|
||||
const kvRow4 = NameValueModel(name: "code", value: "US");
|
||||
Uri uri4Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.foss42.com',
|
||||
@@ -218,7 +218,7 @@ void main() {
|
||||
test('Testing getValidRequestUri when query params in both url and kvrow',
|
||||
() {
|
||||
String url6 = "api.foss42.com/country/data?code=IND";
|
||||
const kvRow6 = NameValueModel("code", "US");
|
||||
const kvRow6 = NameValueModel(name: "code", value: "US");
|
||||
Uri uri6Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.foss42.com',
|
||||
|
||||
@@ -204,8 +204,9 @@ void main() {
|
||||
url: 'api.foss42.com/case/lower',
|
||||
name: 'foss42 api',
|
||||
requestHeaders: [
|
||||
NameValueModel('content-length', '18'),
|
||||
NameValueModel('content-type', 'application/json; charset=utf-8')
|
||||
NameValueModel(name: 'content-length', value: '18'),
|
||||
NameValueModel(
|
||||
name: 'content-type', value: 'application/json; charset=utf-8')
|
||||
],
|
||||
requestBodyContentType: ContentType.json,
|
||||
requestBody: '''{
|
||||
|
||||
Reference in New Issue
Block a user