From 01122b240764643e1572515659374d297cca9348 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Mon, 3 Sep 2018 01:26:48 +0300 Subject: [PATCH] migrating to typescript --- test/TestModules/DataContentTest.js | 130 --------------------------- test/TestModules/DataContentTest.ts | 132 ++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 130 deletions(-) delete mode 100644 test/TestModules/DataContentTest.js create mode 100644 test/TestModules/DataContentTest.ts diff --git a/test/TestModules/DataContentTest.js b/test/TestModules/DataContentTest.js deleted file mode 100644 index 90830d6..0000000 --- a/test/TestModules/DataContentTest.js +++ /dev/null @@ -1,130 +0,0 @@ -/* - * This file is a part of "NMIG" - the database migration tool. - * - * Copyright (C) 2016 - present, Anatoly Khaytovich - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program (please see the "LICENSE.md" file). - * If not, see . - * - * @author Anatoly Khaytovich - */ -'use strict'; - -/** - * Retrieve a data from `table_a`. - * - * @param {TestSchemaProcessor} testSchemaProcessor - * - * @returns {Promise} - */ -const retrieveData = testSchemaProcessor => { - const sql = `SELECT ENCODE(table_a.blob, 'escape') AS blob_text, table_a.* - FROM ${ testSchemaProcessor.conversion._schema }.table_a AS table_a;`; - - return testSchemaProcessor - .queryPg(sql) - .then(data => data.rows[0]); -}; - -/** - * The data content testing. - * - * @param {TestSchemaProcessor} testSchemaProcessor - * @param {Tape} tape - * - * @returns {undefined} - */ -module.exports = (testSchemaProcessor, tape) => { - retrieveData(testSchemaProcessor).then(data => { - const autoTimeoutMs = 3 * 1000; // 3 seconds. - const numberOfPlannedAssertions = 24; - const originalTestBlobText = testSchemaProcessor.getTestBlob(testSchemaProcessor.conversion).toString(); - - tape.plan(numberOfPlannedAssertions); - tape.timeoutAfter(autoTimeoutMs); - - tape.comment('Test blob_text column value'); - tape.equal(data.blob_text, originalTestBlobText); - - tape.comment('Test bit column value'); - tape.equal(data.bit, '1'); // BIT is actually a "bit string", for example: '1110' -> 14 - - tape.comment('Test id_test_unique_index column value'); - tape.equal(data.id_test_unique_index, 7384); - - tape.comment('Test id_test_composite_unique_index_1 column value'); - tape.equal(data.id_test_composite_unique_index_1, 125); - - tape.comment('Test id_test_composite_unique_index_2 column value'); - tape.equal(data.id_test_composite_unique_index_2, 234); - - tape.comment('Test id_test_index column value'); - tape.equal(data.id_test_index, 123); - - tape.comment('Test int_test_not_null column value'); - tape.equal(data.int_test_not_null, 123); - - tape.comment('Test id_test_composite_index_1 column value'); - tape.equal(data.id_test_composite_index_1, 11); - - tape.comment('Test id_test_composite_index_2 column value'); - tape.equal(data.id_test_composite_index_2, 22); - - tape.comment('Test json_test_comment column value'); - tape.equal(JSON.stringify(data.json_test_comment), '{"prop1":"First","prop2":2}'); - - tape.comment('Test year column value'); - tape.equal(data.year, 1984); - - tape.comment('Test bigint column value'); - tape.equal(data.bigint, '1234567890123456800'); - - tape.comment('Test float column value'); - tape.equal(data.float, 12345.5); - - tape.comment('Test double column value'); - tape.equal(data.double, 123456789.23); - - tape.comment('Test numeric column value'); - tape.equal(data.numeric, '1234567890'); - - tape.comment('Test decimal column value'); - tape.equal(data.decimal, '1234567890'); - - tape.comment('Test char_5 column value'); - tape.equal(data.char_5, 'fghij'); - - tape.comment('Test varchar_5 column value'); - tape.equal(data.varchar_5, 'abcde'); - - tape.comment('Test date column value'); - tape.equal(`${ data.date.getFullYear() }-${ data.date.getMonth() + 1 }-${ data.date.getDate() }`, '1984-11-30'); - - tape.comment('Test time column value'); - tape.equal(data.time, '21:12:33'); - - tape.comment('Test text column value'); - tape.equal(data.text, 'Test text'); - - tape.comment('Test enum column value'); - tape.equal(data.enum, 'e1'); - - tape.comment('Test set column value'); - tape.equal(data.set, 's2'); - - const date = `${ data.timestamp.getFullYear() }-${ data.timestamp.getMonth() + 1 }-${ data.timestamp.getDate() }`; - const time = `${ data.timestamp.getHours() }:${ data.timestamp.getMinutes() }:${ data.timestamp.getSeconds() }`; - tape.comment('Test timestamp column value'); - tape.equal(`${ date } ${ time }`, '2018-11-11 22:21:20'); - }); -}; diff --git a/test/TestModules/DataContentTest.ts b/test/TestModules/DataContentTest.ts new file mode 100644 index 0000000..e3b47d9 --- /dev/null +++ b/test/TestModules/DataContentTest.ts @@ -0,0 +1,132 @@ +/* + * This file is a part of "NMIG" - the database migration tool. + * + * Copyright (C) 2016 - present, Anatoly Khaytovich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (please see the "LICENSE.md" file). + * If not, see . + * + * @author Anatoly Khaytovich + */ +import Conversion from '../../src/Conversion'; +import TestSchemaProcessor from './TestSchemaProcessor'; +import DBAccess from '../../src/DBAccess'; +import DBVendors from '../../src/DBVendors'; +import DBAccessQueryResult from '../../src/DBAccessQueryResult'; +import { Test } from 'tape'; + +/** + * Retrieves a data from `table_a`. + */ +async function retrieveData(testSchemaProcessor: TestSchemaProcessor): Promise { + const logTitle: string = 'DataContentTest::retrieveData'; + const sql: string = `SELECT ENCODE(table_a.blob, 'escape') AS blob_text, table_a.* + FROM ${ (testSchemaProcessor.conversion)._schema }.table_a AS table_a;`; + + const result: DBAccessQueryResult = await (testSchemaProcessor.dbAccess).query( + logTitle, + sql, + DBVendors.PG, + true, + false + ); + + return result.data.rows[0]; +} + +/** + * The data content testing. + */ +export default async function(testSchemaProcessor: TestSchemaProcessor, tape: Test): Promise { + const data: any = await retrieveData(testSchemaProcessor); + const autoTimeoutMs: number = 3 * 1000; // 3 seconds. + const numberOfPlannedAssertions: number = 24; + const originalTestBlobText: string = testSchemaProcessor.getTestBlob(testSchemaProcessor.conversion).toString(); + + tape.plan(numberOfPlannedAssertions); + tape.timeoutAfter(autoTimeoutMs); + + tape.comment('Test blob_text column value'); + tape.equal(data.blob_text, originalTestBlobText); + + tape.comment('Test bit column value'); + tape.equal(data.bit, '1'); // BIT is actually a "bit string", for example: '1110' -> 14 + + tape.comment('Test id_test_unique_index column value'); + tape.equal(data.id_test_unique_index, 7384); + + tape.comment('Test id_test_composite_unique_index_1 column value'); + tape.equal(data.id_test_composite_unique_index_1, 125); + + tape.comment('Test id_test_composite_unique_index_2 column value'); + tape.equal(data.id_test_composite_unique_index_2, 234); + + tape.comment('Test id_test_index column value'); + tape.equal(data.id_test_index, 123); + + tape.comment('Test int_test_not_null column value'); + tape.equal(data.int_test_not_null, 123); + + tape.comment('Test id_test_composite_index_1 column value'); + tape.equal(data.id_test_composite_index_1, 11); + + tape.comment('Test id_test_composite_index_2 column value'); + tape.equal(data.id_test_composite_index_2, 22); + + tape.comment('Test json_test_comment column value'); + tape.equal(JSON.stringify(data.json_test_comment), '{"prop1":"First","prop2":2}'); + + tape.comment('Test year column value'); + tape.equal(data.year, 1984); + + tape.comment('Test bigint column value'); + tape.equal(data.bigint, '1234567890123456800'); + + tape.comment('Test float column value'); + tape.equal(data.float, 12345.5); + + tape.comment('Test double column value'); + tape.equal(data.double, 123456789.23); + + tape.comment('Test numeric column value'); + tape.equal(data.numeric, '1234567890'); + + tape.comment('Test decimal column value'); + tape.equal(data.decimal, '1234567890'); + + tape.comment('Test char_5 column value'); + tape.equal(data.char_5, 'fghij'); + + tape.comment('Test varchar_5 column value'); + tape.equal(data.varchar_5, 'abcde'); + + tape.comment('Test date column value'); + tape.equal(`${ data.date.getFullYear() }-${ data.date.getMonth() + 1 }-${ data.date.getDate() }`, '1984-11-30'); + + tape.comment('Test time column value'); + tape.equal(data.time, '21:12:33'); + + tape.comment('Test text column value'); + tape.equal(data.text, 'Test text'); + + tape.comment('Test enum column value'); + tape.equal(data.enum, 'e1'); + + tape.comment('Test set column value'); + tape.equal(data.set, 's2'); + + const date: string = `${ data.timestamp.getFullYear() }-${ data.timestamp.getMonth() + 1 }-${ data.timestamp.getDate() }`; + const time: string = `${ data.timestamp.getHours() }:${ data.timestamp.getMinutes() }:${ data.timestamp.getSeconds() }`; + tape.comment('Test timestamp column value'); + tape.equal(`${ date } ${ time }`, '2018-11-11 22:21:20'); +}