node-oracledb/test/soda3.js

192 lines
6.4 KiB
JavaScript
Raw Normal View History

2023-05-03 18:32:09 +08:00
/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. */
2018-09-30 20:25:54 +08:00
/******************************************************************************
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.
2018-09-30 20:25:54 +08:00
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2018-09-30 20:25:54 +08:00
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
2018-09-30 20:25:54 +08:00
*
* 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.
2018-09-30 20:25:54 +08:00
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 167. soda3.js
*
* DESCRIPTION
* SODA tests that use many collections.
*
*****************************************************************************/
'use strict';
2019-02-08 09:51:05 +08:00
const oracledb = require('oracledb');
2022-08-12 12:13:25 +08:00
const assert = require('assert');
2023-02-21 12:04:16 +08:00
const dbConfig = require('./dbconfig.js');
2019-02-08 09:51:05 +08:00
const sodaUtil = require('./sodaUtil.js');
const testsUtil = require('./testsUtil.js');
2018-09-30 20:25:54 +08:00
describe('167. soda3.js', () => {
2019-01-23 05:00:54 +08:00
let isRunnable;
2018-09-30 20:25:54 +08:00
let conn, sd, t_collections;
2023-08-17 16:11:49 +08:00
const t_collectionNames = [
2018-09-30 20:25:54 +08:00
"chris_1", "chris_2", "chris_3", "chris_4",
"changjie_1", "changjie_2", "Changjie_3", "Changjie_4",
"venkat_1", "venkat_2", "venkat_3", "venkat_4"
];
before('create collections', async function() {
isRunnable = await testsUtil.isSodaRunnable();
2019-01-23 05:00:54 +08:00
if (!isRunnable) {
this.skip();
}
2018-09-30 20:25:54 +08:00
await sodaUtil.cleanup();
2023-02-21 12:04:16 +08:00
conn = await oracledb.getConnection(dbConfig);
2023-02-21 11:20:36 +08:00
sd = conn.getSodaDatabase();
t_collections = await Promise.all(
t_collectionNames.map(function(name) {
return sd.createCollection(name);
})
);
2018-09-30 20:25:54 +08:00
}); // before
after('drop collections, close connection', async () => {
2019-01-23 05:00:54 +08:00
if (!isRunnable) return;
2023-02-21 11:20:36 +08:00
if (t_collections) {
await Promise.all(
t_collections.map(function(coll) {
return coll.drop();
})
);
2018-09-30 20:25:54 +08:00
}
2023-02-21 11:20:36 +08:00
await conn.close();
2018-09-30 20:25:54 +08:00
}); // after
it('167.1 get collection names', async () => {
2023-02-21 11:20:36 +08:00
const cNames = await sd.getCollectionNames();
assert.strictEqual(cNames.length, t_collectionNames.length);
2023-05-03 18:32:09 +08:00
assert.deepStrictEqual(cNames, t_collectionNames.sort());
2018-09-30 20:25:54 +08:00
});
it('167.2 getCollectionNames() - limit option', async () => {
2023-02-21 11:20:36 +08:00
const options = { limit: 1 };
const cNames = await sd.getCollectionNames(options);
assert.strictEqual(cNames.length, 1);
2023-05-03 18:32:09 +08:00
assert.deepStrictEqual(cNames, t_collectionNames.sort().slice(0, 1));
2018-09-30 20:25:54 +08:00
});
it('167.3 getCollectionNames() - limit is "undefined"', async () => {
2023-02-21 11:20:36 +08:00
const options = { limit: undefined };
const cNames = await sd.getCollectionNames(options);
assert.strictEqual(cNames.length, t_collectionNames.length);
2023-05-03 18:32:09 +08:00
assert.deepStrictEqual(cNames, t_collectionNames.sort());
2018-09-30 20:25:54 +08:00
});
it('167.4 getCollectionNames() - limit is 0', async () => {
2023-02-21 11:20:36 +08:00
const options = { limit: 0 };
const cNames = await sd.getCollectionNames(options);
assert.strictEqual(cNames.length, t_collectionNames.length);
2023-05-03 18:32:09 +08:00
assert.deepStrictEqual(cNames, t_collectionNames.sort());
2018-09-30 20:25:54 +08:00
});
it('167.5 getCollectionNames() - limit is null', async () => {
2023-08-17 16:11:49 +08:00
const options = { limit: null };
2023-02-21 11:45:10 +08:00
await assert.rejects(
2023-02-21 11:20:36 +08:00
async () => await sd.getCollectionNames(options),
/NJS-007: invalid value for "limit" in parameter 1/
);
2018-09-30 20:25:54 +08:00
});
it('167.6 getCollectionNames() - limit is an empty string', async () => {
2023-02-21 11:20:36 +08:00
const options = { limit: '' };
2023-02-21 11:45:10 +08:00
await assert.rejects(
2023-02-21 11:20:36 +08:00
async () => await sd.getCollectionNames(options),
/NJS-007: invalid value for "limit" in parameter 1/
);
2018-09-30 20:25:54 +08:00
});
it('167.7 getCollectionNames() - limit is a negative number', async () => {
2023-02-21 11:20:36 +08:00
const options = { limit: -7 };
const cNames = await sd.getCollectionNames(options);
assert.strictEqual(cNames.length, t_collectionNames.length);
2023-05-03 18:32:09 +08:00
assert.deepStrictEqual(cNames, t_collectionNames.sort());
2018-09-30 20:25:54 +08:00
});
2018-12-23 06:36:33 +08:00
it('167.8 startsWith option - basic test', async () => {
2023-02-21 11:20:36 +08:00
const options = { startsWith: "changjie" };
const cNames = await sd.getCollectionNames(options);
2023-05-03 18:32:09 +08:00
assert.deepStrictEqual(cNames, t_collectionNames.sort().slice(2));
2018-09-30 20:25:54 +08:00
});
2018-12-23 06:36:33 +08:00
it('167.9 startsWith is case sensitive', async () => {
2023-02-21 11:20:36 +08:00
const options = { startsWith: "Changjie" };
const cNames = await sd.getCollectionNames(options);
assert.strictEqual(cNames.length, t_collectionNames.length);
2023-05-03 18:32:09 +08:00
assert.deepStrictEqual(cNames, t_collectionNames.sort());
2018-09-30 20:25:54 +08:00
});
2018-12-23 06:36:33 +08:00
it('167.10 startsWith is an empty string', async () => {
2023-02-21 11:20:36 +08:00
const options = { startsWith: "" };
const cNames = await sd.getCollectionNames(options);
assert.strictEqual(cNames.length, t_collectionNames.length);
2023-05-03 18:32:09 +08:00
assert.deepStrictEqual(cNames, t_collectionNames.sort());
2018-09-30 20:25:54 +08:00
});
2018-12-23 06:36:33 +08:00
it('167.11 startsWith is null', async () => {
2023-02-21 11:20:36 +08:00
const options = { startsWith: null };
2023-02-21 11:45:10 +08:00
await assert.rejects(
2023-02-21 11:20:36 +08:00
async () => await sd.getCollectionNames(options),
/NJS-007: invalid value for "startsWith" in parameter 1/
);
2018-09-30 20:25:54 +08:00
});
2018-12-23 06:36:33 +08:00
it('167.12 Negative - startsWith has invalid type, a Number', async () => {
2023-02-21 11:20:36 +08:00
const options = { startsWith: 7 };
2023-02-21 11:45:10 +08:00
await assert.rejects(
2023-02-21 11:20:36 +08:00
async () => await sd.getCollectionNames(options),
/NJS-007: invalid value for "startsWith" in parameter 1/
);
2018-09-30 20:25:54 +08:00
});
it('167.13 openCollection() basic case 1', async () => {
2023-02-21 11:20:36 +08:00
const candidate = "Changjie_3";
const coll = await sd.openCollection(candidate);
assert.strictEqual(coll.name, candidate);
2018-09-30 20:25:54 +08:00
});
it('167.14 openCollection() basic case 2', async () => {
2023-02-21 11:20:36 +08:00
const candidate = "chris_1";
const coll = await sd.openCollection(candidate);
assert.strictEqual(coll.name, candidate);
2018-09-30 20:25:54 +08:00
});
it('167.15 the returned value is null if the requested collection does not exist', async () => {
2023-02-21 11:20:36 +08:00
const candidate = "nonexistent_collection";
const coll = await sd.openCollection(candidate);
assert.strictEqual(coll, undefined);
2018-09-30 20:25:54 +08:00
});
it('167.16 the requested collection name is case sensitive', async () => {
2023-02-21 11:20:36 +08:00
const candidate = "changjie_3";
const coll = await sd.openCollection(candidate);
assert.strictEqual(coll, undefined);
2018-09-30 20:25:54 +08:00
});
2018-12-23 06:36:33 +08:00
});