Skip to content

Commit b60211e

Browse files
committed
Test SODA mediaType and key attributes
1 parent abc2c66 commit b60211e

File tree

2 files changed

+299
-2
lines changed

2 files changed

+299
-2
lines changed

test/list.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4212,7 +4212,11 @@ Overview of node-oracledb functional tests
42124212
168.1 insertOneAndGet() fetches attributes without content
42134213
168.2 cannot customize the key value without metadata setting
42144214
168.3 content is null
4215-
168.4 customize the key value
4215+
168.4 customize the key value, String value
4216+
168.5 Negative - customize the key value, numeric value
4217+
168.6 get mediaType
4218+
168.7 customize the value of mediaType
4219+
168.8 Negative - customize mediaType, invalide type, numeric value
42164220

42174221
170. poolDrain.js
42184222
170.1 close pool with force flag, and prevent new connection

test/soda4.js

Lines changed: 294 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('168. soda4.js', () => {
173173
}
174174
}); // 168.3
175175

176-
it('168.4 customize the key value', async () => {
176+
it('168.4 customize the key value, String value', async () => {
177177
let conn;
178178
try {
179179
conn = await oracledb.getConnection(dbconfig);
@@ -254,4 +254,297 @@ describe('168. soda4.js', () => {
254254
}
255255
}); // 168.4
256256

257+
// A variation of 168.4
258+
it('168.5 Negative - customize the key value, numeric value', async () => {
259+
let conn, coll;
260+
try {
261+
conn = await oracledb.getConnection(dbconfig);
262+
let sd = conn.getSodaDatabase();
263+
let collectionName = 'soda_test_168_5';
264+
let testMetaData = {
265+
"schemaName" : dbconfig.user.toUpperCase(),
266+
"tableName" : collectionName,
267+
"keyColumn" :
268+
{
269+
"name" : "ID",
270+
"sqlType" : "NUMBER",
271+
"assignmentMethod" : "CLIENT"
272+
},
273+
"contentColumn" :
274+
{
275+
"name" : "JSON_DOCUMENTS",
276+
"sqlType" : "BLOB",
277+
"compress" : "NONE",
278+
"cache" : true,
279+
"encrypt" : "NONE",
280+
"validation" : "STRICT"
281+
},
282+
"versionColumn" :
283+
{
284+
"name" : "VERSION",
285+
"type":"String",
286+
"method":"SHA256"
287+
},
288+
"lastModifiedColumn" :
289+
{
290+
"name":"LAST_MODIFIED"
291+
},
292+
"creationTimeColumn":
293+
{
294+
"name":"CREATED_ON"
295+
},
296+
"readOnly": false
297+
};
298+
299+
coll = await sd.createCollection(collectionName, { metaData: testMetaData});
300+
301+
let testContent = {
302+
name: "Shelly",
303+
address: {city: "Shenzhen", country: "China"}
304+
};
305+
306+
/* The key must always be a string and is always returned a string as
307+
well -- even if the "type" in the database is numeric. */
308+
let testKey = 86755;
309+
sd.createDocument(testContent, { key: testKey } );
310+
311+
} catch(err) {
312+
should.exist(err);
313+
should.strictEqual(
314+
err.message,
315+
'NJS-008: invalid type for "key" in parameter 2'
316+
);
317+
} finally {
318+
if (coll) {
319+
try {
320+
let res = await coll.drop();
321+
should.strictEqual(res.dropped, true);
322+
} catch(err) {
323+
should.not.exist(err);
324+
}
325+
}
326+
327+
if (conn) {
328+
try {
329+
await conn.close();
330+
} catch(err) {
331+
should.not.exist(err);
332+
}
333+
}
334+
}
335+
}); // 168.5
336+
337+
it('168.6 get mediaType', async () => {
338+
let conn;
339+
try {
340+
conn = await oracledb.getConnection(dbconfig);
341+
let sd = conn.getSodaDatabase();
342+
let collectionName = 'soda_test_168_6';
343+
let coll = await sd.createCollection(collectionName);
344+
345+
// Insert a new document
346+
// Content is empty
347+
let testContent = {};
348+
349+
let myDoc = await coll.insertOneAndGet(testContent);
350+
let myMediaType = myDoc.mediaType;
351+
should.exist(myMediaType);
352+
should.strictEqual(myMediaType, 'application/json');
353+
let myKey = myDoc.key;
354+
355+
// Fetch it back
356+
let doc2 = await coll.find().key(myKey).getOne();
357+
should.strictEqual(doc2.mediaType, 'application/json');
358+
359+
await conn.commit();
360+
let res = await coll.drop();
361+
should.strictEqual(res.dropped, true);
362+
363+
} catch(err) {
364+
should.not.exist(err);
365+
} finally {
366+
if (conn) {
367+
try {
368+
await conn.close();
369+
} catch(err) {
370+
should.not.exist(err);
371+
}
372+
}
373+
}
374+
}); // 168.6
375+
376+
it('168.7 customize the value of mediaType', async () => {
377+
let conn, coll;
378+
try {
379+
conn = await oracledb.getConnection(dbconfig);
380+
let sd = conn.getSodaDatabase();
381+
let collectionName = 'soda_test_168_7';
382+
let testMetaData = {
383+
"schemaName" : dbconfig.user.toUpperCase(),
384+
"tableName" : collectionName,
385+
"keyColumn" :
386+
{
387+
"name" : "ID",
388+
"sqlType" : "NUMBER",
389+
"assignmentMethod" : "CLIENT"
390+
},
391+
"mediaTypeColumn":
392+
{
393+
"name": "MediaType"
394+
},
395+
"contentColumn" :
396+
{
397+
"name" : "DOCUMENT",
398+
"sqlType" : "BLOB",
399+
"compress" : "NONE",
400+
"cache" : true,
401+
"encrypt" : "NONE",
402+
"validation" : "STRICT"
403+
},
404+
"versionColumn" :
405+
{
406+
"name" : "VERSION",
407+
"type":"String",
408+
"method":"SHA256"
409+
},
410+
"lastModifiedColumn" :
411+
{
412+
"name":"LAST_MODIFIED"
413+
},
414+
"creationTimeColumn":
415+
{
416+
"name":"CREATED_ON"
417+
},
418+
"readOnly": false
419+
};
420+
421+
coll = await sd.createCollection(collectionName, { metaData: testMetaData});
422+
423+
// Insert a new document
424+
let testContent = {};
425+
let testMediaType = 'image/png';
426+
let testKey = '86755';
427+
let testDoc = sd.createDocument(
428+
testContent,
429+
{ mediaType: testMediaType, key: testKey }
430+
);
431+
should.strictEqual(testDoc.mediaType, testMediaType);
432+
433+
let myKey = testDoc.key;
434+
435+
await coll.insertOne(testDoc);
436+
437+
// Fetch the document back
438+
let myDoc = await coll.find().key(myKey).getOne();
439+
440+
should.strictEqual(myDoc.mediaType, testMediaType);
441+
442+
} catch(err) {
443+
should.not.exist(err);
444+
} finally {
445+
await conn.commit();
446+
if (coll) {
447+
try {
448+
let res = await coll.drop();
449+
should.strictEqual(res.dropped, true);
450+
} catch(err) {
451+
should.not.exist(err);
452+
}
453+
}
454+
455+
if (conn) {
456+
try {
457+
await conn.close();
458+
} catch(err) {
459+
should.not.exist(err);
460+
}
461+
}
462+
}
463+
}); // 168.7
464+
465+
it('168.8 Negative - customize mediaType, invalide type, numeric value', async () => {
466+
let conn, coll;
467+
try {
468+
conn = await oracledb.getConnection(dbconfig);
469+
let sd = conn.getSodaDatabase();
470+
let collectionName = 'soda_test_168_7';
471+
let testMetaData = {
472+
"schemaName" : dbconfig.user.toUpperCase(),
473+
"tableName" : collectionName,
474+
"keyColumn" :
475+
{
476+
"name" : "ID",
477+
"sqlType" : "NUMBER",
478+
"assignmentMethod" : "CLIENT"
479+
},
480+
"mediaTypeColumn":
481+
{
482+
"name": "MediaType"
483+
},
484+
"contentColumn" :
485+
{
486+
"name" : "DOCUMENT",
487+
"sqlType" : "BLOB",
488+
"compress" : "NONE",
489+
"cache" : true,
490+
"encrypt" : "NONE",
491+
"validation" : "STRICT"
492+
},
493+
"versionColumn" :
494+
{
495+
"name" : "VERSION",
496+
"type":"String",
497+
"method":"SHA256"
498+
},
499+
"lastModifiedColumn" :
500+
{
501+
"name":"LAST_MODIFIED"
502+
},
503+
"creationTimeColumn":
504+
{
505+
"name":"CREATED_ON"
506+
},
507+
"readOnly": false
508+
};
509+
510+
coll = await sd.createCollection(collectionName, { metaData: testMetaData});
511+
512+
// Insert a new document
513+
let testContent = {};
514+
515+
/* Negative value */
516+
let testMediaType = 65432;
517+
let testKey = '86755';
518+
sd.createDocument(
519+
testContent,
520+
{ mediaType: testMediaType, key: testKey }
521+
);
522+
523+
} catch(err) {
524+
should.exist(err);
525+
should.strictEqual(
526+
err.message,
527+
'NJS-008: invalid type for "mediaType" in parameter 2'
528+
);
529+
} finally {
530+
await conn.commit();
531+
if (coll) {
532+
try {
533+
let res = await coll.drop();
534+
should.strictEqual(res.dropped, true);
535+
} catch(err) {
536+
should.not.exist(err);
537+
}
538+
}
539+
540+
if (conn) {
541+
try {
542+
await conn.close();
543+
} catch(err) {
544+
should.not.exist(err);
545+
}
546+
}
547+
}
548+
}); // 168.8
549+
257550
});

0 commit comments

Comments
 (0)