Skip to content

Commit 63c7ce9

Browse files
committed
Add tests for option object of SODA dropIndex()
1 parent aaf2a74 commit 63c7ce9

File tree

2 files changed

+90
-22
lines changed

2 files changed

+90
-22
lines changed

test/list.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4253,4 +4253,6 @@ Overview of node-oracledb functional tests
42534253
173.7 dropIndex(), basic case
42544254
173.8 dropping index does not impact query
42554255
173.9 The index is dropped regardless of the auto commit mode
4256-
173.10 Negative - dropIndex() no parameter
4256+
173.10 Negative - dropIndex() no parameter
4257+
173.11 option object of dropIndex(), basic case
4258+
173.12 option object of dropIndex(), boolean value is false

test/soda5.js

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ const should = require('should');
3232
const dbconfig = require('./dbconfig.js');
3333
const sodaUtil = require('./sodaUtil.js');
3434

35+
const t_contents = [
36+
{ id: 1001, name: "Gillian", office: "Shenzhen" },
37+
{ id: 1002, name: "Chris", office: "Melbourne" },
38+
{ id: 1003, name: "Changjie", office: "Shenzhen" },
39+
{ id: 1004, name: "Venkat", office: "Bangalore" },
40+
{ id: 1005, name: "May", office: "London" },
41+
{ id: 1006, name: "Joe", office: "San Francisco" },
42+
{ id: 1007, name: "Gavin", office: "New York" }
43+
];
44+
3545
describe('173. soda5.js', () => {
36-
37-
const t_contents = [
38-
{ id: 1001, name: "Gillian", office: "Shenzhen" },
39-
{ id: 1002, name: "Chris", office: "Melbourne" },
40-
{ id: 1003, name: "Changjie", office: "Shenzhen" },
41-
{ id: 1004, name: "Venkat", office: "Bangalore" },
42-
{ id: 1005, name: "May", office: "London" },
43-
{ id: 1006, name: "Joe", office: "San Francisco" },
44-
{ id: 1007, name: "Gavin", office: "New York" }
45-
];
4646

4747
before(async function() {
4848
const runnable = await sodaUtil.checkPrerequisites();
@@ -76,7 +76,7 @@ describe('173. soda5.js', () => {
7676
return collection.insertOne(content);
7777
})
7878
);
79-
79+
8080
// Fetch back
8181
let empInShenzhen = await collection.find()
8282
.filter({ "office": {"$like": "Shenzhen"} })
@@ -141,13 +141,13 @@ describe('173. soda5.js', () => {
141141
} catch(err) {
142142
should.not.exist(err);
143143
}
144-
144+
145145
try {
146146
await conn.commit();
147-
}
147+
}
148148
catch(err) {
149149
should.not.exist(err);
150-
}
150+
}
151151

152152
if (collection) {
153153
let res = await collection.drop();
@@ -169,7 +169,7 @@ describe('173. soda5.js', () => {
169169

170170
let soda = conn.getSodaDatabase();
171171
collection = await soda.createCollection("soda_test_173_3");
172-
172+
173173
} catch(err) {
174174
should.not.exist(err);
175175
}
@@ -204,7 +204,7 @@ describe('173. soda5.js', () => {
204204

205205
let soda = conn.getSodaDatabase();
206206
collection = await soda.createCollection("soda_test_173_4");
207-
207+
208208
} catch(err) {
209209
should.not.exist(err);
210210
}
@@ -312,7 +312,7 @@ describe('173. soda5.js', () => {
312312
return collection.insertOne(content);
313313
})
314314
);
315-
315+
316316
// Fetch back
317317
let empInShenzhen = await collection.find()
318318
.filter({ "office": {"$like": "Shenzhen"} })
@@ -371,7 +371,7 @@ describe('173. soda5.js', () => {
371371
// drop index
372372
let indexName = indexSpec.name;
373373
await collection.dropIndex(indexName);
374-
374+
375375
// Fetch back
376376
let empInShenzhen = await collection.find()
377377
.filter({ "office": {"$like": "Shenzhen"} })
@@ -422,7 +422,7 @@ describe('173. soda5.js', () => {
422422
return collection.insertOne(content);
423423
})
424424
);
425-
425+
426426
// Fetch back
427427
let empInShenzhen = await collection.find()
428428
.filter({ "office": {"$like": "Shenzhen"} })
@@ -478,7 +478,7 @@ describe('173. soda5.js', () => {
478478
return collection.insertOne(content);
479479
})
480480
);
481-
481+
482482
// Fetch back
483483
let empInShenzhen = await collection.find()
484484
.filter({ "office": {"$like": "Shenzhen"} })
@@ -510,4 +510,70 @@ describe('173. soda5.js', () => {
510510
}
511511
}
512512
}); // 173.10
513-
});
513+
514+
it('173.11 option object of dropIndex(), basic case', async () => {
515+
let options = { "force" : true };
516+
await dropIdxOpt(options);
517+
}); // 173.11
518+
519+
it('173.12 option object of dropIndex(), boolean value is false', async () => {
520+
let options = { "force" : false };
521+
await dropIdxOpt(options);
522+
}); // 173.12
523+
524+
});
525+
526+
const dropIdxOpt = async function(opts) {
527+
let conn, collection;
528+
try {
529+
conn = await oracledb.getConnection(dbconfig);
530+
531+
let soda = conn.getSodaDatabase();
532+
collection = await soda.createCollection("soda_test_173_7");
533+
534+
let indexSpec = {
535+
"name": "OFFICE_IDX",
536+
"fields": [
537+
{
538+
"path": "office",
539+
"datatype": "string",
540+
"order": "asc"
541+
}
542+
]
543+
};
544+
await collection.createIndex(indexSpec);
545+
546+
await Promise.all(
547+
t_contents.map(function(content) {
548+
return collection.insertOne(content);
549+
})
550+
);
551+
552+
// Fetch back
553+
let empInShenzhen = await collection.find()
554+
.filter({ "office": {"$like": "Shenzhen"} })
555+
.count();
556+
should.strictEqual(empInShenzhen.count, 2);
557+
558+
// drop index
559+
let indexName = indexSpec.name;
560+
await collection.dropIndex(indexName, opts);
561+
562+
await conn.commit();
563+
564+
} catch(err) {
565+
should.noConflict.exist(err);
566+
} finally {
567+
if (collection) {
568+
let res = await collection.drop();
569+
should.strictEqual(res.dropped, true);
570+
}
571+
if (conn) {
572+
try {
573+
await conn.close();
574+
} catch(err) {
575+
should.not.exist(err);
576+
}
577+
}
578+
}
579+
};

0 commit comments

Comments
 (0)