@@ -56,6 +56,55 @@ describe('Bigtable/Mutation', function() {
56
56
57
57
assert . strictEqual ( num , decoded ) ;
58
58
} ) ;
59
+
60
+ it ( 'should convert a base64 encoded MIN_SAFE_INTEGER number when true' , function ( ) {
61
+ const num = Number . MIN_SAFE_INTEGER ;
62
+ const encoded = Buffer . from ( Long . fromNumber ( num ) . toBytesBE ( ) ) . toString (
63
+ 'base64'
64
+ ) ;
65
+ const decoded = Mutation . convertFromBytes ( encoded , {
66
+ isPossibleNumber : true ,
67
+ } ) ;
68
+
69
+ assert . strictEqual ( num , decoded ) ;
70
+ } ) ;
71
+
72
+ it ( 'should convert a base64 encoded MAX_SAFE_INTEGER number when true' , function ( ) {
73
+ const num = Number . MAX_SAFE_INTEGER ;
74
+ const encoded = Buffer . from ( Long . fromNumber ( num ) . toBytesBE ( ) ) . toString (
75
+ 'base64'
76
+ ) ;
77
+ const decoded = Mutation . convertFromBytes ( encoded , {
78
+ isPossibleNumber : true ,
79
+ } ) ;
80
+
81
+ assert . strictEqual ( num , decoded ) ;
82
+ } ) ;
83
+
84
+ it ( 'should not convert a base64 encoded smaller than MIN_SAFE_INTEGER number when true' , function ( ) {
85
+ const num = Number . MIN_SAFE_INTEGER - 100 ;
86
+ const encoded = Buffer . from ( Long . fromNumber ( num ) . toBytesBE ( ) ) . toString (
87
+ 'base64'
88
+ ) ;
89
+ const decoded = Mutation . convertFromBytes ( encoded , {
90
+ isPossibleNumber : true ,
91
+ } ) ;
92
+
93
+ assert . notStrictEqual ( num , decoded ) ;
94
+ } ) ;
95
+
96
+ it ( 'should not convert a base64 encoded larger than MAX_SAFE_INTEGER number when true' , function ( ) {
97
+ const num = Number . MAX_SAFE_INTEGER + 100 ;
98
+ const encoded = Buffer . from ( Long . fromNumber ( num ) . toBytesBE ( ) ) . toString (
99
+ 'base64'
100
+ ) ;
101
+ const decoded = Mutation . convertFromBytes ( encoded , {
102
+ isPossibleNumber : true ,
103
+ } ) ;
104
+
105
+ assert . notStrictEqual ( num , decoded ) ;
106
+ } ) ;
107
+
59
108
it ( 'should not convert a base64 encoded number when false' , function ( ) {
60
109
const num = 10 ;
61
110
const encoded = Buffer . from ( Long . fromNumber ( num ) . toBytesBE ( ) ) . toString (
0 commit comments