fixed test environment setup

This commit is contained in:
Umed Khudoiberdiev 2016-12-07 12:23:56 +05:00
parent 3cdae400f4
commit 70336bce11
41 changed files with 383 additions and 616 deletions

View File

@ -1,64 +0,0 @@
{
"connections": {
"mysql": {
"host": "localhost",
"port": 3306,
"username": "root",
"password": "admin",
"database": "test"
},
"mysqlSecondary": {
"host": "localhost",
"port": 3306,
"username": "root",
"password": "admin",
"database": "test2"
},
"mariadb": {
"host": "localhost",
"port": 3307,
"username": "root",
"password": "admin",
"database": "test"
},
"mariadbSecondary": {
"host": "localhost",
"port": 3307,
"username": "root",
"password": "admin",
"database": "test2"
},
"sqlite": {
"storage": "temp/sqlitedb.db"
},
"sqliteSecondary": {
"storage": "temp/sqlitedb-secondary.db"
},
"postgres": {
"host": "localhost",
"port": 5432,
"username": "test",
"password": "admin",
"database": "test"
},
"postgresSecondary": {
"host": "localhost",
"port": 5432,
"username": "test",
"password": "admin",
"database": "test2"
},
"mssql": {
"host": "192.168.1.10",
"username": "sa",
"password": "admin12345",
"database": "test"
},
"mssqlSecondary": {
"host": "192.168.1.10",
"username": "sa",
"password": "admin12345",
"database": "test"
}
}
}

View File

@ -1,38 +0,0 @@
{
"connections": {
"mysql": {
"host": "localhost",
"port": 3306,
"username": "root",
"password": "admin",
"database": "test"
},
"mysqlSecondary": {
"host": "localhost",
"port": 3306,
"username": "root",
"password": "admin",
"database": "test2"
},
"sqlite": {
"storage": "temp/sqlitedb.db"
},
"sqliteSecondary": {
"storage": "temp/sqlitedb-secondary.db"
},
"postgres": {
"host": "localhost",
"port": 5432,
"username": "root",
"password": "admin",
"database": "test"
},
"postgresSecondary": {
"host": "localhost",
"port": 5432,
"username": "root",
"password": "admin",
"database": "test2"
}
}
}

View File

@ -1,6 +1,7 @@
[
{
"name": "default",
"skip": false,
"name": "mysql",
"driver": {
"type": "mysql",
"host": "localhost",
@ -8,7 +9,61 @@
"username": "root",
"password": "admin",
"database": "test"
},
"autoSchemaSync": true
}
},
{
"skip": false,
"name": "mariadb",
"driver": {
"type": "mariadb",
"host": "localhost",
"port": 3307,
"username": "root",
"password": "admin",
"database": "test"
}
},
{
"skip": false,
"name": "sqlite",
"driver": {
"type": "sqlite",
"storage": "temp/sqlitedb.db"
}
},
{
"skip": false,
"name": "postgres",
"driver": {
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "root",
"password": "admin",
"database": "test"
}
},
{
"skip": true,
"name": "mssql",
"driver": {
"type": "mssql",
"host": "localhost",
"username": "sa",
"password": "admin",
"database": "test"
}
},
{
"skip": true,
"name": "oracle",
"driver": {
"type": "oracle",
"host": "localhost",
"username": "system",
"password": "oracle",
"port": 1521,
"sid": "xe.oracle.docker"
}
}
]

View File

