@@ -48,10 +48,13 @@ const globalVars = [
48
48
EnvironmentVariableModel (key: "num" , value: "5670000" ),
49
49
EnvironmentVariableModel (key: "token" , value: "token" ),
50
50
];
51
+ final globalVarsMap = {for (var item in globalVars) item.key: item.value};
51
52
const activeEnvVars = [
52
53
EnvironmentVariableModel (key: "url" , value: "api.apidash.dev" ),
53
54
EnvironmentVariableModel (key: "num" , value: "8940000" ),
54
55
];
56
+ final activeEnvVarsMap = {for (var item in activeEnvVars) item.key: item.value};
57
+ final combinedEnvVarsMap = mergeMaps (globalVarsMap, activeEnvVarsMap);
55
58
56
59
void main () {
57
60
group ("Testing getEnvironmentTitle function" , () {
@@ -125,66 +128,45 @@ void main() {
125
128
group ("Testing substituteVariables function" , () {
126
129
test ("Testing substituteVariables with null" , () {
127
130
String ? input;
128
- Map <String ?, List <EnvironmentVariableModel >> envMap = {};
129
- String ? activeEnvironmentId;
130
- expect (substituteVariables (input, envMap, activeEnvironmentId), null );
131
+ Map <String , String > envMap = {};
132
+ expect (substituteVariables (input, envMap), null );
131
133
});
132
134
133
135
test ("Testing substituteVariables with empty input" , () {
134
136
String input = "" ;
135
- Map <String ?, List <EnvironmentVariableModel >> envMap = {};
136
- String ? activeEnvironmentId;
137
- expect (substituteVariables (input, envMap, activeEnvironmentId), "" );
137
+ Map <String , String > envMap = {};
138
+ expect (substituteVariables (input, envMap), "" );
138
139
});
139
140
140
141
test ("Testing substituteVariables with empty envMap" , () {
141
142
String input = "{{url}}/humanize/social?num={{num}}" ;
142
- Map <String ?, List <EnvironmentVariableModel >> envMap = {};
143
- String ? activeEnvironmentId;
144
- String expected = "/humanize/social?num=" ;
145
- expect (substituteVariables (input, envMap, activeEnvironmentId), expected);
143
+ Map <String , String > envMap = {};
144
+ String expected = "{{url}}/humanize/social?num={{num}}" ;
145
+ expect (substituteVariables (input, envMap), expected);
146
146
});
147
147
148
148
test ("Testing substituteVariables with empty activeEnvironmentId" , () {
149
149
String input = "{{url}}/humanize/social?num={{num}}" ;
150
- Map <String ?, List <EnvironmentVariableModel >> envMap = {
151
- kGlobalEnvironmentId: globalVars,
152
- };
153
150
String expected = "api.foss42.com/humanize/social?num=5670000" ;
154
- expect (substituteVariables (input, envMap, null ), expected);
151
+ expect (substituteVariables (input, globalVarsMap ), expected);
155
152
});
156
153
157
154
test ("Testing substituteVariables with non-empty activeEnvironmentId" , () {
158
155
String input = "{{url}}/humanize/social?num={{num}}" ;
159
- Map <String ?, List <EnvironmentVariableModel >> envMap = {
160
- kGlobalEnvironmentId: globalVars,
161
- "activeEnvId" : activeEnvVars,
162
- };
163
- String ? activeEnvId = "activeEnvId" ;
164
156
String expected = "api.apidash.dev/humanize/social?num=8940000" ;
165
- expect (substituteVariables (input, envMap, activeEnvId ), expected);
157
+ expect (substituteVariables (input, combinedEnvVarsMap ), expected);
166
158
});
167
159
168
160
test ("Testing substituteVariables with incorrect paranthesis" , () {
169
161
String input = "{{url}}}/humanize/social?num={{num}}" ;
170
- Map <String ?, List <EnvironmentVariableModel >> envMap = {
171
- kGlobalEnvironmentId: globalVars,
172
- "activeEnvId" : activeEnvVars,
173
- };
174
- String ? activeEnvId = "activeEnvId" ;
175
162
String expected = "api.apidash.dev}/humanize/social?num=8940000" ;
176
- expect (substituteVariables (input, envMap, activeEnvId ), expected);
163
+ expect (substituteVariables (input, combinedEnvVarsMap ), expected);
177
164
});
178
165
179
166
test ("Testing substituteVariables function with unavailable variables" , () {
180
167
String input = "{{url1}}/humanize/social?num={{num}}" ;
181
- Map <String ?, List <EnvironmentVariableModel >> envMap = {
182
- kGlobalEnvironmentId: globalVars,
183
- "activeEnvId" : activeEnvVars,
184
- };
185
- String ? activeEnvironmentId = "activeEnvId" ;
186
- String expected = "/humanize/social?num=8940000" ;
187
- expect (substituteVariables (input, envMap, activeEnvironmentId), expected);
168
+ String expected = "{{url1}}/humanize/social?num=8940000" ;
169
+ expect (substituteVariables (input, combinedEnvVarsMap), expected);
188
170
});
189
171
});
190
172
@@ -251,9 +233,9 @@ void main() {
251
233
};
252
234
String ? activeEnvironmentId = "activeEnvId" ;
253
235
const expected = HttpRequestModel (
254
- url: "/humanize/social" ,
236
+ url: "{{url1}} /humanize/social" ,
255
237
headers: [
256
- NameValueModel (name: "Authorization" , value: "Bearer " ),
238
+ NameValueModel (name: "Authorization" , value: "Bearer {{token1}} " ),
257
239
],
258
240
params: [
259
241
NameValueModel (name: "num" , value: "8940000" ),
0 commit comments