|
18 | 18 | import { expect, use } from 'chai';
|
19 | 19 | import chaiAsPromised from 'chai-as-promised';
|
20 | 20 |
|
| 21 | +import { Bytes, vector } from '../../../src/api'; |
| 22 | +import { GeoPoint } from '../../../src/lite-api/geo_point'; |
| 23 | +import { Timestamp } from '../../../src/lite-api/timestamp'; |
21 | 24 | import { addEqualityMatcher } from '../../util/equality_matcher';
|
22 | 25 | import { Deferred } from '../../util/promise';
|
23 | 26 | import {
|
@@ -476,6 +479,116 @@ apiDescribe.only('Pipelines', persistence => {
|
476 | 479 | );
|
477 | 480 | });
|
478 | 481 |
|
| 482 | + it('accepts and returns all data types', async () => { |
| 483 | + const refDate = new Date(); |
| 484 | + const refTimestamp = Timestamp.now(); |
| 485 | + const constants = [ |
| 486 | + Constant.of(1).as('number'), |
| 487 | + Constant.of('a string').as('string'), |
| 488 | + Constant.of(true).as('boolean'), |
| 489 | + Constant.of(null).as('null'), |
| 490 | + Constant.of(new GeoPoint(0.1, 0.2)).as('geoPoint'), |
| 491 | + Constant.of(refTimestamp).as('timestamp'), |
| 492 | + Constant.of(refDate).as('date'), |
| 493 | + Constant.of( |
| 494 | + Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])) |
| 495 | + ).as('bytes'), |
| 496 | + Constant.of(doc(firestore, 'foo', 'bar')).as('documentReference'), |
| 497 | + Constant.of(vector([1, 2, 3])).as('vectorValue'), |
| 498 | + Constant.of({ |
| 499 | + 'number': 1, |
| 500 | + 'string': 'a string', |
| 501 | + 'boolean': true, |
| 502 | + 'null': null, |
| 503 | + 'geoPoint': new GeoPoint(0.1, 0.2), |
| 504 | + 'timestamp': refTimestamp, |
| 505 | + 'date': refDate, |
| 506 | + 'uint8Array': Bytes.fromUint8Array( |
| 507 | + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0]) |
| 508 | + ), |
| 509 | + 'documentReference': doc(firestore, 'foo', 'bar'), |
| 510 | + 'vectorValue': vector([1, 2, 3]), |
| 511 | + 'map': { |
| 512 | + 'number': 2, |
| 513 | + 'string': 'b string' |
| 514 | + }, |
| 515 | + 'array': [1, 'c string'] |
| 516 | + }).as('map'), |
| 517 | + Constant.of([ |
| 518 | + 1, |
| 519 | + 'a string', |
| 520 | + true, |
| 521 | + null, |
| 522 | + new GeoPoint(0.1, 0.2), |
| 523 | + refTimestamp, |
| 524 | + refDate, |
| 525 | + Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])), |
| 526 | + doc(firestore, 'foo', 'bar'), |
| 527 | + vector([1, 2, 3]), |
| 528 | + { |
| 529 | + 'number': 2, |
| 530 | + 'string': 'b string' |
| 531 | + } |
| 532 | + ]).as('array') |
| 533 | + ]; |
| 534 | + |
| 535 | + const results = await randomCol |
| 536 | + .pipeline() |
| 537 | + .limit(1) |
| 538 | + .select(...constants) |
| 539 | + .execute(); |
| 540 | + |
| 541 | + expectResults(results, { |
| 542 | + 'number': 1, |
| 543 | + 'string': 'a string', |
| 544 | + 'boolean': true, |
| 545 | + 'null': null, |
| 546 | + 'geoPoint': new GeoPoint(0.1, 0.2), |
| 547 | + 'timestamp': refTimestamp, |
| 548 | + 'date': Timestamp.fromDate(refDate), |
| 549 | + 'bytes': Bytes.fromUint8Array( |
| 550 | + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0]) |
| 551 | + ), |
| 552 | + 'documentReference': doc(firestore, 'foo', 'bar'), |
| 553 | + 'vectorValue': vector([1, 2, 3]), |
| 554 | + 'map': { |
| 555 | + 'number': 1, |
| 556 | + 'string': 'a string', |
| 557 | + 'boolean': true, |
| 558 | + 'null': null, |
| 559 | + 'geoPoint': new GeoPoint(0.1, 0.2), |
| 560 | + 'timestamp': refTimestamp, |
| 561 | + 'date': Timestamp.fromDate(refDate), |
| 562 | + 'uint8Array': Bytes.fromUint8Array( |
| 563 | + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0]) |
| 564 | + ), |
| 565 | + 'documentReference': doc(firestore, 'foo', 'bar'), |
| 566 | + 'vectorValue': vector([1, 2, 3]), |
| 567 | + 'map': { |
| 568 | + 'number': 2, |
| 569 | + 'string': 'b string' |
| 570 | + }, |
| 571 | + 'array': [1, 'c string'] |
| 572 | + }, |
| 573 | + 'array': [ |
| 574 | + 1, |
| 575 | + 'a string', |
| 576 | + true, |
| 577 | + null, |
| 578 | + new GeoPoint(0.1, 0.2), |
| 579 | + refTimestamp, |
| 580 | + Timestamp.fromDate(refDate), |
| 581 | + Bytes.fromUint8Array(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 0])), |
| 582 | + doc(firestore, 'foo', 'bar'), |
| 583 | + vector([1, 2, 3]), |
| 584 | + { |
| 585 | + 'number': 2, |
| 586 | + 'string': 'b string' |
| 587 | + } |
| 588 | + ] |
| 589 | + }); |
| 590 | + }); |
| 591 | + |
479 | 592 | it('cond works', async () => {
|
480 | 593 | const results = await randomCol
|
481 | 594 | .pipeline()
|
|
0 commit comments