mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
refactored test for #160
This commit is contained in:
parent
93756f0876
commit
1121a8df3d
@ -55,19 +55,6 @@
|
||||
"logQueries": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"skip": false,
|
||||
"name": "postgres-schema",
|
||||
"driver": {
|
||||
"type": "postgres",
|
||||
"host": "localhost",
|
||||
"port": 5432,
|
||||
"username": "test",
|
||||
"password": "test",
|
||||
"database": "test",
|
||||
"schemaName": "test-schema"
|
||||
}
|
||||
},
|
||||
{
|
||||
"skip": true,
|
||||
"name": "mssql",
|
||||
|
||||
@ -360,12 +360,13 @@ describe("Connection", () => {
|
||||
|
||||
});
|
||||
|
||||
describe("Can change postgres default schema name", () => {
|
||||
describe.only("Can change postgres default schema name", () => {
|
||||
let connections: Connection[];
|
||||
beforeEach(async () => {
|
||||
connections = await createTestingConnections({
|
||||
enabledDrivers: ["postgres"],
|
||||
entities: [Post]
|
||||
entities: [Post],
|
||||
schemaName: "test-schema"
|
||||
});
|
||||
});
|
||||
afterEach(() => closeTestingConnections(connections));
|
||||
@ -380,8 +381,7 @@ describe("Connection", () => {
|
||||
await PostRepo.persist(post);
|
||||
|
||||
const query = await connection.driver.createQueryRunner();
|
||||
const schemaName = connection.driver.options.schemaName || "public";
|
||||
const rows = await query.query(`select * from "${schemaName}"."post" where id = $1`, [post.id]);
|
||||
const rows = await query.query(`select * from "test-schema"."post" where id = $1`, [post.id]);
|
||||
expect(rows[0]["title"]).to.be.eq(post.title);
|
||||
}));
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ interface TestingConnectionOptions extends ConnectionOptions {
|
||||
* Options used to create a connection for testing purposes.
|
||||
*/
|
||||
export interface TestingOptions {
|
||||
|
||||
/**
|
||||
* Connection name to be overridden.
|
||||
* This can be used to create multiple connections with single connection configuration.
|
||||
@ -51,6 +52,11 @@ export interface TestingOptions {
|
||||
*/
|
||||
dropSchemaOnConnection?: boolean;
|
||||
|
||||
/**
|
||||
* Schema name used for postgres driver.
|
||||
*/
|
||||
schemaName?: string;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +71,8 @@ export function setupSingleTestingConnection(driverType: DriverType, options: Te
|
||||
entitySchemas: options.entitySchemas ? options.entitySchemas : [],
|
||||
dropSchemaOnConnection: options.dropSchemaOnConnection ? options.dropSchemaOnConnection : false,
|
||||
schemaCreate: options.schemaCreate ? options.schemaCreate : false,
|
||||
enabledDrivers: [driverType]
|
||||
enabledDrivers: [driverType],
|
||||
schemaName: options.schemaName ? options.schemaName : undefined
|
||||
});
|
||||
if (!testingConnections.length)
|
||||
throw new Error(`Unable to run tests because connection options for "${driverType}" are not set.`);
|
||||
@ -106,13 +113,21 @@ export function setupTestingConnections(options?: TestingOptions) {
|
||||
return !connectionOptions.skip;
|
||||
})
|
||||
.map(connectionOptions => {
|
||||
return Object.assign({}, connectionOptions as ConnectionOptions, {
|
||||
const newConnectionOptions = 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,
|
||||
});
|
||||
|
||||
|
||||
if (options && options.schemaName && newConnectionOptions.driver) {
|
||||
// todo: we use any because driver.schemaName is readonly. Need to find better solution here
|
||||
(newConnectionOptions.driver as any).schemaName = options.schemaName;
|
||||
}
|
||||
|
||||
return newConnectionOptions;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user