@@ -24,6 +24,7 @@ import {GrpcService} from '../src/common-grpc/service';
2424import { google } from '../protos/protos' ;
2525import { GoogleError } from 'google-gax' ;
2626import { util } from 'protobufjs' ;
27+ import { v4 as uuidv4 } from 'uuid' ;
2728import Long = util . Long ;
2829const singer = require ( './data/singer' ) ;
2930const music = singer . examples . spanner . music ;
@@ -152,6 +153,22 @@ describe('codec', () => {
152153 } ) ;
153154 } ) ;
154155
156+ describe ( 'UUID' , ( ) => {
157+ it ( 'should store the value' , ( ) => {
158+ const value = uuidv4 ( ) ;
159+ const uuid = new codec . UUID ( value ) ;
160+
161+ assert . strictEqual ( uuid . value , value ) ;
162+ } ) ;
163+
164+ it ( 'should return as a uuid' , ( ) => {
165+ const value = uuidv4 ( ) ;
166+ const uuid = new codec . UUID ( value ) ;
167+
168+ assert . strictEqual ( uuid . valueOf ( ) , String ( value ) ) ;
169+ } ) ;
170+ } ) ;
171+
155172 describe ( 'Float' , ( ) => {
156173 it ( 'should store the value' , ( ) => {
157174 const value = 8 ;
@@ -680,6 +697,17 @@ describe('codec', () => {
680697 assert . deepStrictEqual ( decoded , expected ) ;
681698 } ) ;
682699
700+ it ( 'should decode UUID' , ( ) => {
701+ const value = uuidv4 ( ) ;
702+
703+ const decoded = codec . decode ( value , {
704+ code : google . spanner . v1 . TypeCode . UUID ,
705+ } ) ;
706+
707+ assert ( decoded instanceof codec . UUID ) ;
708+ assert . strictEqual ( decoded . value , value ) ;
709+ } ) ;
710+
683711 it . skip ( 'should decode FLOAT32' , ( ) => {
684712 const value = 'Infinity' ;
685713
@@ -1070,6 +1098,15 @@ describe('codec', () => {
10701098 assert . strictEqual ( encoded , '10' ) ;
10711099 } ) ;
10721100
1101+ it ( 'should encode UUID' , ( ) => {
1102+ const random = uuidv4 ( ) ;
1103+ const value = new codec . UUID ( random ) ;
1104+
1105+ const encoded = codec . encode ( value ) ;
1106+
1107+ assert . strictEqual ( encoded , random ) ;
1108+ } ) ;
1109+
10731110 it . skip ( 'should encode FLOAT32' , ( ) => {
10741111 const value = new codec . Float32 ( 10 ) ;
10751112
@@ -1165,6 +1202,12 @@ describe('codec', () => {
11651202 } ) ;
11661203 } ) ;
11671204
1205+ it ( 'should determine if the value is a uuid' , ( ) => {
1206+ assert . deepStrictEqual ( codec . getType ( new codec . UUID ( uuidv4 ( ) ) ) , {
1207+ type : 'uuid' ,
1208+ } ) ;
1209+ } ) ;
1210+
11681211 it . skip ( 'should determine if the value is a float32' , ( ) => {
11691212 assert . deepStrictEqual ( codec . getType ( new codec . Float32 ( 1.1 ) ) , {
11701213 type : 'float32' ,
@@ -1317,6 +1360,9 @@ describe('codec', () => {
13171360 google . spanner . v1 . TypeCode . TYPE_CODE_UNSPECIFIED
13181361 ] ,
13191362 } ,
1363+ uuid : {
1364+ code : google . spanner . v1 . TypeCode [ google . spanner . v1 . TypeCode . UUID ] ,
1365+ } ,
13201366 bool : {
13211367 code : google . spanner . v1 . TypeCode [ google . spanner . v1 . TypeCode . BOOL ] ,
13221368 } ,
0 commit comments