@ -1,3 +1,8 @@
/**
* Driver type.
*/
export type DriverType = "mysql"|"postgres"|"mariadb"|"sqlite"|"oracle"|"mssql"|"websql";
/**
* Connectivity options used to connect to the database, and other database-driver-specific options.
*/
@ -6,7 +11,7 @@ export interface DriverOptions {
/**
* Database type. This value is required.
*/
readonly type: "mysql"|"postgres"|"mariadb"|"sqlite"|"oracle"|"mssql"|"websql";
readonly type: DriverType;
/**
* Connection url to where perform connection to.

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {PostDetails} from "./entity/PostDetails";
@ -7,13 +7,13 @@ import {PostDetails} from "./entity/PostDetails";
describe.skip("cascades > should insert by cascades from both sides (#57)", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should insert by cascades from owner side", () => Promise.all(connections.map(async connection => {

View File

@ -1,10 +1,9 @@
import "reflect-metadata";
import {expect} from "chai";
import {createTestingConnectionOptions} from "../../utils/test-utils";
import {setupSingleTestingConnection} from "../../utils/test-utils";
import {ConnectionOptions} from "../../../src/connection/ConnectionOptions";
import {ConnectionManager} from "../../../src/connection/ConnectionManager";
import {MysqlDriver} from "../../../src/driver/mysql/MysqlDriver";
import {ConnectionNotFoundError} from "../../../src/connection/error/ConnectionNotFoundError";
import {PrimaryGeneratedColumn} from "../../../src/decorator/columns/PrimaryGeneratedColumn";
import {Column} from "../../../src/decorator/columns/Column";
import {Table} from "../../../src/decorator/tables/Table";
@ -29,9 +28,11 @@ describe("ConnectionManager", () => {
describe("create", function() {
it("should create a mysql connection when mysql driver is specified", () => {
const options: ConnectionOptions = {
driver: createTestingConnectionOptions("mysql")
};
const options: ConnectionOptions = setupSingleTestingConnection("mysql", {
name: "default",
entities: []
});
const connectionManager = new ConnectionManager();
const connection = connectionManager.create(options);
connection.name.should.be.equal("default");
@ -56,9 +57,10 @@ describe("ConnectionManager", () => {
describe("createAndConnect", function() {
it("should create a mysql connection when mysql driver is specified AND connect to it", async () => {
const options: ConnectionOptions = {
driver: createTestingConnectionOptions("mysql")
};
const options: ConnectionOptions = setupSingleTestingConnection("mysql", {
name: "default",
entities: []
});
const connectionManager = new ConnectionManager();
const connection = await connectionManager.createAndConnect(options);
connection.name.should.be.equal("default");
@ -85,10 +87,10 @@ describe("ConnectionManager", () => {
describe("get", function() {
it("should give connection with a requested name", () => {
const options: ConnectionOptions = {
const options: ConnectionOptions = setupSingleTestingConnection("mysql", {
name: "myMysqlConnection",
driver: createTestingConnectionOptions("mysql")
};
entities: []
});
const connectionManager = new ConnectionManager();
const connection = connectionManager.create(options);
connection.driver.should.be.instanceOf(MysqlDriver);
@ -96,10 +98,10 @@ describe("ConnectionManager", () => {
});
it("should throw an error if connection with the given name was not found", () => {
const options: ConnectionOptions = {
const options: ConnectionOptions = setupSingleTestingConnection("mysql", {
name: "myMysqlConnection",
driver: createTestingConnectionOptions("mysql")
};
entities: []
});
const connectionManager = new ConnectionManager();
const connection = connectionManager.create(options);
connection.driver.should.be.instanceOf(MysqlDriver);
@ -111,11 +113,11 @@ describe("ConnectionManager", () => {
describe("create connection options", function() {
it("should not drop the database if dropSchemaOnConnection was not specified", async () => {
const options: ConnectionOptions = {
driver: createTestingConnectionOptions("mysql"),
autoSchemaSync: true,
const options: ConnectionOptions = setupSingleTestingConnection("mysql", {
name: "myMysqlConnection",
schemaCreate: true,
entities: [Post]
};
});
const connectionManager = new ConnectionManager();
// create connection, save post and close connection
@ -133,12 +135,12 @@ describe("ConnectionManager", () => {
});
it("should drop the database if dropSchemaOnConnection was set to true (mysql)", async () => {
const options: ConnectionOptions = {
const options: ConnectionOptions = setupSingleTestingConnection("mysql", {
name: "myMysqlConnection",
schemaCreate: true,
dropSchemaOnConnection: true,
autoSchemaSync: true,
driver: createTestingConnectionOptions("mysql"),
entities: [Post]
};
});
const connectionManager = new ConnectionManager();
// create connection, save post and close connection

View File

@ -3,24 +3,15 @@ import {expect} from "chai";
import {Post} from "./entity/Post";
import {View} from "./entity/View";
import {Category} from "./entity/Category";
import {setupTestingConnections, closeConnections, createTestingConnectionOptions} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, setupSingleTestingConnection} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {CannotConnectAlreadyConnectedError} from "../../../src/connection/error/CannotConnectAlreadyConnectedError";
import {CannotCloseNotConnectedError} from "../../../src/connection/error/CannotCloseNotConnectedError";
import {CannotImportAlreadyConnectedError} from "../../../src/connection/error/CannotImportAlreadyConnectedError";
import {Repository} from "../../../src/repository/Repository";
import {TreeRepository} from "../../../src/repository/TreeRepository";
import {getConnectionManager} from "../../../src/index";
import {ConnectionOptions} from "../../../src/connection/ConnectionOptions";
import {CannotSyncNotConnectedError} from "../../../src/connection/error/CannotSyncNotConnectedError";
import {getConnectionManager, createConnection} from "../../../src/index";
import {NoConnectionForRepositoryError} from "../../../src/connection/error/NoConnectionForRepositoryError";
import {RepositoryNotFoundError} from "../../../src/connection/error/RepositoryNotFoundError";
import {DefaultNamingStrategy} from "../../../src/naming-strategy/DefaultNamingStrategy";
import {FirstCustomNamingStrategy} from "./naming-strategy/FirstCustomNamingStrategy";
import {SecondCustomNamingStrategy} from "./naming-strategy/SecondCustomNamingStrategy";
import {CannotUseNamingStrategyNotConnectedError} from "../../../src/connection/error/CannotUseNamingStrategyNotConnectedError";
import {NamingStrategyNotFoundError} from "../../../src/connection/error/NamingStrategyNotFoundError";
import {RepositoryNotTreeError} from "../../../src/connection/error/RepositoryNotTreeError";
import {EntityManager} from "../../../src/entity-manager/EntityManager";
import {CannotGetEntityManagerNotConnectedError} from "../../../src/connection/error/CannotGetEntityManagerNotConnectedError";
import {Blog} from "./modules/blog/entity/Blog";
@ -34,11 +25,10 @@ describe("Connection", () => {
let connection: Connection;
before(async () => {
const options: ConnectionOptions = {
driver: createTestingConnectionOptions("mysql"),
connection = getConnectionManager().create(setupSingleTestingConnection("mysql", {
name: "default",
entities: []
};
connection = await getConnectionManager().create(options);
}));
});
after(() => {
if (connection.isConnected)
@ -94,8 +84,8 @@ describe("Connection", () => {
describe("after connection is established successfully", function() {
let connections: Connection[];
beforeEach(() => setupTestingConnections({ entities: [Post, Category], schemaCreate: true }).then(all => connections = all));
afterEach(() => closeConnections(connections));
beforeEach(() => createTestingConnections({ entities: [Post, Category], schemaCreate: true }).then(all => connections = all));
afterEach(() => closeTestingConnections(connections));
it("connection.isConnected should be true", () => connections.forEach(connection => {
connection.isConnected.should.be.true;
@ -135,8 +125,8 @@ describe("Connection", () => {
describe("working with repositories after connection is established successfully", function() {
let connections: Connection[];
before(() => setupTestingConnections({ entities: [Post, Category], schemaCreate: true }).then(all => connections = all));
after(() => closeConnections(connections));
before(() => createTestingConnections({ entities: [Post, Category], schemaCreate: true }).then(all => connections = all));
after(() => closeTestingConnections(connections));
it("should be able to get simple entity repository", () => connections.forEach(connection => {
connection.getRepository(Post).should.be.instanceOf(Repository);
@ -177,8 +167,8 @@ describe("Connection", () => {
describe("generate a schema when connection.syncSchema is called", function() {
let connections: Connection[];
beforeEach(() => setupTestingConnections({ entities: [Post], schemaCreate: true }).then(all => connections = all));
afterEach(() => closeConnections(connections));
beforeEach(() => createTestingConnections({ entities: [Post], schemaCreate: true }).then(all => connections = all));
afterEach(() => closeTestingConnections(connections));
it("database should be empty after schema is synced with dropDatabase flag", () => Promise.all(connections.map(async connection => {
const postRepository = connection.getRepository(Post);
@ -198,7 +188,7 @@ describe("Connection", () => {
// open a close connections
let connections: Connection[] = [];
before(() => setupTestingConnections({ entities: [Post], schemaCreate: true }).then(all => {
before(() => createTestingConnections({ entities: [Post], schemaCreate: true }).then(all => {
connections = all;
return Promise.all(connections.map(connection => connection.close()));
}));
@ -217,14 +207,14 @@ describe("Connection", () => {
let firstConnection: Connection, secondConnection: Connection;
beforeEach(async () => {
firstConnection = await getConnectionManager().create({
driver: createTestingConnectionOptions("mysql"),
name: "firstConnection"
});
secondConnection = await getConnectionManager().create({
driver: createTestingConnectionOptions("mysql"),
name: "secondConnection"
});
firstConnection = getConnectionManager().create(setupSingleTestingConnection("mysql", {
name: "firstConnection",
entities: []
}));
secondConnection = getConnectionManager().create(setupSingleTestingConnection("mysql", {
name: "secondConnection",
entities: []
}));
});
it("should import first connection's entities only", async () => {
@ -269,9 +259,10 @@ describe("Connection", () => {
let connection: Connection;
beforeEach(async () => {
connection = await getConnectionManager().create({
driver: createTestingConnectionOptions("mysql")
});
connection = getConnectionManager().create(setupSingleTestingConnection("mysql", {
name: "default",
entities: []
}));
});
afterEach(() => connection.isConnected ? connection.close() : {});
@ -316,9 +307,10 @@ describe("Connection", () => {
let connection: Connection;
beforeEach(async () => {
connection = await getConnectionManager().create({
driver: createTestingConnectionOptions("mysql")
});
connection = getConnectionManager().create(setupSingleTestingConnection("mysql", {
name: "default",
entities: []
}));
});
afterEach(() => connection.isConnected ? connection.close() : {});
@ -357,8 +349,8 @@ describe("Connection", () => {
describe("skip schema generation when skipSchemaSync option is used", function() {
let connections: Connection[];
beforeEach(() => setupTestingConnections({ entities: [View] }).then(all => connections = all));
afterEach(() => closeConnections(connections));
beforeEach(() => createTestingConnections({ entities: [View] }).then(all => connections = all));
afterEach(() => closeTestingConnections(connections));
it("database should be empty after schema sync", () => Promise.all(connections.map(async connection => {
await connection.syncSchema(true);
const queryRunner = await connection.driver.createQueryRunner();

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Counters} from "./entity/Counters";
@ -7,9 +7,11 @@ import {Counters} from "./entity/Counters";
describe("decorators > embedded", () => {
let connections: Connection[];
beforeEach(() => setupTestingConnections({ entities: [Post, Counters], reloadAndCreateSchema: true }).then(all => connections = all));
beforeEach(() => reloadDatabases(connections));
afterEach(() => closeConnections(connections));
beforeEach(() => createTestingConnections({
entities: [Post, Counters]
}).then(all => connections = all));
beforeEach(() => reloadTestingDatabases(connections));
afterEach(() => closeTestingConnections(connections));
describe("basic functionality", function() {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -10,13 +10,13 @@ describe("QueryBuilder > relation-count", () => {
// const resourceDir = __dirname + "/../../../../../../test/functional/query-builder/join-relation-ids/";
let connections: Connection[];
before(() => setupTestingConnections({
before(() => createTestingConnections({
entities: [Post, Category, Tag],
schemaCreate: true,
dropSchemaOnConnection: true
}).then(all => connections = all));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("basic functionality", function() {

View File

@ -1,7 +1,7 @@
import "reflect-metadata";
import * as chai from "chai";
import {expect} from "chai";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -16,9 +16,9 @@ describe("QueryBuilder > relation-id", () => {
// todo: also make sure all new qb features to work with FindOptions
let connections: Connection[];
before(() => setupTestingConnections({ entities: [Post, Category, Tag], schemaCreate: true, dropSchemaOnConnection: true }).then(all => connections = all));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
before(() => createTestingConnections({ entities: [Post, Category, Tag], schemaCreate: true, dropSchemaOnConnection: true }).then(all => connections = all));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("basic functionality", function() {

View File

@ -1,18 +1,18 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Customer} from "./entity/Customer";
describe("indices > basic unique index test", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("unique index", function() {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -14,19 +14,14 @@ describe("lazy-relations", () => {
const profileSchema = require(resourceDir + "schema/profile.json");
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [Post, Category],
entitySchemas: [userSchema, profileSchema],
schemaCreate: true,
dropSchemaOnConnection: true,
skipPostgres: true,
skipMariadb: true,
skipSqlite: true,
skipOracle: true,
skipSqlServer: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist and hydrate successfully on a relation without inverse side", () => Promise.all(connections.map(async connection => {
const postRepository = connection.getRepository(Post);

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -7,13 +7,13 @@ import {Category} from "./entity/Category";
describe("persistence > cascade operations", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe.skip("cascade insert", function() {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -7,13 +7,13 @@ import {Category} from "./entity/Category";
describe("persistence > cascade operations with custom name", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("cascade update", function() {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -7,13 +7,13 @@ import {Category} from "./entity/Category";
describe.skip("persistence > insert operations", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("cascade insert", function() {

View File

@ -2,19 +2,19 @@ import "reflect-metadata";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
import {Connection} from "../../../../../src/connection/Connection";
import {setupTestingConnections, reloadDatabases, closeConnections} from "../../../../utils/test-utils";
import {createTestingConnections, reloadTestingDatabases, closeTestingConnections} from "../../../../utils/test-utils";
describe("persistence > insert > update-relation-columns-after-insertion", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should work perfectly", () => Promise.all(connections.map(async connection => {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -7,13 +7,13 @@ import {Category} from "./entity/Category";
describe("persistence > multi primary keys", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("insert", function () {

View File

@ -3,7 +3,6 @@ import {PrimaryColumn} from "../../../../../src/decorator/columns/PrimaryColumn"
import {Column} from "../../../../../src/decorator/columns/Column";
import {Post} from "./Post";
import {OneToMany} from "../../../../../src/decorator/relations/OneToMany";
import {JoinColumn} from "../../../../../src/decorator/relations/JoinColumn";
@Table()

View File

@ -2,7 +2,6 @@ import {Table} from "../../../../../src/decorator/tables/Table";
import {PrimaryColumn} from "../../../../../src/decorator/columns/PrimaryColumn";
import {Column} from "../../../../../src/decorator/columns/Column";
import {ManyToOne} from "../../../../../src/decorator/relations/ManyToOne";
import {JoinColumn} from "../../../../../src/decorator/relations/JoinColumn";
import {Category} from "./Category";
@Table()

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -7,13 +7,13 @@ import {Category} from "./entity/Category";
describe("persistence > multi primary keys", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("insert", function () {

View File

@ -4,7 +4,7 @@ import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
import {FindOptions} from "../../../../src/find-options/FindOptions";
import {closeConnections, reloadDatabases, setupTestingConnections} from "../../../utils/test-utils";
import {closeTestingConnections, reloadTestingDatabases, createTestingConnections} from "../../../utils/test-utils";
describe("persistence > one-to-many", function() {
@ -14,15 +14,14 @@ describe("persistence > one-to-many", function() {
let connections: Connection[];
before(() => {
return setupTestingConnections({
return createTestingConnections({
entities: [Post, Category],
schemaCreate: true,
dropSchemaOnConnection: true,
skipPostgres: true // TODO: fix it, right now postgres is failing for some reason when pooling enabled
}).then(all => connections = all);
});
after(() => closeConnections(connections));
beforeEach(() => reloadDatabases(connections));
after(() => closeTestingConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
// -------------------------------------------------------------------------
// Specifications

View File

@ -1,15 +1,14 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
import {CircularRelationsError} from "../../../../src/metadata-builder/error/CircularRelationsError";
describe("persistence > order of persistence execution operations", () => {
describe("should throw exception when non-resolvable circular relations found", function() {
it("should throw CircularRelationsError", () => setupTestingConnections({
it("should throw CircularRelationsError", () => createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
@ -20,13 +19,13 @@ describe("persistence > order of persistence execution operations", () => {
describe.skip("should persist all entities in correct order", function() {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("", () => Promise.all(connections.map(async connection => {
// create first category and post and save them

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {PostDetails} from "./entity/PostDetails";
@ -7,13 +7,13 @@ import {PostDetails} from "./entity/PostDetails";
describe("relations > relation mapped to relation with different name (#56)", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should work perfectly", () => Promise.all(connections.map(async connection => {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -7,13 +7,13 @@ import {Category} from "./entity/Category";
describe.skip("relations > relation with primary key", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
// dropSchemaOnConnection: true
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("many-to-one with primary key in relation", function() {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {QueryBuilder} from "../../../../src/query-builder/QueryBuilder";
@ -15,14 +15,14 @@ describe("repository > basic methods", () => {
const userSchema = require(resourceDir + "schema/user.json");
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [Post, Blog, Category],
entitySchemas: [userSchema, questionSchema],
schemaCreate: true,
dropSchemaOnConnection: true
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("target", function() {

View File

@ -1,6 +1,6 @@
import "reflect-metadata";
import {expect} from "chai";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
import {Connection} from "../../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {FindOptions} from "../../../../src/find-options/FindOptions";
@ -11,14 +11,14 @@ describe("repository > find methods", () => {
const userSchema = require(resourceDir + "schema/user.json");
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [Post],
entitySchemas: [userSchema],
schemaCreate: true,
dropSchemaOnConnection: true
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
describe("find and findAndCount", function() {

View File

@ -1,16 +1,16 @@
import "reflect-metadata";
import {Category} from "./entity/Category";
import {Connection} from "../../../../src/connection/Connection";
import {setupTestingConnections, reloadDatabases, closeConnections} from "../../../utils/test-utils";
import {createTestingConnections, reloadTestingDatabases, closeTestingConnections} from "../../../utils/test-utils";
describe("closure-table", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [Category],
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should work correctly when saving using parent category", () => Promise.all(connections.map(async connection => {
const categoryRepository = connection.getTreeRepository(Category);

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {expect} from "chai";
@ -8,13 +8,13 @@ import {Category} from "./entity/Category";
describe("github issues > #47 wrong sql syntax when loading lazy relation", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully and return persisted entity", () => Promise.all(connections.map(async connection => {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {User} from "./entity/User";
import {expect} from "chai";
@ -8,13 +8,13 @@ import {AccessToken} from "./entity/AccessToken";
describe("github issues > #56 relationships only work when both primary keys have the same name", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully and return persisted entity", () => Promise.all(connections.map(async connection => {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {User} from "./entity/User";
import {expect} from "chai";
@ -8,13 +8,13 @@ import {AccessToken} from "./entity/AccessToken";
describe("github issues > #57 cascade insert not working with OneToOne relationship", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully from owner side", () => Promise.all(connections.map(async connection => {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
@ -9,13 +9,13 @@ import {expect} from "chai";
describe("github issues > #58 relations with multiple primary keys", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully and return persisted entity", () => Promise.all(connections.map(async connection => {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {expect} from "chai";
@ -8,13 +8,13 @@ import {Category} from "./entity/Category";
describe("github issues > #70 cascade deleting works incorrect", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully and return persisted entity", () => Promise.all(connections.map(async connection => {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {expect} from "chai";
import {Artikel} from "./entity/Artikel";
@ -8,13 +8,13 @@ import {Kollektion} from "./entity/Kollektion";
describe("github issues > #71 ManyToOne relation with custom column name persistence fails", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully entity successfully with its many-to-one relation", () => Promise.all(connections.map(async connection => {

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {DeliveryNote} from "./entity/DeliveryNote";
import {expect} from "chai";
@ -7,12 +7,12 @@ import {expect} from "chai";
describe("github issues > #78 repository 'create' is skipping inherited fields", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully and return persisted entity", () => Promise.all(connections.map(async connection => {
const repository = connection.getRepository(DeliveryNote);

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {expect} from "chai";
@ -7,13 +7,13 @@ import {expect} from "chai";
describe("github issues > #80 repository.persist fails when empty array is sent to the method", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully and return persisted entity", () => Promise.all(connections.map(async connection => {
const post = new Post();

View File

@ -2,7 +2,7 @@ import "reflect-metadata";
import {expect} from "chai";
import {Connection} from "../../src/connection/Connection";
import {Post} from "../../sample/sample1-simple-entity/entity/Post";
import {closeConnections, reloadDatabases, setupTestingConnections} from "../utils/test-utils";
import {closeTestingConnections, reloadTestingDatabases, createTestingConnections} from "../utils/test-utils";
describe("insertion", function() {
@ -11,12 +11,12 @@ describe("insertion", function() {
// -------------------------------------------------------------------------
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [Post],
schemaCreate: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
// -------------------------------------------------------------------------
// Specifications: persist

View File

@ -1,7 +1,7 @@
import "reflect-metadata";
import {expect} from "chai";
import {Connection} from "../../src/connection/Connection";
import {createConnection, ConnectionOptions} from "../../src/index";
import {getConnectionManager, createConnection} from "../../src/index";
import {Repository} from "../../src/repository/Repository";
import {PostDetails} from "../../sample/sample2-one-to-one/entity/PostDetails";
import {Post} from "../../sample/sample2-one-to-one/entity/Post";
@ -10,7 +10,7 @@ import {PostAuthor} from "../../sample/sample2-one-to-one/entity/PostAuthor";
import {PostMetadata} from "../../sample/sample2-one-to-one/entity/PostMetadata";
import {PostImage} from "../../sample/sample2-one-to-one/entity/PostImage";
import {PostInformation} from "../../sample/sample2-one-to-one/entity/PostInformation";
import {createTestingConnectionOptions} from "../utils/test-utils";
import {setupSingleTestingConnection} from "../utils/test-utils";
describe("one-to-one", function() {
@ -18,20 +18,12 @@ describe("one-to-one", function() {
// Configuration
// -------------------------------------------------------------------------
const options: ConnectionOptions = {
driver: createTestingConnectionOptions("mysql"),
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor],
// logging: {
// logQueries: true
// }
};
// connect to db
let connection: Connection;
before(function() {
return createConnection(options)
.then(con => connection = con)
.catch(e => console.log("Error during connection to db: " + e, e.stack));
before(async function() {
connection = await createConnection(setupSingleTestingConnection("mysql", {
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor],
}));
});
after(() => connection.close());

View File

@ -1,7 +1,7 @@
import "reflect-metadata";
import {expect} from "chai";
import {Connection} from "../../src/connection/Connection";
import {createConnection, ConnectionOptions} from "../../src/index";
import {getConnectionManager, createConnection} from "../../src/index";
import {Repository} from "../../src/repository/Repository";
import {PostDetails} from "../../sample/sample3-many-to-one/entity/PostDetails";
import {Post} from "../../sample/sample3-many-to-one/entity/Post";
@ -10,7 +10,7 @@ import {PostAuthor} from "../../sample/sample3-many-to-one/entity/PostAuthor";
import {PostMetadata} from "../../sample/sample3-many-to-one/entity/PostMetadata";
import {PostImage} from "../../sample/sample3-many-to-one/entity/PostImage";
import {PostInformation} from "../../sample/sample3-many-to-one/entity/PostInformation";
import {createTestingConnectionOptions} from "../utils/test-utils";
import {setupSingleTestingConnection} from "../utils/test-utils";
describe("many-to-one", function() {
@ -18,20 +18,12 @@ describe("many-to-one", function() {
// Configuration
// -------------------------------------------------------------------------
const options: ConnectionOptions = {
driver: createTestingConnectionOptions("mysql"),
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor],
// logging: {
// logQueries: true
// }
};
// connect to db
let connection: Connection;
before(function() {
return createConnection(options)
.then(con => connection = con)
.catch(e => console.log("Error during connection to db: " + e, e.stack));
before(async function() {
connection = await createConnection(setupSingleTestingConnection("mysql", {
entities: [Post, PostDetails, PostCategory, PostMetadata, PostImage, PostInformation, PostAuthor],
}));
});
after(() => connection.close());

View File

@ -1,14 +1,14 @@
import "reflect-metadata";
import {expect} from "chai";
import {Connection} from "../../src/connection/Connection";
import {ConnectionOptions, createConnection} from "../../src/index";
import {getConnectionManager, createConnection} from "../../src/index";
import {Repository} from "../../src/repository/Repository";
import {PostDetails} from "../../sample/sample4-many-to-many/entity/PostDetails";
import {Post} from "../../sample/sample4-many-to-many/entity/Post";
import {PostCategory} from "../../sample/sample4-many-to-many/entity/PostCategory";
import {PostMetadata} from "../../sample/sample4-many-to-many/entity/PostMetadata";
import {PostImage} from "../../sample/sample4-many-to-many/entity/PostImage";
import {createTestingConnectionOptions} from "../utils/test-utils";
import {setupSingleTestingConnection} from "../utils/test-utils";
describe("many-to-many", function() {
@ -16,21 +16,12 @@ describe("many-to-many", function() {
// Configuration
// -------------------------------------------------------------------------
const options: ConnectionOptions = {
driver: createTestingConnectionOptions("mysql"),
entities: [__dirname + "/../../sample/sample4-many-to-many/entity/*"],
// logging: {
// logQueries: true,
// logSchemaCreation: true
// }
};
// connect to db
let connection: Connection;
before(function() {
return createConnection(options)
.then(con => connection = con)
.catch(e => console.log("Error during connection to db: " + e, e.stack));
before(async function() {
connection = await createConnection(setupSingleTestingConnection("mysql", {
entities: [__dirname + "/../../sample/sample4-many-to-many/entity/*"],
}));
});
after(() => connection.close());

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Post} from "./entity/Post";
import {expect} from "chai";
@ -8,13 +8,13 @@ import {Category} from "./entity/Category";
describe("other issues > using limit in conjunction with order by", () => {
let connections: Connection[];
before(async () => connections = await setupTestingConnections({
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadDatabases(connections));
after(() => closeConnections(connections));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should persist successfully and return persisted entity", () => Promise.all(connections.map(async function(connection) {

View File

@ -1,302 +1,149 @@
import {ConnectionOptions} from "../../src/connection/ConnectionOptions";
import {createConnection} from "../../src/index";
import {createConnection, createConnections} from "../../src/index";
import {Connection} from "../../src/connection/Connection";
import {DriverOptions} from "../../src/driver/DriverOptions";
import {DriverType} from "../../src/driver/DriverOptions";
import {EntitySchema} from "../../src/entity-schema/EntitySchema";
export interface TestingConnectionOptions {
entitySchemas?: EntitySchema[];
entities?: string[]|Function[];
secondaryConnections?: boolean;
schemaCreate?: boolean;
dropSchemaOnConnection?: boolean;
reloadAndCreateSchema?: boolean;
skipMysql?: boolean;
skipMariadb?: boolean;
skipPostgres?: boolean;
skipSqlite?: boolean;
skipSqlserver?: boolean;
skipOracle?: boolean;
skipSqlServer?: boolean;
}
/**
* Interface in which data is stored in ormconfig.json of the project.
*/
interface TestingConnectionOptions extends ConnectionOptions {
export function closeConnections(connections: Connection[]) {
return Promise.all(connections.map(connection => connection.isConnected ? connection.close() : undefined));
}
/**
* Indicates if this connection should be skipped.
*/
skip: boolean;
export function createTestingConnectionOptions(type: "mysql"|"mysqlSecondary"|"mariadb"|"mariadbSecondary"|"postgres"|"postgresSecondary"|"sqlite"|"sqliteSecondary"|"mssql"|"mssqlSecondary"): DriverOptions {
const parameters = require(__dirname + "/../../../../config/parameters.json"); // path is relative to compile directory
// const parameters = require(__dirname + "/../../config/parameters.json");
let driverType: "mysql"|"mariadb"|"postgres"|"sqlite"|"mssql" = "mysql"; // = type === "mysql" || type === "mysqlSecondary" ? "mysql" : "postgres";
if (type === "mysql" || type === "mysqlSecondary") {
driverType = "mysql";
} else if (type === "mariadb" || type === "mariadbSecondary") {
driverType = "mariadb";
} else if (type === "postgres" || type === "postgresSecondary") {
driverType = "postgres";
} else if (type === "sqlite" || type === "sqliteSecondary") {
driverType = "sqlite";
} else if (type === "mssql" || type === "mssqlSecondary") {
driverType = "mssql";
}
return {
type: driverType,
host: parameters.connections[type].host,
port: parameters.connections[type].port,
username: parameters.connections[type].username,
password: parameters.connections[type].password,
database: parameters.connections[type].database,
storage: parameters.connections[type].storage
};
}
/*export async function setupTestingConnections(options?: TestingConnectionOptions) {
const parameters: ConnectionOptions = {
driver: createTestingConnectionOptions(process.env["connection_setup_name"]),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
entities: options && options.entities ? options.entities : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const connection = await createConnection(parameters);
if (options && options.reloadAndCreateSchema)
await connection.syncSchema(true);
return [connection];
}*/
export async function setupTestingConnections(options?: TestingConnectionOptions): Promise<Connection[]> {
const mysqlParameters: ConnectionOptions = {
name: "mysqlPrimaryConnection",
driver: createTestingConnectionOptions("mysql"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const mysqlSecondaryParameters: ConnectionOptions = {
name: "mysqlSecondaryConnection",
driver: createTestingConnectionOptions("mysqlSecondary"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const mariadbParameters: ConnectionOptions = {
name: "mariadbPrimaryConnection",
driver: createTestingConnectionOptions("mariadb"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const mariadbSecondaryParameters: ConnectionOptions = {
name: "mariadbSecondaryConnection",
driver: createTestingConnectionOptions("mariadbSecondary"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const postgresParameters: ConnectionOptions = {
name: "postgresPrimaryConnection",
driver: createTestingConnectionOptions("postgres"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const postgresSecondaryParameters: ConnectionOptions = {
name: "postgresSecondaryConnection",
driver: createTestingConnectionOptions("postgresSecondary"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const sqliteParameters: ConnectionOptions = {
name: "sqlitePrimaryConnection",
driver: createTestingConnectionOptions("sqlite"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const sqliteSecondaryParameters: ConnectionOptions = {
name: "sqliteSecondaryConnection",
driver: createTestingConnectionOptions("sqliteSecondary"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const mssqlParameters: ConnectionOptions = {
name: "mssqlPrimaryConnection",
driver: createTestingConnectionOptions("mssql"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const mssqlSecondaryParameters: ConnectionOptions = {
name: "mssqlSecondaryConnection",
driver: createTestingConnectionOptions("mssqlSecondary"),
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},
};
const mysql = true; // !options || !options.skipMysql;
const mariadb = true; // !options || !options.skipMariadb;
const postgres = true; // !options || !options.skipPostgres;
const sqlite = true; // !options || !options.skipSqlite;
const mssql = false; // !options || !options.skipSqlserver;
const allParameters: ConnectionOptions[] = [];
if (mysql)
allParameters.push(mysqlParameters);
if (mariadb)
allParameters.push(mariadbParameters);
if (postgres)
allParameters.push(postgresParameters);
if (sqlite)
allParameters.push(sqliteParameters);
if (mssql)
allParameters.push(mssqlParameters);
if (mysql && options && options.secondaryConnections)
allParameters.push(mysqlSecondaryParameters);
if (mariadb && options && options.secondaryConnections)
allParameters.push(mariadbSecondaryParameters);
if (postgres && options && options.secondaryConnections)
allParameters.push(postgresSecondaryParameters);
if (sqlite && options && options.secondaryConnections)
allParameters.push(sqliteSecondaryParameters);
if (mssql && options && options.secondaryConnections)
allParameters.push(mssqlSecondaryParameters);
return Promise.all(allParameters.map(async parameters => {
const connection = await createConnection(parameters);
if (options && options.reloadAndCreateSchema)
await connection.syncSchema(true);
return connection;
}));
}
/**
* @deprecated
* Options used to create a connection for testing purposes.
*/
export function setupConnection(callback: (connection: Connection) => any, entities: Function[]) {
export interface TestingOptions {
/**
* Connection name to be overridden.
* This can be used to create multiple connections with single connection configuration.
*/
name?: string;
const parameters: ConnectionOptions = {
driver: {
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "admin",
database: "test"
},
// logging: {
// logQueries: true
// },
autoSchemaSync: true,
entities: entities
};
/**
* List of enabled drivers for the given test suite.
*/
enabledDrivers?: DriverType[];
/**
* Entities needs to be included in the connection for the given test suite.
*/
entities?: string[]|Function[];
/**
* Entity schemas needs to be included in the connection for the given test suite.
*/
entitySchemas?: EntitySchema[];
/**
* Indicates if schema sync should be performed or not.
*/
schemaCreate?: boolean;
/**
* Indicates if schema should be dropped on connection setup.
*/
dropSchemaOnConnection?: boolean;
return function() {
return createConnection(parameters)
.then(connection => {
if (callback)
callback(connection);
return connection;
})
.catch(e => {
console.log("Error during connection to db: " + e);
throw e;
});
};
}
export function reloadDatabases(connections: Connection[]) {
/**
* Creates a testing connection options for the given driver type based on the configuration in the ormconfig.json
* and given options that can override some of its configuration for the test-specific use case.
*/
export function setupSingleTestingConnection(driverType: DriverType, options: TestingOptions) {
const testingConnections = setupTestingConnections({
name: options.name ? options.name : undefined,
entities: options.entities ? options.entities : [],
entitySchemas: options.entitySchemas ? options.entitySchemas : [],
dropSchemaOnConnection: options.dropSchemaOnConnection ? options.dropSchemaOnConnection : false,
schemaCreate: options.schemaCreate ? options.schemaCreate : false,
enabledDrivers: [driverType]
});
if (!testingConnections.length)
throw new Error(`Unable to run tests because connection options for "${driverType}" are not set.`);
return testingConnections[0];
}
/**
* Creates a testing connections options based on the configuration in the ormconfig.json
* and given options that can override some of its configuration for the test-specific use case.
*/
export function setupTestingConnections(options?: TestingOptions) {
let ormConfigConnectionOptionsArray: TestingConnectionOptions[] = [];
try {
ormConfigConnectionOptionsArray = require(__dirname + "/../../../../ormconfig.json");
} catch (err) {
throw new Error(`Cannot find ormconfig.json file in the root of the project. To run tests please create ormconfig.json file` +
` in the root of the project (near ormconfig.json.dist, you need to copy ormconfig.json.dist into ormconfig.json` +
` and change all database settings to match your local environment settings).`);
}
if (!ormConfigConnectionOptionsArray.length)
throw new Error(`No connections setup in ormconfig.json file. Please create configurations for each database type to run tests.`);
return ormConfigConnectionOptionsArray
.filter(connectionOptions => {
if (options && options.enabledDrivers && options.enabledDrivers.length)
return options.enabledDrivers.indexOf(connectionOptions.driver.type) !== -1;
return !connectionOptions.skip;
})
.map(connectionOptions => {
return Object.assign({}, connectionOptions as ConnectionOptions, {
name: options && options.name ? options.name : connectionOptions.name,
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
autoSchemaSync: options && options.entities ? options.schemaCreate : false,
dropSchemaOnConnection: options && options.entities ? options.dropSchemaOnConnection : false,
});
});
}
/**
* Creates a testing connections based on the configuration in the ormconfig.json
* and given options that can override some of its configuration for the test-specific use case.
*/
export async function createTestingConnections(options?: TestingOptions): Promise<Connection[]> {
return createConnections(setupTestingConnections(options));
}
/**
* Closes testing connections if they are connected.
*/
export function closeTestingConnections(connections: Connection[]) {
return Promise.all(connections.map(connection => connection.isConnected ? connection.close() : undefined));
}
/**
* Reloads all databases for all given connections.
*/
export function reloadTestingDatabases(connections: Connection[]) {
return Promise.all(connections.map(connection => connection.syncSchema(true)));
}
/**
* Setups connection.
*
* @deprecated Old method of creating connection. Don't use it anymore. Use createTestingConnections instead.
*/
export function reloadDatabase(connection: Connection) {
return function () {
return connection.syncSchema(true)
.catch(e => console.log("Error during schema re-creation: ", e));
export function setupConnection(callback: (connection: Connection) => any, entities: Function[]) {
return function() {
return createConnection(setupSingleTestingConnection("mysql", { entities: entities }))
.then(connection => {
if (callback)
callback(connection);
return connection;
});
};
}