a zip code crypto-currency system good for red ONLY

testing.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { HttpBackend, HttpClientModule, HttpErrorResponse, HttpEventType, HttpHeaders, HttpResponse } from '@angular/common/http';
  7. import { Injectable, NgModule } from '@angular/core';
  8. import { Observable } from 'rxjs/Observable';
  9. /**
  10. * @fileoverview added by tsickle
  11. * @suppress {checkTypes} checked by tsc
  12. */
  13. /**
  14. * @license
  15. * Copyright Google Inc. All Rights Reserved.
  16. *
  17. * Use of this source code is governed by an MIT-style license that can be
  18. * found in the LICENSE file at https://angular.io/license
  19. */
  20. /**
  21. * Defines a matcher for requests based on URL, method, or both.
  22. *
  23. * \@stable
  24. * @record
  25. */
  26. /**
  27. * Controller to be injected into tests, that allows for mocking and flushing
  28. * of requests.
  29. *
  30. * \@stable
  31. * @abstract
  32. */
  33. var HttpTestingController = /** @class */ (function () {
  34. function HttpTestingController() {
  35. }
  36. return HttpTestingController;
  37. }());
  38. /**
  39. * @fileoverview added by tsickle
  40. * @suppress {checkTypes} checked by tsc
  41. */
  42. /**
  43. * @license
  44. * Copyright Google Inc. All Rights Reserved.
  45. *
  46. * Use of this source code is governed by an MIT-style license that can be
  47. * found in the LICENSE file at https://angular.io/license
  48. */
  49. /**
  50. * A mock requests that was received and is ready to be answered.
  51. *
  52. * This interface allows access to the underlying `HttpRequest`, and allows
  53. * responding with `HttpEvent`s or `HttpErrorResponse`s.
  54. *
  55. * \@stable
  56. */
  57. var TestRequest = /** @class */ (function () {
  58. function TestRequest(request, observer) {
  59. this.request = request;
  60. this.observer = observer;
  61. /**
  62. * \@internal set by `HttpClientTestingBackend`
  63. */
  64. this._cancelled = false;
  65. }
  66. Object.defineProperty(TestRequest.prototype, "cancelled", {
  67. /**
  68. * Whether the request was cancelled after it was sent.
  69. */
  70. get: /**
  71. * Whether the request was cancelled after it was sent.
  72. * @return {?}
  73. */
  74. function () { return this._cancelled; },
  75. enumerable: true,
  76. configurable: true
  77. });
  78. /**
  79. * Resolve the request by returning a body plus additional HTTP information (such as response
  80. * headers) if provided.
  81. *
  82. * Both successful and unsuccessful responses can be delivered via `flush()`.
  83. */
  84. /**
  85. * Resolve the request by returning a body plus additional HTTP information (such as response
  86. * headers) if provided.
  87. *
  88. * Both successful and unsuccessful responses can be delivered via `flush()`.
  89. * @param {?} body
  90. * @param {?=} opts
  91. * @return {?}
  92. */
  93. TestRequest.prototype.flush = /**
  94. * Resolve the request by returning a body plus additional HTTP information (such as response
  95. * headers) if provided.
  96. *
  97. * Both successful and unsuccessful responses can be delivered via `flush()`.
  98. * @param {?} body
  99. * @param {?=} opts
  100. * @return {?}
  101. */
  102. function (body, opts) {
  103. if (opts === void 0) { opts = {}; }
  104. if (this.cancelled) {
  105. throw new Error("Cannot flush a cancelled request.");
  106. }
  107. var /** @type {?} */ url = this.request.urlWithParams;
  108. var /** @type {?} */ headers = (opts.headers instanceof HttpHeaders) ? opts.headers : new HttpHeaders(opts.headers);
  109. body = _maybeConvertBody(this.request.responseType, body);
  110. var /** @type {?} */ statusText = opts.statusText;
  111. var /** @type {?} */ status = opts.status !== undefined ? opts.status : 200;
  112. if (opts.status === undefined) {
  113. if (body === null) {
  114. status = 204;
  115. statusText = statusText || 'No Content';
  116. }
  117. else {
  118. statusText = statusText || 'OK';
  119. }
  120. }
  121. if (statusText === undefined) {
  122. throw new Error('statusText is required when setting a custom status.');
  123. }
  124. if (status >= 200 && status < 300) {
  125. this.observer.next(new HttpResponse({ body: body, headers: headers, status: status, statusText: statusText, url: url }));
  126. this.observer.complete();
  127. }
  128. else {
  129. this.observer.error(new HttpErrorResponse({ error: body, headers: headers, status: status, statusText: statusText, url: url }));
  130. }
  131. };
  132. /**
  133. * Resolve the request by returning an `ErrorEvent` (e.g. simulating a network failure).
  134. */
  135. /**
  136. * Resolve the request by returning an `ErrorEvent` (e.g. simulating a network failure).
  137. * @param {?} error
  138. * @param {?=} opts
  139. * @return {?}
  140. */
  141. TestRequest.prototype.error = /**
  142. * Resolve the request by returning an `ErrorEvent` (e.g. simulating a network failure).
  143. * @param {?} error
  144. * @param {?=} opts
  145. * @return {?}
  146. */
  147. function (error, opts) {
  148. if (opts === void 0) { opts = {}; }
  149. if (this.cancelled) {
  150. throw new Error("Cannot return an error for a cancelled request.");
  151. }
  152. if (opts.status && opts.status >= 200 && opts.status < 300) {
  153. throw new Error("error() called with a successful status.");
  154. }
  155. var /** @type {?} */ headers = (opts.headers instanceof HttpHeaders) ? opts.headers : new HttpHeaders(opts.headers);
  156. this.observer.error(new HttpErrorResponse({
  157. error: error,
  158. headers: headers,
  159. status: opts.status || 0,
  160. statusText: opts.statusText || '',
  161. url: this.request.urlWithParams,
  162. }));
  163. };
  164. /**
  165. * Deliver an arbitrary `HttpEvent` (such as a progress event) on the response stream for this
  166. * request.
  167. */
  168. /**
  169. * Deliver an arbitrary `HttpEvent` (such as a progress event) on the response stream for this
  170. * request.
  171. * @param {?} event
  172. * @return {?}
  173. */
  174. TestRequest.prototype.event = /**
  175. * Deliver an arbitrary `HttpEvent` (such as a progress event) on the response stream for this
  176. * request.
  177. * @param {?} event
  178. * @return {?}
  179. */
  180. function (event) {
  181. if (this.cancelled) {
  182. throw new Error("Cannot send events to a cancelled request.");
  183. }
  184. this.observer.next(event);
  185. };
  186. return TestRequest;
  187. }());
  188. /**
  189. * Helper function to convert a response body to an ArrayBuffer.
  190. * @param {?} body
  191. * @return {?}
  192. */
  193. function _toArrayBufferBody(body) {
  194. if (typeof ArrayBuffer === 'undefined') {
  195. throw new Error('ArrayBuffer responses are not supported on this platform.');
  196. }
  197. if (body instanceof ArrayBuffer) {
  198. return body;
  199. }
  200. throw new Error('Automatic conversion to ArrayBuffer is not supported for response type.');
  201. }
  202. /**
  203. * Helper function to convert a response body to a Blob.
  204. * @param {?} body
  205. * @return {?}
  206. */
  207. function _toBlob(body) {
  208. if (typeof Blob === 'undefined') {
  209. throw new Error('Blob responses are not supported on this platform.');
  210. }
  211. if (body instanceof Blob) {
  212. return body;
  213. }
  214. if (ArrayBuffer && body instanceof ArrayBuffer) {
  215. return new Blob([body]);
  216. }
  217. throw new Error('Automatic conversion to Blob is not supported for response type.');
  218. }
  219. /**
  220. * Helper function to convert a response body to JSON data.
  221. * @param {?} body
  222. * @param {?=} format
  223. * @return {?}
  224. */
  225. function _toJsonBody(body, format) {
  226. if (format === void 0) { format = 'JSON'; }
  227. if (typeof ArrayBuffer !== 'undefined' && body instanceof ArrayBuffer) {
  228. throw new Error("Automatic conversion to " + format + " is not supported for ArrayBuffers.");
  229. }
  230. if (typeof Blob !== 'undefined' && body instanceof Blob) {
  231. throw new Error("Automatic conversion to " + format + " is not supported for Blobs.");
  232. }
  233. if (typeof body === 'string' || typeof body === 'number' || typeof body === 'object' ||
  234. Array.isArray(body)) {
  235. return body;
  236. }
  237. throw new Error("Automatic conversion to " + format + " is not supported for response type.");
  238. }
  239. /**
  240. * Helper function to convert a response body to a string.
  241. * @param {?} body
  242. * @return {?}
  243. */
  244. function _toTextBody(body) {
  245. if (typeof body === 'string') {
  246. return body;
  247. }
  248. if (typeof ArrayBuffer !== 'undefined' && body instanceof ArrayBuffer) {
  249. throw new Error('Automatic conversion to text is not supported for ArrayBuffers.');
  250. }
  251. if (typeof Blob !== 'undefined' && body instanceof Blob) {
  252. throw new Error('Automatic conversion to text is not supported for Blobs.');
  253. }
  254. return JSON.stringify(_toJsonBody(body, 'text'));
  255. }
  256. /**
  257. * Convert a response body to the requested type.
  258. * @param {?} responseType
  259. * @param {?} body
  260. * @return {?}
  261. */
  262. function _maybeConvertBody(responseType, body) {
  263. if (body === null) {
  264. return null;
  265. }
  266. switch (responseType) {
  267. case 'arraybuffer':
  268. return _toArrayBufferBody(body);
  269. case 'blob':
  270. return _toBlob(body);
  271. case 'json':
  272. return _toJsonBody(body);
  273. case 'text':
  274. return _toTextBody(body);
  275. default:
  276. throw new Error("Unsupported responseType: " + responseType);
  277. }
  278. }
  279. /**
  280. * @fileoverview added by tsickle
  281. * @suppress {checkTypes} checked by tsc
  282. */
  283. /**
  284. * @license
  285. * Copyright Google Inc. All Rights Reserved.
  286. *
  287. * Use of this source code is governed by an MIT-style license that can be
  288. * found in the LICENSE file at https://angular.io/license
  289. */
  290. /**
  291. * A testing backend for `HttpClient` which both acts as an `HttpBackend`
  292. * and as the `HttpTestingController`.
  293. *
  294. * `HttpClientTestingBackend` works by keeping a list of all open requests.
  295. * As requests come in, they're added to the list. Users can assert that specific
  296. * requests were made and then flush them. In the end, a verify() method asserts
  297. * that no unexpected requests were made.
  298. *
  299. * \@stable
  300. */
  301. var HttpClientTestingBackend = /** @class */ (function () {
  302. function HttpClientTestingBackend() {
  303. /**
  304. * List of pending requests which have not yet been expected.
  305. */
  306. this.open = [];
  307. }
  308. /**
  309. * Handle an incoming request by queueing it in the list of open requests.
  310. */
  311. /**
  312. * Handle an incoming request by queueing it in the list of open requests.
  313. * @param {?} req
  314. * @return {?}
  315. */
  316. HttpClientTestingBackend.prototype.handle = /**
  317. * Handle an incoming request by queueing it in the list of open requests.
  318. * @param {?} req
  319. * @return {?}
  320. */
  321. function (req) {
  322. var _this = this;
  323. return new Observable(function (observer) {
  324. var /** @type {?} */ testReq = new TestRequest(req, observer);
  325. _this.open.push(testReq);
  326. observer.next(/** @type {?} */ ({ type: HttpEventType.Sent }));
  327. return function () { testReq._cancelled = true; };
  328. });
  329. };
  330. /**
  331. * Helper function to search for requests in the list of open requests.
  332. * @param {?} match
  333. * @return {?}
  334. */
  335. HttpClientTestingBackend.prototype._match = /**
  336. * Helper function to search for requests in the list of open requests.
  337. * @param {?} match
  338. * @return {?}
  339. */
  340. function (match) {
  341. if (typeof match === 'string') {
  342. return this.open.filter(function (testReq) { return testReq.request.urlWithParams === match; });
  343. }
  344. else if (typeof match === 'function') {
  345. return this.open.filter(function (testReq) { return match(testReq.request); });
  346. }
  347. else {
  348. return this.open.filter(function (testReq) {
  349. return (!match.method || testReq.request.method === match.method.toUpperCase()) &&
  350. (!match.url || testReq.request.urlWithParams === match.url);
  351. });
  352. }
  353. };
  354. /**
  355. * Search for requests in the list of open requests, and return all that match
  356. * without asserting anything about the number of matches.
  357. */
  358. /**
  359. * Search for requests in the list of open requests, and return all that match
  360. * without asserting anything about the number of matches.
  361. * @param {?} match
  362. * @return {?}
  363. */
  364. HttpClientTestingBackend.prototype.match = /**
  365. * Search for requests in the list of open requests, and return all that match
  366. * without asserting anything about the number of matches.
  367. * @param {?} match
  368. * @return {?}
  369. */
  370. function (match) {
  371. var _this = this;
  372. var /** @type {?} */ results = this._match(match);
  373. results.forEach(function (result) {
  374. var /** @type {?} */ index = _this.open.indexOf(result);
  375. if (index !== -1) {
  376. _this.open.splice(index, 1);
  377. }
  378. });
  379. return results;
  380. };
  381. /**
  382. * Expect that a single outstanding request matches the given matcher, and return
  383. * it.
  384. *
  385. * Requests returned through this API will no longer be in the list of open requests,
  386. * and thus will not match twice.
  387. */
  388. /**
  389. * Expect that a single outstanding request matches the given matcher, and return
  390. * it.
  391. *
  392. * Requests returned through this API will no longer be in the list of open requests,
  393. * and thus will not match twice.
  394. * @param {?} match
  395. * @param {?=} description
  396. * @return {?}
  397. */
  398. HttpClientTestingBackend.prototype.expectOne = /**
  399. * Expect that a single outstanding request matches the given matcher, and return
  400. * it.
  401. *
  402. * Requests returned through this API will no longer be in the list of open requests,
  403. * and thus will not match twice.
  404. * @param {?} match
  405. * @param {?=} description
  406. * @return {?}
  407. */
  408. function (match, description) {
  409. description = description || this.descriptionFromMatcher(match);
  410. var /** @type {?} */ matches = this.match(match);
  411. if (matches.length > 1) {
  412. throw new Error("Expected one matching request for criteria \"" + description + "\", found " + matches.length + " requests.");
  413. }
  414. if (matches.length === 0) {
  415. throw new Error("Expected one matching request for criteria \"" + description + "\", found none.");
  416. }
  417. return matches[0];
  418. };
  419. /**
  420. * Expect that no outstanding requests match the given matcher, and throw an error
  421. * if any do.
  422. */
  423. /**
  424. * Expect that no outstanding requests match the given matcher, and throw an error
  425. * if any do.
  426. * @param {?} match
  427. * @param {?=} description
  428. * @return {?}
  429. */
  430. HttpClientTestingBackend.prototype.expectNone = /**
  431. * Expect that no outstanding requests match the given matcher, and throw an error
  432. * if any do.
  433. * @param {?} match
  434. * @param {?=} description
  435. * @return {?}
  436. */
  437. function (match, description) {
  438. description = description || this.descriptionFromMatcher(match);
  439. var /** @type {?} */ matches = this.match(match);
  440. if (matches.length > 0) {
  441. throw new Error("Expected zero matching requests for criteria \"" + description + "\", found " + matches.length + ".");
  442. }
  443. };
  444. /**
  445. * Validate that there are no outstanding requests.
  446. */
  447. /**
  448. * Validate that there are no outstanding requests.
  449. * @param {?=} opts
  450. * @return {?}
  451. */
  452. HttpClientTestingBackend.prototype.verify = /**
  453. * Validate that there are no outstanding requests.
  454. * @param {?=} opts
  455. * @return {?}
  456. */
  457. function (opts) {
  458. if (opts === void 0) { opts = {}; }
  459. var /** @type {?} */ open = this.open;
  460. // It's possible that some requests may be cancelled, and this is expected.
  461. // The user can ask to ignore open requests which have been cancelled.
  462. if (opts.ignoreCancelled) {
  463. open = open.filter(function (testReq) { return !testReq.cancelled; });
  464. }
  465. if (open.length > 0) {
  466. // Show the methods and URLs of open requests in the error, for convenience.
  467. var /** @type {?} */ requests = open.map(function (testReq) {
  468. var /** @type {?} */ url = testReq.request.urlWithParams.split('?')[0];
  469. var /** @type {?} */ method = testReq.request.method;
  470. return method + " " + url;
  471. })
  472. .join(', ');
  473. throw new Error("Expected no open requests, found " + open.length + ": " + requests);
  474. }
  475. };
  476. /**
  477. * @param {?} matcher
  478. * @return {?}
  479. */
  480. HttpClientTestingBackend.prototype.descriptionFromMatcher = /**
  481. * @param {?} matcher
  482. * @return {?}
  483. */
  484. function (matcher) {
  485. if (typeof matcher === 'string') {
  486. return "Match URL: " + matcher;
  487. }
  488. else if (typeof matcher === 'object') {
  489. var /** @type {?} */ method = matcher.method || '(any)';
  490. var /** @type {?} */ url = matcher.url || '(any)';
  491. return "Match method: " + method + ", URL: " + url;
  492. }
  493. else {
  494. return "Match by function: " + matcher.name;
  495. }
  496. };
  497. HttpClientTestingBackend.decorators = [
  498. { type: Injectable },
  499. ];
  500. /** @nocollapse */
  501. HttpClientTestingBackend.ctorParameters = function () { return []; };
  502. return HttpClientTestingBackend;
  503. }());
  504. /**
  505. * @fileoverview added by tsickle
  506. * @suppress {checkTypes} checked by tsc
  507. */
  508. /**
  509. * @license
  510. * Copyright Google Inc. All Rights Reserved.
  511. *
  512. * Use of this source code is governed by an MIT-style license that can be
  513. * found in the LICENSE file at https://angular.io/license
  514. */
  515. /**
  516. * Configures `HttpClientTestingBackend` as the `HttpBackend` used by `HttpClient`.
  517. *
  518. * Inject `HttpTestingController` to expect and flush requests in your tests.
  519. *
  520. * \@stable
  521. */
  522. var HttpClientTestingModule = /** @class */ (function () {
  523. function HttpClientTestingModule() {
  524. }
  525. HttpClientTestingModule.decorators = [
  526. { type: NgModule, args: [{
  527. imports: [
  528. HttpClientModule,
  529. ],
  530. providers: [
  531. HttpClientTestingBackend,
  532. { provide: HttpBackend, useExisting: HttpClientTestingBackend },
  533. { provide: HttpTestingController, useExisting: HttpClientTestingBackend },
  534. ],
  535. },] },
  536. ];
  537. /** @nocollapse */
  538. HttpClientTestingModule.ctorParameters = function () { return []; };
  539. return HttpClientTestingModule;
  540. }());
  541. /**
  542. * @fileoverview added by tsickle
  543. * @suppress {checkTypes} checked by tsc
  544. */
  545. /**
  546. * @license
  547. * Copyright Google Inc. All Rights Reserved.
  548. *
  549. * Use of this source code is governed by an MIT-style license that can be
  550. * found in the LICENSE file at https://angular.io/license
  551. */
  552. /**
  553. * @fileoverview added by tsickle
  554. * @suppress {checkTypes} checked by tsc
  555. */
  556. /**
  557. * Generated bundle index. Do not edit.
  558. */
  559. export { HttpTestingController, HttpClientTestingModule, TestRequest, HttpClientTestingBackend as ɵa };
  560. //# sourceMappingURL=testing.js.map