Update SODA index tests
This commit is contained in:
parent
1709700c08
commit
231e187e38
|
@ -202,3 +202,4 @@ test/soda5.js
|
|||
test/soda6.js
|
||||
test/soda7.js
|
||||
test/soda8.js
|
||||
test/soda9.js
|
||||
|
|
|
@ -353,23 +353,26 @@ describe('164. soda1.js', () => {
|
|||
}); // 164.9
|
||||
|
||||
it('164.10 create index', async () => {
|
||||
let conn;
|
||||
let conn, coll;
|
||||
const indexName = "soda_index_164_10";
|
||||
try {
|
||||
conn = await oracledb.getConnection(dbconfig);
|
||||
let sd = conn.getSodaDatabase();
|
||||
let collectionName = 'soda_test_164_10';
|
||||
let coll = await sd.createCollection(collectionName);
|
||||
coll = await sd.createCollection(collectionName);
|
||||
|
||||
var index =
|
||||
{
|
||||
name : "nameIndex",
|
||||
name : indexName,
|
||||
fields : [ { path: "name" }]
|
||||
};
|
||||
|
||||
await coll.createIndex(index);
|
||||
|
||||
await conn.commit();
|
||||
await coll.dropIndex(indexName);
|
||||
await coll.drop();
|
||||
await conn.commit();
|
||||
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
} finally {
|
||||
|
@ -455,6 +458,8 @@ describe('164. soda1.js', () => {
|
|||
let res3 = await collection.find().count();
|
||||
should.strictEqual(res3.count, 2);
|
||||
|
||||
await collection.dropIndex("CITY_IDX");
|
||||
|
||||
// Commit changes
|
||||
await conn.commit();
|
||||
|
||||
|
|
|
@ -0,0 +1,224 @@
|
|||
/* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* The node-oracledb test suite uses 'mocha', 'should' and 'async'.
|
||||
* See LICENSE.md for relevant licenses.
|
||||
*
|
||||
* NAME
|
||||
* 177. soda9.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* sodaCollection Class
|
||||
*
|
||||
*****************************************************************************/
|
||||
'use strict';
|
||||
|
||||
const oracledb = require('oracledb');
|
||||
const should = require('should');
|
||||
const dbconfig = require('./dbconfig.js');
|
||||
const sodaUtil = require('./sodaUtil.js');
|
||||
|
||||
describe('177. soda9.js', () => {
|
||||
|
||||
before(async function() {
|
||||
const runnable = await sodaUtil.checkPrerequisites();
|
||||
if (!runnable) this.skip();
|
||||
|
||||
await sodaUtil.cleanup();
|
||||
});
|
||||
|
||||
it('177.1 insertOne() with a document content', async () => {
|
||||
let conn, collection;
|
||||
|
||||
try {
|
||||
conn = await oracledb.getConnection(dbconfig);
|
||||
let soda = conn.getSodaDatabase();
|
||||
collection = await soda.createCollection("soda_test_177_1");
|
||||
let inContent = { id: 2000, name: "Paul", office: "Singapore" };
|
||||
await collection.insertOne(inContent);
|
||||
|
||||
// fetch back
|
||||
let outDocuments = await collection.find().getDocuments();
|
||||
let outContent = await outDocuments[0].getContent();
|
||||
should.deepEqual(outContent, inContent);
|
||||
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
} finally {
|
||||
await conn.commit();
|
||||
|
||||
if (collection) {
|
||||
let res = await collection.drop();
|
||||
should.strictEqual(res.dropped, true);
|
||||
}
|
||||
|
||||
if (conn) {
|
||||
try {
|
||||
await conn.close();
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}); // 177.1
|
||||
|
||||
it('177.2 insertOne() with a document', async () => {
|
||||
let conn, collection;
|
||||
|
||||
try {
|
||||
conn = await oracledb.getConnection(dbconfig);
|
||||
let soda = conn.getSodaDatabase();
|
||||
collection = await soda.createCollection("soda_test_177_2");
|
||||
let inContent = { id: 2000, name: "Paul", office: "Singapore" };
|
||||
let inDocument = soda.createDocument(inContent);
|
||||
await collection.insertOne(inDocument);
|
||||
|
||||
// fetch back
|
||||
let outDocuments = await collection.find().getDocuments();
|
||||
let outContent = await outDocuments[0].getContent();
|
||||
should.deepEqual(outContent, inContent);
|
||||
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
} finally {
|
||||
await conn.commit();
|
||||
|
||||
if (collection) {
|
||||
let res = await collection.drop();
|
||||
should.strictEqual(res.dropped, true);
|
||||
}
|
||||
|
||||
if (conn) {
|
||||
try {
|
||||
await conn.close();
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}); // 177.2
|
||||
|
||||
it('177.3 insertOneAndGet() with a document content', async () => {
|
||||
let conn, collection;
|
||||
|
||||
try {
|
||||
conn = await oracledb.getConnection(dbconfig);
|
||||
let soda = conn.getSodaDatabase();
|
||||
collection = await soda.createCollection("soda_test_177_3");
|
||||
|
||||
let inContent = { id: 2000, name: "Paul", office: "Singapore" };
|
||||
let middleDocument = await collection.insertOneAndGet(inContent);
|
||||
should.exist(middleDocument);
|
||||
let middleContent = await middleDocument.getContent();
|
||||
should.not.exist(middleContent);
|
||||
|
||||
// Fetch it back
|
||||
let outDocuments = await collection.find().getDocuments();
|
||||
let outContent = await outDocuments[0].getContent();
|
||||
should.deepEqual(outContent, inContent);
|
||||
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
} finally {
|
||||
await conn.commit();
|
||||
|
||||
if (collection) {
|
||||
let res = await collection.drop();
|
||||
should.strictEqual(res.dropped, true);
|
||||
}
|
||||
|
||||
if (conn) {
|
||||
try {
|
||||
await conn.close();
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}); // 177.3
|
||||
|
||||
it('177.4 insertOneAndGet() with a document', async () => {
|
||||
let conn, collection;
|
||||
|
||||
try {
|
||||
conn = await oracledb.getConnection(dbconfig);
|
||||
let soda = conn.getSodaDatabase();
|
||||
collection = await soda.createCollection("soda_test_177_4");
|
||||
|
||||
let inContent = { id: 2000, name: "Paul", office: "Singapore" };
|
||||
let inDocument = soda.createDocument(inContent);
|
||||
let middleDocument = await collection.insertOneAndGet(inDocument);
|
||||
should.exist(middleDocument);
|
||||
let middleContent = await middleDocument.getContent();
|
||||
should.not.exist(middleContent);
|
||||
|
||||
// Fetch it back
|
||||
let outDocuments = await collection.find().getDocuments();
|
||||
let outContent = await outDocuments[0].getContent();
|
||||
should.deepEqual(outContent, inContent);
|
||||
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
} finally {
|
||||
await conn.commit();
|
||||
|
||||
if (collection) {
|
||||
let res = await collection.drop();
|
||||
should.strictEqual(res.dropped, true);
|
||||
}
|
||||
|
||||
if (conn) {
|
||||
try {
|
||||
await conn.close();
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}); // 177.4
|
||||
|
||||
it('177.5 createDocument() followd by getContent() i.e. without being inserted', async () => {
|
||||
|
||||
let conn;
|
||||
|
||||
try {
|
||||
conn = await oracledb.getConnection(dbconfig);
|
||||
let soda = conn.getSodaDatabase();
|
||||
|
||||
let inContent = { id: 2000, name: "Paul", office: "Singapore" };
|
||||
let inDocument = soda.createDocument(inContent);
|
||||
|
||||
// Get content without being inserted
|
||||
let outContent = await inDocument.getContent();
|
||||
should.deepEqual(outContent, inContent);
|
||||
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
} finally {
|
||||
await conn.commit();
|
||||
if (conn) {
|
||||
try {
|
||||
await conn.close();
|
||||
} catch(err) {
|
||||
should.not.exist(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}); // 177.5
|
||||
});
|
Loading…
Reference in New Issue