-
Notifications
You must be signed in to change notification settings - Fork 534
/
Copy pathrequest_model_test.dart
187 lines (176 loc) · 5.25 KB
/
request_model_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:apidash/models/models.dart';
import 'package:apidash/consts.dart';
void main() {
int statusCode = 200;
Map<String, String> headers = {
"content-length": "16",
"x-cloud-trace-context": "dad62aaf7f640300bbf629f4ae2f2f63",
"content-type": "application/json",
"date": "Sun, 23 Apr 2023 23:46:31 GMT",
"server": "Google Frontend"
};
Map<String, String> requestHeaders = {
"content-length": "18",
"content-type": "application/json; charset=utf-8"
};
String body = '{"data":"world"}';
Uint8List bodyBytes = Uint8List.fromList([
123,
34,
100,
97,
116,
97,
34,
58,
34,
119,
111,
114,
108,
100,
34,
125
]);
String formattedBody = '''{
"data": "world"
}''';
Duration time = const Duration(milliseconds: 516);
ResponseModel responseModel = ResponseModel(
statusCode: statusCode,
headers: headers,
requestHeaders: requestHeaders,
body: body,
formattedBody: formattedBody,
bodyBytes: bodyBytes,
time: time);
RequestModel requestModel = RequestModel(
id: '1',
method: HTTPVerb.post,
url: 'api.apidash.dev/case/lower',
name: 'foss42 api',
requestHeaders: const [
NameValueModel(name: 'content-length', value: '18'),
NameValueModel(
name: 'content-type', value: 'application/json; charset=utf-8')
],
requestBodyContentType: ContentType.json,
requestBody: '''{
"text":"WORLD"
}''',
responseStatus: 200,
responseModel: responseModel);
RequestModel requestModelDup = const RequestModel(
id: '1',
method: HTTPVerb.post,
url: 'api.apidash.dev/case/lower',
name: 'foss42 api',
requestHeaders: [
NameValueModel(name: 'content-length', value: '18'),
NameValueModel(
name: 'content-type', value: 'application/json; charset=utf-8')
],
requestBodyContentType: ContentType.json,
requestBody: '''{
"text":"WORLD"
}''');
RequestModel requestModelCopy = const RequestModel(
id: '1',
method: HTTPVerb.post,
url: 'api.apidash.dev/case/lower',
name: 'foss42 api (copy)',
requestHeaders: [
NameValueModel(name: 'content-length', value: '18'),
NameValueModel(
name: 'content-type', value: 'application/json; charset=utf-8')
],
requestBodyContentType: ContentType.json,
requestBody: '''{
"text":"WORLD"
}''');
Map<String, dynamic> requestModelAsJson = {
"id": '1',
"method": 'post',
"url": 'api.apidash.dev/case/lower',
"name": 'foss42 api',
'description': '',
"requestHeaders": {
'content-length': '18',
'content-type': 'application/json; charset=utf-8'
},
'isHeaderEnabledList': null,
'requestParams': null,
'isParamEnabledList': null,
"requestBodyContentType": 'json',
"requestBody": '''{
"text":"WORLD"
}''',
'requestFile': null,
'requestFormDataList': null,
'responseStatus': null,
'message': null,
'responseModel': null
};
test('Testing copyWith', () {
final requestModelcopyWith = requestModel.copyWith(name: 'API foss42');
expect(requestModelcopyWith.name, 'API foss42');
});
test('Testing duplicate', () {
expect(requestModel.duplicate(id: '1'), requestModelCopy);
});
test('Testing toJson', () {
expect(requestModelDup.toJson(), requestModelAsJson);
});
test('Testing fromJson', () {
final modelFromJson = RequestModel.fromJson(requestModelAsJson);
expect(modelFromJson, requestModelDup);
});
final requestModeDupString = [
"Request Id: 1",
"Request Method: post",
"Request URL: api.apidash.dev/case/lower",
"Request Name: foss42 api",
"Request Description: ",
"Request Tab Index: 0",
"Request Headers: [NameValueModel(name: content-length, value: 18), NameValueModel(name: content-type, value: application/json; charset=utf-8)]",
"Enabled Headers: null",
"Request Params: null",
"Enabled Params: null",
"Request Body Content Type: ContentType.json",
'Request Body: {\n"text":"WORLD"\n}',
'Request File: null',
'Request FormData: null',
"Response Status: null",
"Response Message: null",
"Response: null"
].join("\n");
test('Testing toString', () {
expect(requestModelDup.toString(), requestModeDupString);
});
test('Testing getters', () {
expect(requestModel.enabledRequestHeaders, const [
NameValueModel(name: 'content-length', value: '18'),
NameValueModel(
name: 'content-type', value: 'application/json; charset=utf-8')
]);
expect(requestModel.enabledRequestParams, null);
expect(requestModel.enabledHeadersMap, {
'content-length': '18',
'content-type': 'application/json; charset=utf-8'
});
expect(requestModel.enabledParamsMap, {});
expect(requestModel.headersMap, {
'content-length': '18',
'content-type': 'application/json; charset=utf-8'
});
expect(requestModel.paramsMap, {});
expect(requestModel.formDataMapList, []);
expect(requestModel.hasFormData, false);
expect(requestModel.hasContentTypeHeader, true);
});
test('Testing hashcode', () {
expect(requestModel.hashCode, greaterThan(0));
});
}