Skip to content

Commit 147dd0f

Browse files
committed
Create the test file for SODA bulk insert
1 parent 1e72738 commit 147dd0f

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

test/soda10.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
19+
* See LICENSE.md for relevant licenses.
20+
*
21+
* NAME
22+
* 178. soda10.js
23+
*
24+
* DESCRIPTION
25+
* Test Soda Bulk insertion methods.
26+
*
27+
*****************************************************************************/
28+
'use strict';
29+
30+
const oracledb = require('oracledb');
31+
const should = require('should');
32+
const dbconfig = require('./dbconfig.js');
33+
const sodaUtil = require('./sodaUtil.js');
34+
const testsUtil = require('./testsUtil.js');
35+
36+
describe('178. soda10.js', () => {
37+
38+
let conn;
39+
40+
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+
}
50+
51+
} catch (err) {
52+
should.not.exist(err);
53+
}
54+
}); // before()
55+
56+
after(async() => {
57+
try {
58+
59+
await conn.close();
60+
} catch (err) {
61+
should.not.exist(err);
62+
}
63+
}); // after()
64+
65+
it('178.1 basic case of sodaCollection.insertMany()', async () => {
66+
try {
67+
let soda = conn.getSodaDatabase();
68+
const COLL = "soda_test_178_1";
69+
const collection = await soda.createCollection(COLL);
70+
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+
];
77+
let inDocuments = [];
78+
for (let i = 0; i < inContents.length; i++) {
79+
inDocuments[i] = soda.createDocument(inContents[i]); // n.b. synchronous method
80+
}
81+
82+
await collection.insertMany(inDocuments);
83+
84+
// Fetch back
85+
let outDocuments = await collection.find().getDocuments();
86+
let outContents = [];
87+
for (let i = 0; i < outDocuments.length; i++) {
88+
outContents[i] = outDocuments[i].getContent(); // n.b. synchronous method
89+
}
90+
91+
should.deepEqual(outContents, inContents);
92+
93+
await conn.commit();
94+
95+
let res = await collection.drop();
96+
should.strictEqual(res.dropped, true);
97+
} catch (err) {
98+
should.not.exist(err);
99+
}
100+
}); // 178.1
101+
});

0 commit comments

Comments
 (0)