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:
3
integration-tests/.env.template
Normal file
3
integration-tests/.env.template
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default postgres credentials
|
||||
DB_USERNAME=postgres
|
||||
DB_PASSWORD=''
|
||||
3
integration-tests/.gitignore
vendored
Normal file
3
integration-tests/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
.npm
|
||||
.env
|
||||
@@ -1,8 +1,11 @@
|
||||
const DB_USERNAME = process.env.DB_USERNAME || "postgres";
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD || "";
|
||||
|
||||
module.exports = {
|
||||
plugins: [],
|
||||
projectConfig: {
|
||||
// redis_url: REDIS_URL,
|
||||
database_url: "postgres://localhost/medusa-integration",
|
||||
database_url: `postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost/medusa-integration`,
|
||||
database_type: "postgres",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa": "1.1.29-dev-1626162503472",
|
||||
"medusa-interfaces": "1.1.17-dev-1626162503472",
|
||||
"@medusajs/medusa": "^1.1.32",
|
||||
"medusa-interfaces": "^1.1.18",
|
||||
"typeorm": "^0.2.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.10",
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/node": "^7.12.10",
|
||||
"babel-preset-medusa-package": "1.1.10-dev-1626162503472",
|
||||
"babel-preset-medusa-package": "^1.1.11",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
14
integration-tests/package-lock.json
generated
Normal file
14
integration-tests/package-lock.json
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "integration-tests",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"dotenv": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
14
integration-tests/package.json
Normal file
14
integration-tests/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "integration-tests",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "jest.config.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Zakaria S. El Asri",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"dotenv": "^10.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1673,10 +1673,10 @@ babel-preset-jest@^25.5.0:
|
||||
babel-plugin-jest-hoist "^25.5.0"
|
||||
babel-preset-current-node-syntax "^0.1.2"
|
||||
|
||||
babel-preset-medusa-package@^1.1.5-next.0:
|
||||
version "1.1.5-next.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.5-next.0.tgz#3ab62092742ae4976f80e2d0f9ff887866d7f032"
|
||||
integrity sha512-M+DDbIi2VLZdir+svQIpWhUACHTE/1Cx2aQ8zU/n+0kb29yxMVNWqZto9m4Uh3c9PkoSnZfOYpu1AG/5RPByjw==
|
||||
babel-preset-medusa-package@^1.1.12:
|
||||
version "1.1.12"
|
||||
resolved "https://registry.yarnpkg.com/babel-preset-medusa-package/-/babel-preset-medusa-package-1.1.12.tgz#d2acba935813ff080ecac40664bad413432bfcc8"
|
||||
integrity sha512-haNteSlZu6uZUbUr+361JDi+h5Ky1WAzThJe0Q6EswfdvsqEbmGRibCQHZXW4S2LLr9d5UAoeX7azPDRWC2u0A==
|
||||
dependencies:
|
||||
"@babel/plugin-proposal-class-properties" "^7.12.1"
|
||||
"@babel/plugin-proposal-decorators" "^7.12.1"
|
||||
@@ -4545,28 +4545,28 @@ media-typer@0.3.0:
|
||||
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
||||
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
|
||||
|
||||
medusa-core-utils@^1.1.11-next.0, medusa-core-utils@^1.1.11-next.0+60da043:
|
||||
version "1.1.11-next.0"
|
||||
resolved "https://registry.yarnpkg.com/medusa-core-utils/-/medusa-core-utils-1.1.11-next.0.tgz#c65ec751f48a3abf530bea598793fbbb96b84796"
|
||||
integrity sha512-v4qqsRAOBvueJcKeMD8uL2Qb9dvR+qh3sDvW8C+1bpbnjuTbIq2D+d/xT+963mx3+e445XRoePjXNLltUcSicw==
|
||||
medusa-core-utils@^1.1.18:
|
||||
version "1.1.18"
|
||||
resolved "https://registry.yarnpkg.com/medusa-core-utils/-/medusa-core-utils-1.1.18.tgz#2c2c49eeee796493a81bfab58db3f1ef164e6b1b"
|
||||
integrity sha512-xPE+yrC2cvcWdVQwDUDGJGF0WeRYEdkt/qDtzMCtxsed772YPQ+g2DB1IRi9Kae88P127w8pj9XNGQWPYDsOBA==
|
||||
dependencies:
|
||||
joi "^17.3.0"
|
||||
joi-objectid "^3.0.1"
|
||||
|
||||
medusa-interfaces@^1.1.12-next.0:
|
||||
version "1.1.12-next.0"
|
||||
resolved "https://registry.yarnpkg.com/medusa-interfaces/-/medusa-interfaces-1.1.12-next.0.tgz#12f0b6eb068c729b10a66b693462e765a7661954"
|
||||
integrity sha512-55CrFN4QHtUo32XQ88qKw1/CfqwikQxNnR2u05Xyyc63efoxlk6tlGg5o8PH74rA3kwQgmztjfG859GtwBRoOg==
|
||||
medusa-interfaces@^1.1.19:
|
||||
version "1.1.19"
|
||||
resolved "https://registry.yarnpkg.com/medusa-interfaces/-/medusa-interfaces-1.1.19.tgz#8fa162bbc40a6ad4c632f65dfa531a01a0157ab8"
|
||||
integrity sha512-lSebIMjg3JMjmY+wkdvKN1feb5R1p+ZaVNUpBGFh9MQpf5Lgb20OUTpuSoofVYjN0+/nTKHTuyQan6uDuDaP4Q==
|
||||
dependencies:
|
||||
medusa-core-utils "^1.1.11-next.0+60da043"
|
||||
medusa-core-utils "^1.1.18"
|
||||
|
||||
medusa-test-utils@^1.1.14-next.0:
|
||||
version "1.1.14-next.0"
|
||||
resolved "https://registry.yarnpkg.com/medusa-test-utils/-/medusa-test-utils-1.1.14-next.0.tgz#29a85e7f08da811e3f2c735de5a906522de23948"
|
||||
integrity sha512-NMUP7d1HH91piXLZGeF6ifEiyI4cA8jp7OTrD8+i/miS0HwilGxsXxqfzolzgsB/2AWiDrLdWg+pFF8JREQT2Q==
|
||||
medusa-test-utils@^1.1.21:
|
||||
version "1.1.21"
|
||||
resolved "https://registry.yarnpkg.com/medusa-test-utils/-/medusa-test-utils-1.1.21.tgz#f7fedb6af4aee0cbf8926769e6d721e09ebf4a59"
|
||||
integrity sha512-+Hqtb/opWvpEGuCb0zXtYbilHc3j5MGr3pxldwULHxMy9oJmDMME0eF2znd6aQADQipdq2wXGNaBZNG5V6vEwQ==
|
||||
dependencies:
|
||||
"@babel/plugin-transform-classes" "^7.9.5"
|
||||
medusa-core-utils "^1.1.11-next.0+60da043"
|
||||
medusa-core-utils "^1.1.18"
|
||||
randomatic "^3.1.1"
|
||||
|
||||
merge-descriptors@1.0.1:
|
||||
|
||||
Reference in New Issue
Block a user