fix: parameterize integration tests' db credentials (#319)
* add: read db credentials from .env * remove: console.log * fix: default to default pg user and password
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({ path: path.join(__dirname, "../.env") });
|
||||
|
||||
const { dropDatabase, createDatabase } = require("pg-god");
|
||||
const { createConnection } = require("typeorm");
|
||||
|
||||
const path = require("path");
|
||||
const DB_USERNAME = process.env.DB_USERNAME || "postgres";
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD || "";
|
||||
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost/medusa-integration`;
|
||||
const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
};
|
||||
|
||||
const DbTestUtil = {
|
||||
db_: null,
|
||||
@@ -16,7 +25,7 @@ const DbTestUtil = {
|
||||
|
||||
shutdown: async function () {
|
||||
await this.db_.close();
|
||||
return dropDatabase({ databaseName });
|
||||
return dropDatabase({ databaseName }, pgGodCredentials);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -36,11 +45,11 @@ module.exports = {
|
||||
);
|
||||
|
||||
const databaseName = "medusa-integration";
|
||||
await createDatabase({ databaseName });
|
||||
await createDatabase({ databaseName }, pgGodCredentials);
|
||||
|
||||
const connection = await createConnection({
|
||||
type: "postgres",
|
||||
url: "postgres://localhost/medusa-integration",
|
||||
url: DB_URL,
|
||||
migrations: [`${migrationDir}/*.js`],
|
||||
});
|
||||
|
||||
@@ -60,7 +69,7 @@ module.exports = {
|
||||
const entities = modelsLoader({}, { register: false });
|
||||
const dbConnection = await createConnection({
|
||||
type: "postgres",
|
||||
url: "postgres://localhost/medusa-integration",
|
||||
url: DB_URL,
|
||||
entities,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user