OLD | NEW |
(Empty) | |
| 1 library googleapis.firebaseremoteconfig.v1.test; |
| 2 |
| 3 import "dart:core" as core; |
| 4 import "dart:async" as async; |
| 5 import "dart:convert" as convert; |
| 6 |
| 7 import 'package:http/http.dart' as http; |
| 8 import 'package:test/test.dart' as unittest; |
| 9 |
| 10 import 'package:googleapis/firebaseremoteconfig/v1.dart' as api; |
| 11 |
| 12 class HttpServerMock extends http.BaseClient { |
| 13 core.Function _callback; |
| 14 core.bool _expectJson; |
| 15 |
| 16 void register(core.Function callback, core.bool expectJson) { |
| 17 _callback = callback; |
| 18 _expectJson = expectJson; |
| 19 } |
| 20 |
| 21 async.Future<http.StreamedResponse> send(http.BaseRequest request) { |
| 22 if (_expectJson) { |
| 23 return request |
| 24 .finalize() |
| 25 .transform(convert.UTF8.decoder) |
| 26 .join('') |
| 27 .then((core.String jsonString) { |
| 28 if (jsonString.isEmpty) { |
| 29 return _callback(request, null); |
| 30 } else { |
| 31 return _callback(request, convert.JSON.decode(jsonString)); |
| 32 } |
| 33 }); |
| 34 } else { |
| 35 var stream = request.finalize(); |
| 36 if (stream == null) { |
| 37 return _callback(request, []); |
| 38 } else { |
| 39 return stream.toBytes().then((data) { |
| 40 return _callback(request, data); |
| 41 }); |
| 42 } |
| 43 } |
| 44 } |
| 45 } |
| 46 |
| 47 http.StreamedResponse stringResponse(core.int status, |
| 48 core.Map<core.String, core.String> headers, core.String body) { |
| 49 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
| 50 return new http.StreamedResponse(stream, status, headers: headers); |
| 51 } |
| 52 |
| 53 buildUnnamed758() { |
| 54 var o = new core.List<api.RemoteConfigCondition>(); |
| 55 o.add(buildRemoteConfigCondition()); |
| 56 o.add(buildRemoteConfigCondition()); |
| 57 return o; |
| 58 } |
| 59 |
| 60 checkUnnamed758(core.List<api.RemoteConfigCondition> o) { |
| 61 unittest.expect(o, unittest.hasLength(2)); |
| 62 checkRemoteConfigCondition(o[0]); |
| 63 checkRemoteConfigCondition(o[1]); |
| 64 } |
| 65 |
| 66 buildUnnamed759() { |
| 67 var o = new core.Map<core.String, api.RemoteConfigParameter>(); |
| 68 o["x"] = buildRemoteConfigParameter(); |
| 69 o["y"] = buildRemoteConfigParameter(); |
| 70 return o; |
| 71 } |
| 72 |
| 73 checkUnnamed759(core.Map<core.String, api.RemoteConfigParameter> o) { |
| 74 unittest.expect(o, unittest.hasLength(2)); |
| 75 checkRemoteConfigParameter(o["x"]); |
| 76 checkRemoteConfigParameter(o["y"]); |
| 77 } |
| 78 |
| 79 core.int buildCounterRemoteConfig = 0; |
| 80 buildRemoteConfig() { |
| 81 var o = new api.RemoteConfig(); |
| 82 buildCounterRemoteConfig++; |
| 83 if (buildCounterRemoteConfig < 3) { |
| 84 o.conditions = buildUnnamed758(); |
| 85 o.parameters = buildUnnamed759(); |
| 86 } |
| 87 buildCounterRemoteConfig--; |
| 88 return o; |
| 89 } |
| 90 |
| 91 checkRemoteConfig(api.RemoteConfig o) { |
| 92 buildCounterRemoteConfig++; |
| 93 if (buildCounterRemoteConfig < 3) { |
| 94 checkUnnamed758(o.conditions); |
| 95 checkUnnamed759(o.parameters); |
| 96 } |
| 97 buildCounterRemoteConfig--; |
| 98 } |
| 99 |
| 100 core.int buildCounterRemoteConfigCondition = 0; |
| 101 buildRemoteConfigCondition() { |
| 102 var o = new api.RemoteConfigCondition(); |
| 103 buildCounterRemoteConfigCondition++; |
| 104 if (buildCounterRemoteConfigCondition < 3) { |
| 105 o.expression = "foo"; |
| 106 o.name = "foo"; |
| 107 o.tagColor = "foo"; |
| 108 } |
| 109 buildCounterRemoteConfigCondition--; |
| 110 return o; |
| 111 } |
| 112 |
| 113 checkRemoteConfigCondition(api.RemoteConfigCondition o) { |
| 114 buildCounterRemoteConfigCondition++; |
| 115 if (buildCounterRemoteConfigCondition < 3) { |
| 116 unittest.expect(o.expression, unittest.equals('foo')); |
| 117 unittest.expect(o.name, unittest.equals('foo')); |
| 118 unittest.expect(o.tagColor, unittest.equals('foo')); |
| 119 } |
| 120 buildCounterRemoteConfigCondition--; |
| 121 } |
| 122 |
| 123 buildUnnamed760() { |
| 124 var o = new core.Map<core.String, api.RemoteConfigParameterValue>(); |
| 125 o["x"] = buildRemoteConfigParameterValue(); |
| 126 o["y"] = buildRemoteConfigParameterValue(); |
| 127 return o; |
| 128 } |
| 129 |
| 130 checkUnnamed760(core.Map<core.String, api.RemoteConfigParameterValue> o) { |
| 131 unittest.expect(o, unittest.hasLength(2)); |
| 132 checkRemoteConfigParameterValue(o["x"]); |
| 133 checkRemoteConfigParameterValue(o["y"]); |
| 134 } |
| 135 |
| 136 core.int buildCounterRemoteConfigParameter = 0; |
| 137 buildRemoteConfigParameter() { |
| 138 var o = new api.RemoteConfigParameter(); |
| 139 buildCounterRemoteConfigParameter++; |
| 140 if (buildCounterRemoteConfigParameter < 3) { |
| 141 o.conditionalValues = buildUnnamed760(); |
| 142 o.defaultValue = buildRemoteConfigParameterValue(); |
| 143 } |
| 144 buildCounterRemoteConfigParameter--; |
| 145 return o; |
| 146 } |
| 147 |
| 148 checkRemoteConfigParameter(api.RemoteConfigParameter o) { |
| 149 buildCounterRemoteConfigParameter++; |
| 150 if (buildCounterRemoteConfigParameter < 3) { |
| 151 checkUnnamed760(o.conditionalValues); |
| 152 checkRemoteConfigParameterValue(o.defaultValue); |
| 153 } |
| 154 buildCounterRemoteConfigParameter--; |
| 155 } |
| 156 |
| 157 core.int buildCounterRemoteConfigParameterValue = 0; |
| 158 buildRemoteConfigParameterValue() { |
| 159 var o = new api.RemoteConfigParameterValue(); |
| 160 buildCounterRemoteConfigParameterValue++; |
| 161 if (buildCounterRemoteConfigParameterValue < 3) { |
| 162 o.useInAppDefault = true; |
| 163 o.value = "foo"; |
| 164 } |
| 165 buildCounterRemoteConfigParameterValue--; |
| 166 return o; |
| 167 } |
| 168 |
| 169 checkRemoteConfigParameterValue(api.RemoteConfigParameterValue o) { |
| 170 buildCounterRemoteConfigParameterValue++; |
| 171 if (buildCounterRemoteConfigParameterValue < 3) { |
| 172 unittest.expect(o.useInAppDefault, unittest.isTrue); |
| 173 unittest.expect(o.value, unittest.equals('foo')); |
| 174 } |
| 175 buildCounterRemoteConfigParameterValue--; |
| 176 } |
| 177 |
| 178 main() { |
| 179 unittest.group("obj-schema-RemoteConfig", () { |
| 180 unittest.test("to-json--from-json", () { |
| 181 var o = buildRemoteConfig(); |
| 182 var od = new api.RemoteConfig.fromJson(o.toJson()); |
| 183 checkRemoteConfig(od); |
| 184 }); |
| 185 }); |
| 186 |
| 187 unittest.group("obj-schema-RemoteConfigCondition", () { |
| 188 unittest.test("to-json--from-json", () { |
| 189 var o = buildRemoteConfigCondition(); |
| 190 var od = new api.RemoteConfigCondition.fromJson(o.toJson()); |
| 191 checkRemoteConfigCondition(od); |
| 192 }); |
| 193 }); |
| 194 |
| 195 unittest.group("obj-schema-RemoteConfigParameter", () { |
| 196 unittest.test("to-json--from-json", () { |
| 197 var o = buildRemoteConfigParameter(); |
| 198 var od = new api.RemoteConfigParameter.fromJson(o.toJson()); |
| 199 checkRemoteConfigParameter(od); |
| 200 }); |
| 201 }); |
| 202 |
| 203 unittest.group("obj-schema-RemoteConfigParameterValue", () { |
| 204 unittest.test("to-json--from-json", () { |
| 205 var o = buildRemoteConfigParameterValue(); |
| 206 var od = new api.RemoteConfigParameterValue.fromJson(o.toJson()); |
| 207 checkRemoteConfigParameterValue(od); |
| 208 }); |
| 209 }); |
| 210 |
| 211 unittest.group("resource-ProjectsResourceApi", () { |
| 212 unittest.test("method--getRemoteConfig", () { |
| 213 var mock = new HttpServerMock(); |
| 214 api.ProjectsResourceApi res = |
| 215 new api.FirebaseremoteconfigApi(mock).projects; |
| 216 var arg_project = "foo"; |
| 217 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 218 var path = (req.url).path; |
| 219 var pathOffset = 0; |
| 220 var index; |
| 221 var subPart; |
| 222 unittest.expect( |
| 223 path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| 224 pathOffset += 1; |
| 225 unittest.expect( |
| 226 path.substring(pathOffset, pathOffset + 3), unittest.equals("v1/")); |
| 227 pathOffset += 3; |
| 228 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 229 |
| 230 var query = (req.url).query; |
| 231 var queryOffset = 0; |
| 232 var queryMap = {}; |
| 233 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 234 parseBool(n) { |
| 235 if (n == "true") return true; |
| 236 if (n == "false") return false; |
| 237 if (n == null) return null; |
| 238 throw new core.ArgumentError("Invalid boolean: $n"); |
| 239 } |
| 240 |
| 241 if (query.length > 0) { |
| 242 for (var part in query.split("&")) { |
| 243 var keyvalue = part.split("="); |
| 244 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), |
| 245 core.Uri.decodeQueryComponent(keyvalue[1])); |
| 246 } |
| 247 } |
| 248 |
| 249 var h = { |
| 250 "content-type": "application/json; charset=utf-8", |
| 251 }; |
| 252 var resp = convert.JSON.encode(buildRemoteConfig()); |
| 253 return new async.Future.value(stringResponse(200, h, resp)); |
| 254 }), true); |
| 255 res |
| 256 .getRemoteConfig(arg_project) |
| 257 .then(unittest.expectAsync1(((api.RemoteConfig response) { |
| 258 checkRemoteConfig(response); |
| 259 }))); |
| 260 }); |
| 261 |
| 262 unittest.test("method--updateRemoteConfig", () { |
| 263 var mock = new HttpServerMock(); |
| 264 api.ProjectsResourceApi res = |
| 265 new api.FirebaseremoteconfigApi(mock).projects; |
| 266 var arg_request = buildRemoteConfig(); |
| 267 var arg_project = "foo"; |
| 268 var arg_validateOnly = true; |
| 269 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 270 var obj = new api.RemoteConfig.fromJson(json); |
| 271 checkRemoteConfig(obj); |
| 272 |
| 273 var path = (req.url).path; |
| 274 var pathOffset = 0; |
| 275 var index; |
| 276 var subPart; |
| 277 unittest.expect( |
| 278 path.substring(pathOffset, pathOffset + 1), unittest.equals("/")); |
| 279 pathOffset += 1; |
| 280 unittest.expect( |
| 281 path.substring(pathOffset, pathOffset + 3), unittest.equals("v1/")); |
| 282 pathOffset += 3; |
| 283 // NOTE: We cannot test reserved expansions due to the inability to reve
rse the operation; |
| 284 |
| 285 var query = (req.url).query; |
| 286 var queryOffset = 0; |
| 287 var queryMap = {}; |
| 288 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 289 parseBool(n) { |
| 290 if (n == "true") return true; |
| 291 if (n == "false") return false; |
| 292 if (n == null) return null; |
| 293 throw new core.ArgumentError("Invalid boolean: $n"); |
| 294 } |
| 295 |
| 296 if (query.length > 0) { |
| 297 for (var part in query.split("&")) { |
| 298 var keyvalue = part.split("="); |
| 299 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), |
| 300 core.Uri.decodeQueryComponent(keyvalue[1])); |
| 301 } |
| 302 } |
| 303 unittest.expect(queryMap["validateOnly"].first, |
| 304 unittest.equals("$arg_validateOnly")); |
| 305 |
| 306 var h = { |
| 307 "content-type": "application/json; charset=utf-8", |
| 308 }; |
| 309 var resp = convert.JSON.encode(buildRemoteConfig()); |
| 310 return new async.Future.value(stringResponse(200, h, resp)); |
| 311 }), true); |
| 312 res |
| 313 .updateRemoteConfig(arg_request, arg_project, |
| 314 validateOnly: arg_validateOnly) |
| 315 .then(unittest.expectAsync1(((api.RemoteConfig response) { |
| 316 checkRemoteConfig(response); |
| 317 }))); |
| 318 }); |
| 319 }); |
| 320 } |
OLD | NEW |