@@ -66,7 +66,7 @@ describe('Spanner', function() {
6666
6767 insertData . Key = id ;
6868
69- table . insert ( insertData , function ( err ) {
69+ table . insert ( insertData , function ( err , insertResp ) {
7070 if ( err ) {
7171 callback ( err ) ;
7272 return ;
@@ -79,13 +79,13 @@ describe('Spanner', function() {
7979 id : id ,
8080 } ,
8181 } ,
82- function ( err , rows ) {
82+ function ( err , rows , readResp ) {
8383 if ( err ) {
8484 callback ( err ) ;
8585 return ;
8686 }
8787
88- callback ( null , rows . shift ( ) ) ;
88+ callback ( null , rows . shift ( ) , insertResp , readResp ) ;
8989 }
9090 ) ;
9191 } ) ;
@@ -110,7 +110,8 @@ describe('Spanner', function() {
110110 FloatArray ARRAY<FLOAT64>,
111111 IntArray ARRAY<INT64>,
112112 StringArray ARRAY<STRING(MAX)>,
113- TimestampArray ARRAY<TIMESTAMP>
113+ TimestampArray ARRAY<TIMESTAMP>,
114+ CommitTimestamp TIMESTAMP OPTIONS (allow_commit_timestamp=true)
114115 ) PRIMARY KEY (Key)
115116 ` ,
116117 } ,
@@ -600,6 +601,24 @@ describe('Spanner', function() {
600601 } ) ;
601602 } ) ;
602603
604+ describe ( 'commit timestamp' , function ( ) {
605+ it ( 'should accept the commit timestamp placeholder' , function ( done ) {
606+ var data = { CommitTimestamp : Spanner . COMMIT_TIMESTAMP } ;
607+
608+ insert ( data , function ( err , row , commitResponse ) {
609+ assert . ifError ( err ) ;
610+
611+ var timestampFromCommit = fromProtoToDate (
612+ commitResponse . commitTimestamp
613+ ) ;
614+ var timestampFromRead = row . toJSON ( ) . CommitTimestamp ;
615+
616+ assert . deepEqual ( timestampFromCommit , timestampFromRead ) ;
617+ done ( ) ;
618+ } ) ;
619+ } ) ;
620+ } ) ;
621+
603622 it ( 'should throw an error for incorrect value types' , function ( done ) {
604623 table . insert ( { BoolValue : 'abc' } , function ( err ) {
605624 assert ( err ) ;
@@ -3584,3 +3603,8 @@ function wait(time) {
35843603 setTimeout ( resolve , time ) ;
35853604 } ) ;
35863605}
3606+
3607+ function fromProtoToDate ( obj ) {
3608+ var milliseconds = parseInt ( obj . nanos , 10 ) / 1e6 ;
3609+ return new Date ( parseInt ( obj . seconds , 10 ) * 1000 + milliseconds ) ;
3610+ }
0 commit comments