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