node-oracledb/test/dataTypeTimestamp5.js

126 lines
4.4 KiB
JavaScript
Raw Normal View History

2023-02-21 14:08:24 +08:00
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
2015-07-20 12:42:12 +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.
2015-07-20 12:42:12 +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.
2015-07-20 12:42:12 +08:00
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
2015-07-20 12:42:12 +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.
2015-07-20 12:42:12 +08:00
* See the License for the specific language governing permissions and
* limitations under the License.
2016-03-24 14:09:53 +08:00
*
2015-07-20 12:42:12 +08:00
* NAME
* 37. dataTypeTimestamp5.js
*
* DESCRIPTION
* Testing Oracle data type support - TIMESTAMP WITH LOCAL TIME ZONE.
*
*****************************************************************************/
'use strict';
2015-09-02 20:33:00 +08:00
2023-02-21 14:08:24 +08:00
const oracledb = require('oracledb');
2023-02-21 14:18:59 +08:00
const assert = require('assert');
2023-02-21 14:08:24 +08:00
const assist = require('./dataTypeAssist.js');
const dbConfig = require('./dbconfig.js');
2015-07-20 12:42:12 +08:00
describe('37. dataTypeTimestamp5.js', function() {
2016-03-24 14:09:53 +08:00
2023-02-21 14:08:24 +08:00
let connection = null;
2023-08-17 16:11:49 +08:00
const tableName = "nodb_timestamp5";
2023-02-21 14:18:59 +08:00
before('get one connection', async function() {
connection = await oracledb.getConnection(dbConfig);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
after('release connection', async function() {
await connection.close();
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
describe('37.1 Testing JavaScript Date with database TIMESTAMP WITH LOCAL TIME ZONE', function() {
2023-08-17 16:11:49 +08:00
const dates = assist.data.dates;
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
before('create table, insert data', async function() {
2023-03-14 14:33:48 +08:00
await assist.setUp(connection, tableName, dates);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
after(async function() {
2017-11-17 19:59:41 +08:00
oracledb.fetchAsString = [];
2023-02-21 14:18:59 +08:00
await connection.execute(`DROP table ` + tableName + ` PURGE`);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
it('37.1.1 works well with SELECT query', async function() {
2023-03-14 14:33:48 +08:00
await assist.dataTypeSupport(connection, tableName, dates);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
it('37.1.2 works well with result set', async function() {
2023-03-14 14:33:48 +08:00
await assist.verifyResultSet(connection, tableName, dates);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2023-02-21 14:18:59 +08:00
it('37.1.3 works well with REF Cursor', async function() {
2023-03-14 14:33:48 +08:00
await assist.verifyRefCursor(connection, tableName, dates);
2017-06-14 09:54:15 +08:00
});
2016-03-24 14:09:53 +08:00
2023-02-21 14:18:59 +08:00
it('37.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
2023-03-14 14:33:48 +08:00
await assist.verifyRefCursorWithFetchInfo(connection, tableName, dates);
2017-11-17 19:59:41 +08:00
});
2023-02-21 14:18:59 +08:00
it('37.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
2017-11-17 19:59:41 +08:00
oracledb.fetchAsString = [ oracledb.DATE ];
2023-03-14 14:33:48 +08:00
await assist.verifyRefCursorWithFetchAsString(connection, tableName, dates);
2017-11-17 19:59:41 +08:00
});
2017-06-14 09:54:15 +08:00
}); // end of 37.1 suite
2015-09-02 19:08:19 +08:00
describe('37.2 stores null value correctly', function() {
2023-02-21 14:18:59 +08:00
it('37.2.1 testing Null, Empty string and Undefined', async function() {
2023-03-14 14:33:48 +08:00
await assist.verifyNullValues(connection, tableName);
2017-06-14 09:54:15 +08:00
});
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
describe('37.3 testing TIMESTAMP WITH LOCAL TIME ZONE', function() {
2023-08-17 16:11:49 +08:00
const timestamps = assist.TIMESTAMP_TZ_STRINGS_2;
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
before(async function() {
2023-03-14 14:33:48 +08:00
await assist.setUp4sql(connection, tableName, timestamps);
2023-02-21 14:18:59 +08:00
});
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
after(async function() {
await connection.execute(`DROP table ` + tableName + ` PURGE`);
}); // after
2015-09-02 19:08:19 +08:00
2023-02-21 14:18:59 +08:00
it('37.3.1 SELECT query - original data', async function() {
2023-03-14 14:33:48 +08:00
await assist.selectOriginalData(connection, tableName, timestamps);
2015-09-02 19:08:19 +08:00
});
2023-02-21 14:18:59 +08:00
it('37.3.2 SELECT query - formatted data for comparison', async function() {
2023-08-17 16:11:49 +08:00
const sql = `SELECT num, TO_CHAR(content AT TIME ZONE '-8:00', 'DD-MM-YYYY HH24:MI:SS.FF TZR') AS TS_DATA FROM `
2023-02-21 14:18:59 +08:00
+ tableName + ` WHERE num = :no`;
await Promise.all(timestamps.map(async function(timestamp) {
2023-08-17 16:11:49 +08:00
const bv = timestamps.indexOf(timestamp);
const result = await connection.execute(
2023-02-21 14:18:59 +08:00
sql,
{ no: bv },
{
outFormat: oracledb.OUT_FORMAT_OBJECT
});
assert.strictEqual(result.rows[0].TS_DATA, assist.content.timestamps5[bv]);
}));
});
}); // end of 37.3 suite
});
2017-06-14 09:54:15 +08:00
});