migrating to typescript
This commit is contained in:
parent
8853031dc8
commit
4f237be869
9
package-lock.json
generated
9
package-lock.json
generated
|
@ -45,6 +45,15 @@
|
|||
"moment": ">=2.14.0"
|
||||
}
|
||||
},
|
||||
"@types/tape": {
|
||||
"version": "4.2.32",
|
||||
"resolved": "https://registry.npmjs.org/@types/tape/-/tape-4.2.32.tgz",
|
||||
"integrity": "sha512-xil0KO5wkPoixdBWGIGolPv9dekf6dVkjjJLAFYchfKcd4DICou67rgGCIO7wAh3i5Ff/6j9IDgZz+GU9cMaqQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
"@types/mysql": "^2.15.5",
|
||||
"@types/node": "^10.5.4",
|
||||
"@types/pg": "^7.4.10",
|
||||
"@types/tape": "^4.2.32",
|
||||
"tape": "^4.9.1",
|
||||
"typescript": "^2.9.2"
|
||||
},
|
||||
|
|
|
@ -18,25 +18,33 @@
|
|||
*
|
||||
* @author Anatoly Khaytovich <anatolyuss@gmail.com>
|
||||
*/
|
||||
'use strict';
|
||||
import {TestSchemaProcessor} from './TestSchemaProcessor';
|
||||
import Conversion from '../../src/Conversion';
|
||||
import DBAccess from '../../src/DBAccess';
|
||||
import DBVendors from '../../src/DBVendors';
|
||||
import DBAccessQueryResult from '../../src/DBAccessQueryResult';
|
||||
|
||||
/**
|
||||
* Checks if the schema exists.
|
||||
*
|
||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
||||
*
|
||||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
const hasSchemaCreated = testSchemaProcessor => {
|
||||
const sql = `SELECT EXISTS(SELECT schema_name FROM information_schema.schemata
|
||||
WHERE schema_name = '${ testSchemaProcessor.conversion._schema }');`;
|
||||
async function hasSchemaCreated(testSchemaProcessor: TestSchemaProcessor): Promise<boolean> {
|
||||
const logTitle: string = 'SchemaProcessorTest::hasSchemaCreated';
|
||||
const sql: string = `SELECT EXISTS(SELECT schema_name FROM information_schema.schemata
|
||||
WHERE schema_name = '${ (<Conversion>testSchemaProcessor.conversion)._schema }');`;
|
||||
|
||||
return testSchemaProcessor
|
||||
.queryPg(sql)
|
||||
.then(data => !!data.rows[0].exists);
|
||||
};
|
||||
const result: DBAccessQueryResult = await (<DBAccess>testSchemaProcessor.dbAccess).query(
|
||||
logTitle,
|
||||
sql,
|
||||
DBVendors.PG,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
return !!result.data.rows[0].exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: check @types/tape.
|
||||
* Schema creation testing.
|
||||
*
|
||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
||||
|
@ -53,4 +61,4 @@ module.exports = (testSchemaProcessor, tape) => {
|
|||
tape.timeoutAfter(autoTimeoutMs);
|
||||
tape.equal(schemaExists, true);
|
||||
});
|
||||
};
|
||||
}
|
|
@ -71,9 +71,8 @@ export class TestSchemaProcessor {
|
|||
* Removes resources created by test scripts.
|
||||
*/
|
||||
public async removeTestResources(): Promise<void> {
|
||||
const dbAccess: DBAccess = new DBAccess(<Conversion>this.conversion);
|
||||
const sqlDropMySqlDatabase: string = `DROP DATABASE ${ (<Conversion>this.conversion)._mySqlDbName };`;
|
||||
await dbAccess.query(
|
||||
await (<DBAccess>this.dbAccess).query(
|
||||
'removeTestResources',
|
||||
sqlDropMySqlDatabase,
|
||||
DBVendors.MYSQL,
|
||||
|
@ -82,7 +81,7 @@ export class TestSchemaProcessor {
|
|||
);
|
||||
|
||||
const sqlDropPgDatabase: string = `DROP SCHEMA ${ (<Conversion>this.conversion)._schema } CASCADE;`;
|
||||
await dbAccess.query(
|
||||
await (<DBAccess>this.dbAccess).query(
|
||||
'removeTestResources',
|
||||
sqlDropPgDatabase,
|
||||
DBVendors.PG,
|
||||
|
@ -95,9 +94,8 @@ export class TestSchemaProcessor {
|
|||
* Creates test source database.
|
||||
*/
|
||||
private async _createTestSourceDb(conversion: Conversion): Promise<Conversion> {
|
||||
const dbAccess: DBAccess = new DBAccess(conversion);
|
||||
const sql: string = `CREATE DATABASE IF NOT EXISTS ${ (<Conversion>this.conversion)._mySqlDbName };`;
|
||||
await dbAccess.query('_createTestSourceDb', sql, DBVendors.MYSQL, true, false);
|
||||
await (<DBAccess>this.dbAccess).query('_createTestSourceDb', sql, DBVendors.MYSQL, true, false);
|
||||
return conversion;
|
||||
}
|
||||
|
||||
|
@ -140,9 +138,8 @@ export class TestSchemaProcessor {
|
|||
* Loads test schema into MySQL test database.
|
||||
*/
|
||||
private async _loadTestSchema(conversion: Conversion): Promise<Conversion> {
|
||||
const dbAccess: DBAccess = new DBAccess(conversion);
|
||||
const sqlBuffer: Buffer = await this._readTestSchema.bind(this);
|
||||
await dbAccess.query(
|
||||
await (<DBAccess>this.dbAccess).query(
|
||||
'_loadTestSchema',
|
||||
sqlBuffer.toString(),
|
||||
DBVendors.MYSQL,
|
||||
|
@ -164,7 +161,6 @@ export class TestSchemaProcessor {
|
|||
* Loads test data into MySQL test database.
|
||||
*/
|
||||
private async _loadTestData(conversion: Conversion): Promise<Conversion> {
|
||||
const dbAccess: DBAccess = new DBAccess(conversion);
|
||||
const insertParams: any = {
|
||||
id_test_unique_index: 7384,
|
||||
id_test_composite_unique_index_1: 125,
|
||||
|
@ -196,7 +192,7 @@ export class TestSchemaProcessor {
|
|||
const sql: string = `INSERT INTO \`table_a\`(${ insertParamsKeys.join(',') })
|
||||
VALUES(${ insertParamsKeys.map((k: string) => '?').join(',') });`;
|
||||
|
||||
await dbAccess.query(
|
||||
await (<DBAccess>this.dbAccess).query(
|
||||
'TestSchemaProcessor::_loadTestData',
|
||||
sql,
|
||||
DBVendors.MYSQL,
|
||||
|
|
Loading…
Reference in a new issue