Skip to content

Commit d0b4a10

Browse files
committed
Add tests for soda bulk insert
1 parent e1cebf8 commit d0b4a10

File tree

3 files changed

+123
-31
lines changed

3 files changed

+123
-31
lines changed

test/list.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4309,6 +4309,13 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
43094309
177.4 insertOneAndGet() with a document
43104310
177.5 createDocument() followd by getContent() i.e. without being inserted
43114311

4312+
178. soda10.js
4313+
178.1 insertMany() with newSodaDocumentArray
4314+
178.2 insertMany() with newSodaDocumentContentArray
4315+
178.3 insertManyAndGet() with newDocumentArray
4316+
178.4 insertManyAndGet() with newDocumentContentArray
4317+
- 174.5 Negative - insertMany() with empty array
4318+
43124319
179. soda11.js
43134320
179.1 create collection with metadata
43144321
179.2 Negative - create collection with an invalid metadata

test/opts/mocha.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ test/soda6.js
203203
test/soda7.js
204204
test/soda8.js
205205
test/soda9.js
206+
test/soda10.js
206207
test/soda11.js
207208
test/externalProxyAuth.js
208209

test/soda10.js

Lines changed: 115 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,49 @@ const testsUtil = require('./testsUtil.js');
3535

3636
describe('178. soda10.js', () => {
3737

38+
let runnable;
3839
let conn, soda;
3940

4041
before(async function() {
41-
try {
42-
const runnable = await testsUtil.checkPrerequisites();
43-
if (!runnable) {
44-
this.skip();
45-
return;
46-
} else {
47-
await sodaUtil.cleanup();
48-
conn = await oracledb.getConnection(dbconfig);
49-
soda = conn.getSodaDatabase();
50-
}
5142

52-
} catch (err) {
53-
should.not.exist(err);
43+
const runnable = await testsUtil.checkPrerequisites();
44+
45+
if (!runnable) {
46+
this.skip();
47+
return;
48+
} else {
49+
conn = await oracledb.getConnection(dbconfig);
50+
soda = conn.getSodaDatabase();
5451
}
52+
53+
await sodaUtil.cleanup();
54+
5555
}); // before()
5656

57-
after(async() => {
57+
after(async function() {
58+
if (!runnable) {
59+
this.skip();
60+
return;
61+
}
5862
try {
59-
6063
await conn.close();
6164
} catch (err) {
6265
should.not.exist(err);
6366
}
6467
}); // after()
6568

66-
it('178.1 basic case of sodaCollection.insertMany()', async () => {
69+
const inContents = [
70+
{ id: 1, name: "Paul", office: "Singapore" },
71+
{ id: 2, name: "Emma", office: "London" },
72+
{ id: 3, name: "Kate", office: "Edinburgh" },
73+
{ id: 4, name: "Changjie", office: "Shenzhen" }
74+
];
75+
76+
it('178.1 insertMany() with newSodaDocumentArray', async () => {
6777
try {
6878
const COLL = "soda_test_178_1";
6979
const collection = await soda.createCollection(COLL);
7080

71-
let inContents = [
72-
{ id: 1, name: "Paul", office: "Singapore" },
73-
{ id: 2, name: "Emma", office: "London" },
74-
{ id: 3, name: "Kate", office: "Edinburgh" },
75-
{ id: 4, name: "Changjie", office: "Shenzhen" }
76-
];
7781
let inDocuments = [];
7882
for (let i = 0; i < inContents.length; i++) {
7983
inDocuments[i] = soda.createDocument(inContents[i]); // n.b. synchronous method
@@ -99,17 +103,36 @@ describe('178. soda10.js', () => {
99103
}
100104
}); // 178.1
101105

102-
it.skip('178.2 basic case of sodaCollection.insertManyAndGet()', async () => {
106+
it('178.2 insertMany() with newSodaDocumentContentArray', async () => {
103107
try {
104108
const COLL = "soda_test_178_2";
105109
const collection = await soda.createCollection(COLL);
106110

107-
let inContents = [
108-
{ id: 1, name: "Paul", office: "Singapore" },
109-
{ id: 2, name: "Emma", office: "London" },
110-
{ id: 3, name: "Kate", office: "Edinburgh" },
111-
{ id: 4, name: "Changjie", office: "Shenzhen" }
112-
];
111+
await collection.insertMany(inContents);
112+
113+
// Fetch back
114+
let outDocuments = await collection.find().getDocuments();
115+
let outContents = [];
116+
for (let i = 0; i < outDocuments.length; i++) {
117+
outContents[i] = outDocuments[i].getContent(); // n.b. synchronous method
118+
}
119+
120+
should.deepEqual(outContents, inContents);
121+
122+
await conn.commit();
123+
124+
let res = await collection.drop();
125+
should.strictEqual(res.dropped, true);
126+
} catch (err) {
127+
should.not.exist(err);
128+
}
129+
}); // 178.2
130+
131+
it('178.3 insertManyAndGet() with newDocumentArray', async () => {
132+
try {
133+
const COLL = "soda_test_178_3";
134+
const collection = await soda.createCollection(COLL);
135+
113136
let inDocuments = [];
114137
for (let i = 0; i < inContents.length; i++) {
115138
inDocuments[i] = soda.createDocument(inContents[i]); // n.b. synchronous method
@@ -118,9 +141,68 @@ describe('178. soda10.js', () => {
118141
let middleDocuments = await collection.insertManyAndGet(inDocuments);
119142
let middleContents = [];
120143
for (let i = 0; i < middleDocuments.length; i++) {
121-
middleContents[i] = middleDocuments[i].getContent(); // n.b. synchronous method
144+
middleContents[i] = middleDocuments[i].getContent();
145+
should.exist(middleDocuments[i].key);
122146
}
123-
console.log(middleContents);
147+
should.deepEqual(middleContents, [null, null, null, null]);
148+
149+
// Fetch back
150+
let outDocuments = await collection.find().getDocuments();
151+
let outContents = [];
152+
for (let i = 0; i < outDocuments.length; i++) {
153+
outContents[i] = outDocuments[i].getContent(); // n.b. synchronous method
154+
}
155+
156+
should.deepEqual(outContents, inContents);
157+
158+
await conn.commit();
159+
160+
let res = await collection.drop();
161+
should.strictEqual(res.dropped, true);
162+
} catch (err) {
163+
should.not.exist(err);
164+
}
165+
}); // 178.3
166+
167+
it('178.4 insertManyAndGet() with newDocumentContentArray', async () => {
168+
try {
169+
const COLL = "soda_test_178_4";
170+
const collection = await soda.createCollection(COLL);
171+
172+
let middleDocuments = await collection.insertManyAndGet(inContents);
173+
let middleContents = [];
174+
for (let i = 0; i < middleDocuments.length; i++) {
175+
middleContents[i] = middleDocuments[i].getContent();
176+
should.exist(middleDocuments[i].key);
177+
}
178+
should.deepEqual(middleContents, [null, null, null, null]);
179+
180+
// Fetch back
181+
let outDocuments = await collection.find().getDocuments();
182+
let outContents = [];
183+
for (let i = 0; i < outDocuments.length; i++) {
184+
outContents[i] = outDocuments[i].getContent(); // n.b. synchronous method
185+
}
186+
187+
should.deepEqual(outContents, inContents);
188+
189+
await conn.commit();
190+
191+
let res = await collection.drop();
192+
should.strictEqual(res.dropped, true);
193+
} catch (err) {
194+
should.not.exist(err);
195+
}
196+
}); // 178.4
197+
198+
it.skip('174.5 Negative - insertMany() with empty array', async () => {
199+
try {
200+
const COLL = "soda_test_178_5";
201+
const collection = await soda.createCollection(COLL);
202+
203+
// ORA-40673: arrayLength argument cannot be NULL.
204+
let inDocuments = [];
205+
await collection.insertMany(inDocuments);
124206

125207
// Fetch back
126208
let outDocuments = await collection.find().getDocuments();
@@ -130,6 +212,7 @@ describe('178. soda10.js', () => {
130212
}
131213

132214
console.log(outContents);
215+
// should.deepEqual(outContents, inContents);
133216

134217
await conn.commit();
135218

@@ -138,5 +221,6 @@ describe('178. soda10.js', () => {
138221
} catch (err) {
139222
should.not.exist(err);
140223
}
141-
}); // 178.2
224+
}); // 174.5
225+
142226
});

0 commit comments

Comments
 (0)