refactoring
This commit is contained in:
parent
7ea1808201
commit
c3e17548b8
|
@ -20,10 +20,11 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const test = require('tape');
|
||||
const TestSchemaProcessor = require('./TestModules/TestSchemaProcessor');
|
||||
const testSchema = require('./TestModules/SchemaProcessorTest');
|
||||
const testDataContent = require('./TestModules/DataContentTest');
|
||||
const testDataTypes = require('./TestModules/DataTypesTest');
|
||||
const testColumnTypes = require('./TestModules/ColumnTypesTest');
|
||||
|
||||
/**
|
||||
* Runs test suites.
|
||||
|
@ -34,15 +35,22 @@ const testDataTypes = require('./TestModules/DataTypesTest');
|
|||
*/
|
||||
const runTestSuites = testSchemaProcessor => {
|
||||
return () => {
|
||||
Promise.all([
|
||||
// A list of test suite modules.
|
||||
// Each test suite module must export a function, that returns a promise.
|
||||
testSchema(testSchemaProcessor),
|
||||
testDataContent(testSchemaProcessor),
|
||||
testDataTypes(testSchemaProcessor),
|
||||
])
|
||||
.then(() => testSchemaProcessor.removeTestResources())
|
||||
test.onFinish(() => {
|
||||
testSchemaProcessor.removeTestResources()
|
||||
.then(() => process.exit());
|
||||
});
|
||||
|
||||
test('Test schema should be created', tapeTestSchema => {
|
||||
testSchema(testSchemaProcessor, tapeTestSchema);
|
||||
});
|
||||
|
||||
test('Test the data content', tapeTestDataContent => {
|
||||
testDataContent(testSchemaProcessor, tapeTestDataContent);
|
||||
});
|
||||
|
||||
test('Test column types', tapeTestColumnTypes => {
|
||||
testColumnTypes(testSchemaProcessor, tapeTestColumnTypes);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const { test } = require('tape');
|
||||
|
||||
/**
|
||||
* Returns `table_a` column types.
|
||||
*
|
||||
|
@ -94,13 +92,12 @@ const getExpectedColumnTypes = () => {
|
|||
* The data content testing.
|
||||
*
|
||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
||||
* @param {Tape} tape
|
||||
*
|
||||
* @returns {Promise<Any>}
|
||||
* @returns {undefined}
|
||||
*/
|
||||
module.exports = testSchemaProcessor => {
|
||||
return new Promise(resolve => {
|
||||
module.exports = (testSchemaProcessor, tape) => {
|
||||
getColumnTypes(testSchemaProcessor).then(data => {
|
||||
test('Test the data types', tape => {
|
||||
const expectedColumnTypes = getExpectedColumnTypes();
|
||||
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
||||
const numberOfPlannedAssertions = data.length;
|
||||
|
@ -112,11 +109,9 @@ module.exports = testSchemaProcessor => {
|
|||
const columnName = data[i].column_name;
|
||||
const actualColumnType = data[i].data_type;
|
||||
const expectedColumnType = expectedColumnTypes[columnName];
|
||||
|
||||
tape.comment(`Test ${ columnName } column type`);
|
||||
tape.equal(actualColumnType, expectedColumnType);
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
|
@ -20,8 +20,6 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const { test } = require('tape');
|
||||
|
||||
/**
|
||||
* Retrieve a data from `table_a`.
|
||||
*
|
||||
|
@ -42,52 +40,91 @@ const retrieveData = testSchemaProcessor => {
|
|||
* The data content testing.
|
||||
*
|
||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
||||
* @param {Tape} tape
|
||||
*
|
||||
* @returns {Promise<Any>}
|
||||
* @returns {undefined}
|
||||
*/
|
||||
module.exports = testSchemaProcessor => {
|
||||
return new Promise(resolve => {
|
||||
module.exports = (testSchemaProcessor, tape) => {
|
||||
retrieveData(testSchemaProcessor).then(data => {
|
||||
test('Test the data content', tape => {
|
||||
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
||||
const numberOfPlannedAssertions = 24;
|
||||
const originalTestBlobText = testSchemaProcessor
|
||||
.getTestBlob(testSchemaProcessor._conversion)
|
||||
.toString();
|
||||
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');
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const { test } = require('tape');
|
||||
|
||||
/**
|
||||
* Checks if the schema exists.
|
||||
*
|
||||
|
@ -42,24 +40,17 @@ const hasSchemaCreated = testSchemaProcessor => {
|
|||
* Schema creation testing.
|
||||
*
|
||||
* @param {TestSchemaProcessor} testSchemaProcessor
|
||||
* @param {Tape} tape
|
||||
*
|
||||
* @returns {Promise<any>}
|
||||
* @returns {undefined}
|
||||
*/
|
||||
module.exports = testSchemaProcessor => {
|
||||
return new Promise(resolve => {
|
||||
test('Test schema should be created', tape => {
|
||||
const numberOfPlannedAssertions = 2;
|
||||
module.exports = (testSchemaProcessor, tape) => {
|
||||
hasSchemaCreated(testSchemaProcessor).then(schemaExists => {
|
||||
const numberOfPlannedAssertions = 1;
|
||||
const autoTimeoutMs = 3 * 1000; // 3 seconds.
|
||||
|
||||
tape.plan(numberOfPlannedAssertions);
|
||||
tape.timeoutAfter(autoTimeoutMs);
|
||||
|
||||
hasSchemaCreated(testSchemaProcessor).then(schemaExists => {
|
||||
tape.equal(typeof schemaExists, 'boolean');
|
||||
tape.equal(schemaExists, true);
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue