Skip to content

Commit 5447f06

Browse files
committed
SODA test customizing document key
1 parent 8333482 commit 5447f06

File tree

2 files changed

+103
-21
lines changed

2 files changed

+103
-21
lines changed

test/list.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,9 +4208,10 @@ Overview of node-oracledb functional tests
42084208
167.16 the requested collection name is case sensitive
42094209

42104210
168. soda4.js
4211-
168.1 insertOneAndGet() method
4212-
168.2 customize the key value
4211+
168.1 insertOneAndGet() fetches attributes without content
4212+
168.2 cannot customize the key value without metadata setting
42134213
168.3 content is null
4214+
168.4 customize the key value
42144215

42154216
170. poolDrain.js
42164217
170.1 close pool with force flag, and prevent new connection

test/soda4.js

Lines changed: 100 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('168. soda4.js', () => {
4141
await sodaUtil.cleanup();
4242
});
4343

44-
it.skip('168.1 insertOneAndGet() method', async () => {
44+
it('168.1 insertOneAndGet() fetches attributes without content', async () => {
4545
let conn;
4646
try {
4747
conn = await oracledb.getConnection(dbconfig);
@@ -65,8 +65,7 @@ describe('168. soda4.js', () => {
6565
(myDoc).should.be.an.Object();
6666

6767
let content1 = myDoc.getContent();
68-
console.log("getContent()");
69-
console.log(content1);
68+
should.not.exist(content1);
7069

7170
// Fetch it back
7271
let doc2 = await coll.find().key(myKey).getOne();
@@ -92,38 +91,38 @@ describe('168. soda4.js', () => {
9291
}
9392
}); // 168.1
9493

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;
9896
try {
9997
conn = await oracledb.getConnection(dbconfig);
10098
let sd = conn.getSodaDatabase();
10199
let collectionName = 'soda_test_168_2';
102-
let coll = await sd.createCollection(collectionName);
100+
coll = await sd.createCollection(collectionName);
103101

104102
// Insert a new document
105103
let testContent = {
106104
name: "Shelly",
107105
address: {city: "Shenzhen", country: "China"}
108106
};
109107
let testKey = "86755";
110-
let testDoc = await sd.createDocument(testContent, { key: testKey} );
108+
let testDoc = sd.createDocument(testContent, { key: testKey} );
111109
should.exist(testDoc);
112-
console.log(testDoc);
113110
await coll.insertOne(testDoc);
114111

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-
124112
} 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.
126116
} 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+
127126
if (conn) {
128127
try {
129128
await conn.close();
@@ -143,6 +142,7 @@ describe('168. soda4.js', () => {
143142
let coll = await sd.createCollection(collectionName);
144143

145144
// Insert a new document
145+
// Content is empty
146146
let testContent = {};
147147

148148
let myDoc = await coll.insertOneAndGet(testContent);
@@ -173,4 +173,85 @@ describe('168. soda4.js', () => {
173173
}
174174
}); // 168.3
175175

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+
176257
});

0 commit comments

Comments
 (0)