OLD | NEW |
1 library googleapis.firebasedynamiclinks.v1.test; | 1 library googleapis.firebasedynamiclinks.v1.test; |
2 | 2 |
3 import "dart:core" as core; | 3 import "dart:core" as core; |
4 import "dart:collection" as collection; | 4 import "dart:collection" as collection; |
5 import "dart:async" as async; | 5 import "dart:async" as async; |
6 import "dart:convert" as convert; | 6 import "dart:convert" as convert; |
7 | 7 |
8 import 'package:http/http.dart' as http; | 8 import 'package:http/http.dart' as http; |
9 import 'package:http/testing.dart' as http_testing; | 9 import 'package:http/testing.dart' as http_testing; |
10 import 'package:unittest/unittest.dart' as unittest; | 10 import 'package:test/test.dart' as unittest; |
11 | 11 |
12 import 'package:googleapis/firebasedynamiclinks/v1.dart' as api; | 12 import 'package:googleapis/firebasedynamiclinks/v1.dart' as api; |
13 | 13 |
14 class HttpServerMock extends http.BaseClient { | 14 class HttpServerMock extends http.BaseClient { |
15 core.Function _callback; | 15 core.Function _callback; |
16 core.bool _expectJson; | 16 core.bool _expectJson; |
17 | 17 |
18 void register(core.Function callback, core.bool expectJson) { | 18 void register(core.Function callback, core.bool expectJson) { |
19 _callback = callback; | 19 _callback = callback; |
20 _expectJson = expectJson; | 20 _expectJson = expectJson; |
(...skipping 18 matching lines...) Expand all Loading... |
39 } else { | 39 } else { |
40 return stream.toBytes().then((data) { | 40 return stream.toBytes().then((data) { |
41 return _callback(request, data); | 41 return _callback(request, data); |
42 }); | 42 }); |
43 } | 43 } |
44 } | 44 } |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 http.StreamedResponse stringResponse( | 48 http.StreamedResponse stringResponse( |
49 core.int status, core.Map headers, core.String body) { | 49 core.int status, core.Map<core.String, core.String> headers, core.String bod
y) { |
50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
51 return new http.StreamedResponse(stream, status, headers: headers); | 51 return new http.StreamedResponse(stream, status, headers: headers); |
52 } | 52 } |
53 | 53 |
54 core.int buildCounterAnalyticsInfo = 0; | 54 core.int buildCounterAnalyticsInfo = 0; |
55 buildAnalyticsInfo() { | 55 buildAnalyticsInfo() { |
56 var o = new api.AnalyticsInfo(); | 56 var o = new api.AnalyticsInfo(); |
57 buildCounterAnalyticsInfo++; | 57 buildCounterAnalyticsInfo++; |
58 if (buildCounterAnalyticsInfo < 3) { | 58 if (buildCounterAnalyticsInfo < 3) { |
59 o.googlePlayAnalytics = buildGooglePlayAnalytics(); | 59 o.googlePlayAnalytics = buildGooglePlayAnalytics(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 checkCreateShortDynamicLinkRequest(api.CreateShortDynamicLinkRequest o) { | 113 checkCreateShortDynamicLinkRequest(api.CreateShortDynamicLinkRequest o) { |
114 buildCounterCreateShortDynamicLinkRequest++; | 114 buildCounterCreateShortDynamicLinkRequest++; |
115 if (buildCounterCreateShortDynamicLinkRequest < 3) { | 115 if (buildCounterCreateShortDynamicLinkRequest < 3) { |
116 checkDynamicLinkInfo(o.dynamicLinkInfo); | 116 checkDynamicLinkInfo(o.dynamicLinkInfo); |
117 unittest.expect(o.longDynamicLink, unittest.equals('foo')); | 117 unittest.expect(o.longDynamicLink, unittest.equals('foo')); |
118 checkSuffix(o.suffix); | 118 checkSuffix(o.suffix); |
119 } | 119 } |
120 buildCounterCreateShortDynamicLinkRequest--; | 120 buildCounterCreateShortDynamicLinkRequest--; |
121 } | 121 } |
122 | 122 |
123 buildUnnamed2044() { | 123 buildUnnamed2054() { |
124 var o = new core.List<api.DynamicLinkWarning>(); | 124 var o = new core.List<api.DynamicLinkWarning>(); |
125 o.add(buildDynamicLinkWarning()); | 125 o.add(buildDynamicLinkWarning()); |
126 o.add(buildDynamicLinkWarning()); | 126 o.add(buildDynamicLinkWarning()); |
127 return o; | 127 return o; |
128 } | 128 } |
129 | 129 |
130 checkUnnamed2044(core.List<api.DynamicLinkWarning> o) { | 130 checkUnnamed2054(core.List<api.DynamicLinkWarning> o) { |
131 unittest.expect(o, unittest.hasLength(2)); | 131 unittest.expect(o, unittest.hasLength(2)); |
132 checkDynamicLinkWarning(o[0]); | 132 checkDynamicLinkWarning(o[0]); |
133 checkDynamicLinkWarning(o[1]); | 133 checkDynamicLinkWarning(o[1]); |
134 } | 134 } |
135 | 135 |
136 core.int buildCounterCreateShortDynamicLinkResponse = 0; | 136 core.int buildCounterCreateShortDynamicLinkResponse = 0; |
137 buildCreateShortDynamicLinkResponse() { | 137 buildCreateShortDynamicLinkResponse() { |
138 var o = new api.CreateShortDynamicLinkResponse(); | 138 var o = new api.CreateShortDynamicLinkResponse(); |
139 buildCounterCreateShortDynamicLinkResponse++; | 139 buildCounterCreateShortDynamicLinkResponse++; |
140 if (buildCounterCreateShortDynamicLinkResponse < 3) { | 140 if (buildCounterCreateShortDynamicLinkResponse < 3) { |
141 o.previewLink = "foo"; | 141 o.previewLink = "foo"; |
142 o.shortLink = "foo"; | 142 o.shortLink = "foo"; |
143 o.warning = buildUnnamed2044(); | 143 o.warning = buildUnnamed2054(); |
144 } | 144 } |
145 buildCounterCreateShortDynamicLinkResponse--; | 145 buildCounterCreateShortDynamicLinkResponse--; |
146 return o; | 146 return o; |
147 } | 147 } |
148 | 148 |
149 checkCreateShortDynamicLinkResponse(api.CreateShortDynamicLinkResponse o) { | 149 checkCreateShortDynamicLinkResponse(api.CreateShortDynamicLinkResponse o) { |
150 buildCounterCreateShortDynamicLinkResponse++; | 150 buildCounterCreateShortDynamicLinkResponse++; |
151 if (buildCounterCreateShortDynamicLinkResponse < 3) { | 151 if (buildCounterCreateShortDynamicLinkResponse < 3) { |
152 unittest.expect(o.previewLink, unittest.equals('foo')); | 152 unittest.expect(o.previewLink, unittest.equals('foo')); |
153 unittest.expect(o.shortLink, unittest.equals('foo')); | 153 unittest.expect(o.shortLink, unittest.equals('foo')); |
154 checkUnnamed2044(o.warning); | 154 checkUnnamed2054(o.warning); |
155 } | 155 } |
156 buildCounterCreateShortDynamicLinkResponse--; | 156 buildCounterCreateShortDynamicLinkResponse--; |
157 } | 157 } |
158 | 158 |
| 159 core.int buildCounterDynamicLinkEventStat = 0; |
| 160 buildDynamicLinkEventStat() { |
| 161 var o = new api.DynamicLinkEventStat(); |
| 162 buildCounterDynamicLinkEventStat++; |
| 163 if (buildCounterDynamicLinkEventStat < 3) { |
| 164 o.count = "foo"; |
| 165 o.event = "foo"; |
| 166 o.platform = "foo"; |
| 167 } |
| 168 buildCounterDynamicLinkEventStat--; |
| 169 return o; |
| 170 } |
| 171 |
| 172 checkDynamicLinkEventStat(api.DynamicLinkEventStat o) { |
| 173 buildCounterDynamicLinkEventStat++; |
| 174 if (buildCounterDynamicLinkEventStat < 3) { |
| 175 unittest.expect(o.count, unittest.equals('foo')); |
| 176 unittest.expect(o.event, unittest.equals('foo')); |
| 177 unittest.expect(o.platform, unittest.equals('foo')); |
| 178 } |
| 179 buildCounterDynamicLinkEventStat--; |
| 180 } |
| 181 |
159 core.int buildCounterDynamicLinkInfo = 0; | 182 core.int buildCounterDynamicLinkInfo = 0; |
160 buildDynamicLinkInfo() { | 183 buildDynamicLinkInfo() { |
161 var o = new api.DynamicLinkInfo(); | 184 var o = new api.DynamicLinkInfo(); |
162 buildCounterDynamicLinkInfo++; | 185 buildCounterDynamicLinkInfo++; |
163 if (buildCounterDynamicLinkInfo < 3) { | 186 if (buildCounterDynamicLinkInfo < 3) { |
164 o.analyticsInfo = buildAnalyticsInfo(); | 187 o.analyticsInfo = buildAnalyticsInfo(); |
165 o.androidInfo = buildAndroidInfo(); | 188 o.androidInfo = buildAndroidInfo(); |
166 o.dynamicLinkDomain = "foo"; | 189 o.dynamicLinkDomain = "foo"; |
167 o.iosInfo = buildIosInfo(); | 190 o.iosInfo = buildIosInfo(); |
168 o.link = "foo"; | 191 o.link = "foo"; |
(...skipping 11 matching lines...) Expand all Loading... |
180 checkAndroidInfo(o.androidInfo); | 203 checkAndroidInfo(o.androidInfo); |
181 unittest.expect(o.dynamicLinkDomain, unittest.equals('foo')); | 204 unittest.expect(o.dynamicLinkDomain, unittest.equals('foo')); |
182 checkIosInfo(o.iosInfo); | 205 checkIosInfo(o.iosInfo); |
183 unittest.expect(o.link, unittest.equals('foo')); | 206 unittest.expect(o.link, unittest.equals('foo')); |
184 checkNavigationInfo(o.navigationInfo); | 207 checkNavigationInfo(o.navigationInfo); |
185 checkSocialMetaTagInfo(o.socialMetaTagInfo); | 208 checkSocialMetaTagInfo(o.socialMetaTagInfo); |
186 } | 209 } |
187 buildCounterDynamicLinkInfo--; | 210 buildCounterDynamicLinkInfo--; |
188 } | 211 } |
189 | 212 |
| 213 buildUnnamed2055() { |
| 214 var o = new core.List<api.DynamicLinkEventStat>(); |
| 215 o.add(buildDynamicLinkEventStat()); |
| 216 o.add(buildDynamicLinkEventStat()); |
| 217 return o; |
| 218 } |
| 219 |
| 220 checkUnnamed2055(core.List<api.DynamicLinkEventStat> o) { |
| 221 unittest.expect(o, unittest.hasLength(2)); |
| 222 checkDynamicLinkEventStat(o[0]); |
| 223 checkDynamicLinkEventStat(o[1]); |
| 224 } |
| 225 |
| 226 core.int buildCounterDynamicLinkStats = 0; |
| 227 buildDynamicLinkStats() { |
| 228 var o = new api.DynamicLinkStats(); |
| 229 buildCounterDynamicLinkStats++; |
| 230 if (buildCounterDynamicLinkStats < 3) { |
| 231 o.linkEventStats = buildUnnamed2055(); |
| 232 } |
| 233 buildCounterDynamicLinkStats--; |
| 234 return o; |
| 235 } |
| 236 |
| 237 checkDynamicLinkStats(api.DynamicLinkStats o) { |
| 238 buildCounterDynamicLinkStats++; |
| 239 if (buildCounterDynamicLinkStats < 3) { |
| 240 checkUnnamed2055(o.linkEventStats); |
| 241 } |
| 242 buildCounterDynamicLinkStats--; |
| 243 } |
| 244 |
190 core.int buildCounterDynamicLinkWarning = 0; | 245 core.int buildCounterDynamicLinkWarning = 0; |
191 buildDynamicLinkWarning() { | 246 buildDynamicLinkWarning() { |
192 var o = new api.DynamicLinkWarning(); | 247 var o = new api.DynamicLinkWarning(); |
193 buildCounterDynamicLinkWarning++; | 248 buildCounterDynamicLinkWarning++; |
194 if (buildCounterDynamicLinkWarning < 3) { | 249 if (buildCounterDynamicLinkWarning < 3) { |
195 o.warningCode = "foo"; | 250 o.warningCode = "foo"; |
196 o.warningMessage = "foo"; | 251 o.warningMessage = "foo"; |
197 } | 252 } |
198 buildCounterDynamicLinkWarning--; | 253 buildCounterDynamicLinkWarning--; |
199 return o; | 254 return o; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 438 |
384 unittest.group("obj-schema-CreateShortDynamicLinkResponse", () { | 439 unittest.group("obj-schema-CreateShortDynamicLinkResponse", () { |
385 unittest.test("to-json--from-json", () { | 440 unittest.test("to-json--from-json", () { |
386 var o = buildCreateShortDynamicLinkResponse(); | 441 var o = buildCreateShortDynamicLinkResponse(); |
387 var od = new api.CreateShortDynamicLinkResponse.fromJson(o.toJson()); | 442 var od = new api.CreateShortDynamicLinkResponse.fromJson(o.toJson()); |
388 checkCreateShortDynamicLinkResponse(od); | 443 checkCreateShortDynamicLinkResponse(od); |
389 }); | 444 }); |
390 }); | 445 }); |
391 | 446 |
392 | 447 |
| 448 unittest.group("obj-schema-DynamicLinkEventStat", () { |
| 449 unittest.test("to-json--from-json", () { |
| 450 var o = buildDynamicLinkEventStat(); |
| 451 var od = new api.DynamicLinkEventStat.fromJson(o.toJson()); |
| 452 checkDynamicLinkEventStat(od); |
| 453 }); |
| 454 }); |
| 455 |
| 456 |
393 unittest.group("obj-schema-DynamicLinkInfo", () { | 457 unittest.group("obj-schema-DynamicLinkInfo", () { |
394 unittest.test("to-json--from-json", () { | 458 unittest.test("to-json--from-json", () { |
395 var o = buildDynamicLinkInfo(); | 459 var o = buildDynamicLinkInfo(); |
396 var od = new api.DynamicLinkInfo.fromJson(o.toJson()); | 460 var od = new api.DynamicLinkInfo.fromJson(o.toJson()); |
397 checkDynamicLinkInfo(od); | 461 checkDynamicLinkInfo(od); |
398 }); | 462 }); |
399 }); | 463 }); |
400 | 464 |
401 | 465 |
| 466 unittest.group("obj-schema-DynamicLinkStats", () { |
| 467 unittest.test("to-json--from-json", () { |
| 468 var o = buildDynamicLinkStats(); |
| 469 var od = new api.DynamicLinkStats.fromJson(o.toJson()); |
| 470 checkDynamicLinkStats(od); |
| 471 }); |
| 472 }); |
| 473 |
| 474 |
402 unittest.group("obj-schema-DynamicLinkWarning", () { | 475 unittest.group("obj-schema-DynamicLinkWarning", () { |
403 unittest.test("to-json--from-json", () { | 476 unittest.test("to-json--from-json", () { |
404 var o = buildDynamicLinkWarning(); | 477 var o = buildDynamicLinkWarning(); |
405 var od = new api.DynamicLinkWarning.fromJson(o.toJson()); | 478 var od = new api.DynamicLinkWarning.fromJson(o.toJson()); |
406 checkDynamicLinkWarning(od); | 479 checkDynamicLinkWarning(od); |
407 }); | 480 }); |
408 }); | 481 }); |
409 | 482 |
410 | 483 |
411 unittest.group("obj-schema-GooglePlayAnalytics", () { | 484 unittest.group("obj-schema-GooglePlayAnalytics", () { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 }); | 534 }); |
462 }); | 535 }); |
463 | 536 |
464 | 537 |
465 unittest.group("resource-ShortLinksResourceApi", () { | 538 unittest.group("resource-ShortLinksResourceApi", () { |
466 unittest.test("method--create", () { | 539 unittest.test("method--create", () { |
467 | 540 |
468 var mock = new HttpServerMock(); | 541 var mock = new HttpServerMock(); |
469 api.ShortLinksResourceApi res = new api.FirebasedynamiclinksApi(mock).shor
tLinks; | 542 api.ShortLinksResourceApi res = new api.FirebasedynamiclinksApi(mock).shor
tLinks; |
470 var arg_request = buildCreateShortDynamicLinkRequest(); | 543 var arg_request = buildCreateShortDynamicLinkRequest(); |
471 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 544 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
472 var obj = new api.CreateShortDynamicLinkRequest.fromJson(json); | 545 var obj = new api.CreateShortDynamicLinkRequest.fromJson(json); |
473 checkCreateShortDynamicLinkRequest(obj); | 546 checkCreateShortDynamicLinkRequest(obj); |
474 | 547 |
475 var path = (req.url).path; | 548 var path = (req.url).path; |
476 var pathOffset = 0; | 549 var pathOffset = 0; |
477 var index; | 550 var index; |
478 var subPart; | 551 var subPart; |
479 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 552 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
480 pathOffset += 1; | 553 pathOffset += 1; |
481 unittest.expect(path.substring(pathOffset, pathOffset + 13), unittest.eq
uals("v1/shortLinks")); | 554 unittest.expect(path.substring(pathOffset, pathOffset + 13), unittest.eq
uals("v1/shortLinks")); |
(...skipping 16 matching lines...) Expand all Loading... |
498 } | 571 } |
499 } | 572 } |
500 | 573 |
501 | 574 |
502 var h = { | 575 var h = { |
503 "content-type" : "application/json; charset=utf-8", | 576 "content-type" : "application/json; charset=utf-8", |
504 }; | 577 }; |
505 var resp = convert.JSON.encode(buildCreateShortDynamicLinkResponse()); | 578 var resp = convert.JSON.encode(buildCreateShortDynamicLinkResponse()); |
506 return new async.Future.value(stringResponse(200, h, resp)); | 579 return new async.Future.value(stringResponse(200, h, resp)); |
507 }), true); | 580 }), true); |
508 res.create(arg_request).then(unittest.expectAsync(((api.CreateShortDynamic
LinkResponse response) { | 581 res.create(arg_request).then(unittest.expectAsync1(((api.CreateShortDynami
cLinkResponse response) { |
509 checkCreateShortDynamicLinkResponse(response); | 582 checkCreateShortDynamicLinkResponse(response); |
510 }))); | 583 }))); |
511 }); | 584 }); |
512 | 585 |
513 }); | 586 }); |
514 | 587 |
515 | 588 |
| 589 unittest.group("resource-V1ResourceApi", () { |
| 590 unittest.test("method--getLinkStats", () { |
| 591 |
| 592 var mock = new HttpServerMock(); |
| 593 api.V1ResourceApi res = new api.FirebasedynamiclinksApi(mock).v1; |
| 594 var arg_dynamicLink = "foo"; |
| 595 var arg_durationDays = "foo"; |
| 596 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 597 var path = (req.url).path; |
| 598 var pathOffset = 0; |
| 599 var index; |
| 600 var subPart; |
| 601 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 602 pathOffset += 1; |
| 603 unittest.expect(path.substring(pathOffset, pathOffset + 3), unittest.equ
als("v1/")); |
| 604 pathOffset += 3; |
| 605 index = path.indexOf("/linkStats", pathOffset); |
| 606 unittest.expect(index >= 0, unittest.isTrue); |
| 607 subPart = core.Uri.decodeQueryComponent(path.substring(pathOffset, index
)); |
| 608 pathOffset = index; |
| 609 unittest.expect(subPart, unittest.equals("$arg_dynamicLink")); |
| 610 unittest.expect(path.substring(pathOffset, pathOffset + 10), unittest.eq
uals("/linkStats")); |
| 611 pathOffset += 10; |
| 612 |
| 613 var query = (req.url).query; |
| 614 var queryOffset = 0; |
| 615 var queryMap = {}; |
| 616 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 617 parseBool(n) { |
| 618 if (n == "true") return true; |
| 619 if (n == "false") return false; |
| 620 if (n == null) return null; |
| 621 throw new core.ArgumentError("Invalid boolean: $n"); |
| 622 } |
| 623 if (query.length > 0) { |
| 624 for (var part in query.split("&")) { |
| 625 var keyvalue = part.split("="); |
| 626 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 627 } |
| 628 } |
| 629 unittest.expect(queryMap["durationDays"].first, unittest.equals(arg_dura
tionDays)); |
| 630 |
| 631 |
| 632 var h = { |
| 633 "content-type" : "application/json; charset=utf-8", |
| 634 }; |
| 635 var resp = convert.JSON.encode(buildDynamicLinkStats()); |
| 636 return new async.Future.value(stringResponse(200, h, resp)); |
| 637 }), true); |
| 638 res.getLinkStats(arg_dynamicLink, durationDays: arg_durationDays).then(uni
ttest.expectAsync1(((api.DynamicLinkStats response) { |
| 639 checkDynamicLinkStats(response); |
| 640 }))); |
| 641 }); |
| 642 |
| 643 }); |
| 644 |
| 645 |
516 } | 646 } |
517 | 647 |
OLD | NEW |