@@ -41,7 +41,7 @@ describe('168. soda4.js', () => {
41
41
await sodaUtil . cleanup ( ) ;
42
42
} ) ;
43
43
44
- it . skip ( '168.1 insertOneAndGet() method ' , async ( ) => {
44
+ it ( '168.1 insertOneAndGet() fetches attributes without content ' , async ( ) => {
45
45
let conn ;
46
46
try {
47
47
conn = await oracledb . getConnection ( dbconfig ) ;
@@ -65,8 +65,7 @@ describe('168. soda4.js', () => {
65
65
( myDoc ) . should . be . an . Object ( ) ;
66
66
67
67
let content1 = myDoc . getContent ( ) ;
68
- console . log ( "getContent()" ) ;
69
- console . log ( content1 ) ;
68
+ should . not . exist ( content1 ) ;
70
69
71
70
// Fetch it back
72
71
let doc2 = await coll . find ( ) . key ( myKey ) . getOne ( ) ;
@@ -92,38 +91,38 @@ describe('168. soda4.js', () => {
92
91
}
93
92
} ) ; // 168.1
94
93
95
- // ORA-40665: A client-assigned key cannot be used for this operation.
96
- it . skip ( '168.2 customize the key value' , async ( ) => {
97
- let conn ;
94
+ it ( '168.2 cannot customize the key value without metadata setting' , async ( ) => {
95
+ let conn , coll ;
98
96
try {
99
97
conn = await oracledb . getConnection ( dbconfig ) ;
100
98
let sd = conn . getSodaDatabase ( ) ;
101
99
let collectionName = 'soda_test_168_2' ;
102
- let coll = await sd . createCollection ( collectionName ) ;
100
+ coll = await sd . createCollection ( collectionName ) ;
103
101
104
102
// Insert a new document
105
103
let testContent = {
106
104
name : "Shelly" ,
107
105
address : { city : "Shenzhen" , country : "China" }
108
106
} ;
109
107
let testKey = "86755" ;
110
- let testDoc = await sd . createDocument ( testContent , { key : testKey } ) ;
108
+ let testDoc = sd . createDocument ( testContent , { key : testKey } ) ;
111
109
should . exist ( testDoc ) ;
112
- console . log ( testDoc ) ;
113
110
await coll . insertOne ( testDoc ) ;
114
111
115
- // Fetch it back
116
- let doc2 = await coll . find ( ) . key ( testKey ) . getOne ( ) ;
117
- let content2 = doc2 . getContent ( ) ;
118
- console . log ( content2 ) ;
119
-
120
- await conn . commit ( ) ;
121
- let res = await coll . drop ( ) ;
122
- should . strictEqual ( res . dropped , true ) ;
123
-
124
112
} catch ( err ) {
125
- should . not . exist ( err ) ;
113
+ should . exist ( err ) ;
114
+ ( err . message ) . should . startWith ( 'ORA-40665:' ) ;
115
+ // ORA-40665: A client-assigned key cannot be used for this operation.
126
116
} finally {
117
+ if ( coll ) {
118
+ try {
119
+ let res = await coll . drop ( ) ;
120
+ should . strictEqual ( res . dropped , true ) ;
121
+ } catch ( err ) {
122
+ should . not . exist ( err ) ;
123
+ }
124
+ }
125
+
127
126
if ( conn ) {
128
127
try {
129
128
await conn . close ( ) ;
@@ -143,6 +142,7 @@ describe('168. soda4.js', () => {
143
142
let coll = await sd . createCollection ( collectionName ) ;
144
143
145
144
// Insert a new document
145
+ // Content is empty
146
146
let testContent = { } ;
147
147
148
148
let myDoc = await coll . insertOneAndGet ( testContent ) ;
@@ -173,4 +173,85 @@ describe('168. soda4.js', () => {
173
173
}
174
174
} ) ; // 168.3
175
175
176
+ it ( '168.4 customize the key value' , async ( ) => {
177
+ let conn ;
178
+ try {
179
+ conn = await oracledb . getConnection ( dbconfig ) ;
180
+ let sd = conn . getSodaDatabase ( ) ;
181
+ let collectionName = 'soda_test_168_4' ;
182
+ let testMetaData = {
183
+ "schemaName" : dbconfig . user . toUpperCase ( ) ,
184
+ "tableName" : collectionName ,
185
+ "keyColumn" :
186
+ {
187
+ "name" : "ID" ,
188
+ "sqlType" : "NUMBER" ,
189
+ "assignmentMethod" : "CLIENT"
190
+ } ,
191
+ "contentColumn" :
192
+ {
193
+ "name" : "JSON_DOCUMENTS" ,
194
+ "sqlType" : "BLOB" ,
195
+ "compress" : "NONE" ,
196
+ "cache" : true ,
197
+ "encrypt" : "NONE" ,
198
+ "validation" : "STRICT"
199
+ } ,
200
+ "versionColumn" :
201
+ {
202
+ "name" : "VERSION" ,
203
+ "type" :"String" ,
204
+ "method" :"SHA256"
205
+ } ,
206
+ "lastModifiedColumn" :
207
+ {
208
+ "name" :"LAST_MODIFIED"
209
+ } ,
210
+ "creationTimeColumn" :
211
+ {
212
+ "name" :"CREATED_ON"
213
+ } ,
214
+ "readOnly" : false
215
+ } ;
216
+
217
+ let coll = await sd . createCollection ( collectionName , { metaData : testMetaData } ) ;
218
+
219
+ let testContent = {
220
+ name : "Shelly" ,
221
+ address : { city : "Shenzhen" , country : "China" }
222
+ } ;
223
+
224
+ /* The key must always be a string and is always returned a string as
225
+ well -- even if the "type" in the database is numeric. */
226
+ let testKey = '86755' ;
227
+ let testDoc = sd . createDocument ( testContent , { key : testKey } ) ;
228
+ should . strictEqual ( testDoc . key , testKey ) ;
229
+ await coll . insertOne ( testDoc ) ;
230
+
231
+ // Fetch it back
232
+ let docGot = await coll . find ( ) . key ( testKey ) . getOne ( ) ;
233
+ let contentGot = docGot . getContent ( ) ;
234
+ should . strictEqual ( contentGot . name , testContent . name ) ;
235
+ should . strictEqual (
236
+ contentGot . address . country ,
237
+ testContent . address . country
238
+ ) ;
239
+
240
+ await conn . commit ( ) ;
241
+ let res = await coll . drop ( ) ;
242
+ should . strictEqual ( res . dropped , true ) ;
243
+
244
+ } catch ( err ) {
245
+ should . not . exist ( err ) ;
246
+ } finally {
247
+ if ( conn ) {
248
+ try {
249
+ await conn . close ( ) ;
250
+ } catch ( err ) {
251
+ should . not . exist ( err ) ;
252
+ }
253
+ }
254
+ }
255
+ } ) ; // 168.4
256
+
176
257
} ) ;
0 commit comments