Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"use strict";
'use strict';

const path = require("path");
const pathToHooks = path.join(process.cwd(), "test", "setup", "hook.js");
const path = require('path');
const pathToHooks = path.join(process.cwd(), 'test', 'setup', 'hook.js');

module.exports = {
// spec: "test/**/*.test.js",
require: pathToHooks,
// file: [pathToHooks],
recursive: true,
reporter: "spec",
reporter: 'spec',
parallel: false,
ignore: ["/path/to/some/ignored/file"],
extension: ["js", "cjs", "mjs"],
ignore: ['/path/to/some/ignored/file'],
extension: ['js', 'cjs', 'mjs'],
color: true,
diff: true,
exit: true,
};
6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: true,
singleQuote: true,
};
12 changes: 1 addition & 11 deletions config/environments/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@
"port": 4000,
"db": {
"username": "root",
"password": null,
"password": "",
"name": "productbox",
"host": "127.0.0.1"
},
"auth0_primary": {
"clientId": "",
"clientSecret": "",
"domain": "",
"connection": ""
},
"auth0_secondary": {
"clientId": "",
"clientSecret": ""
}
}
15 changes: 3 additions & 12 deletions config/environments/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
"port": 4000,
"db": {
"username": "root",
"password": null,
"password": "",
"name": "productbox_test",
"host": "127.0.0.1"
},
"auth0_primary": {
"clientId": "",
"clientSecret": "",
"domain": "",
"connection": ""
},
"auth0_secondary": {
"clientId": "",
"clientSecret": ""
"host": "127.0.0.1",
"port": 3306
}
}
91 changes: 28 additions & 63 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,62 @@
const convict = require("convict");
const convict = require('convict');

// Define a schema
var config = convict({
env: {
doc: "The application environment.",
format: ["production", "development", "test"],
default: "development",
env: "NODE_ENV",
doc: 'The application environment.',
format: ['production', 'development', 'test'],
default: 'development',
env: 'NODE_ENV',
},
ip: {
doc: "The IP address to bind.",
format: "ipaddress",
default: "127.0.0.1",
env: "IP_ADDRESS",
doc: 'The IP address to bind.',
format: 'ipaddress',
default: '127.0.0.1',
env: 'IP_ADDRESS',
},
port: {
doc: "The port to bind.",
format: "port",
doc: 'The port to bind.',
format: 'port',
default: 8080,
env: "PORT",
arg: "port",
env: 'PORT',
arg: 'port',
},
db: {
host: {
doc: "Database host name/IP",
doc: 'Database host name/IP',
format: String,
default: "127.0.0.1",
default: '127.0.0.1',
},
name: {
doc: "Database name",
doc: 'Database name',
format: String,
default: "database_development",
default: 'database_development',
},
username: {
doc: "db user",
doc: 'db user',
format: String,
default: "root",
default: 'root',
},
password: {
doc: "db password",
format: "*",
doc: 'db password',
format: '*',
default: null,
},
},
auth0_primary: {
clientId: {
doc: "Auth0 primary application clientID",
format: String,
default: null,
env: "AUTH0_CLIENT_ID",
},
clientSecret: {
doc: "Auth0 primary application Secret",
format: String,
default: null,
env: "AUTH0_CLIENT_SECRET",
},
domain: {
doc: "Auth0 application Domain name",
format: String,
default: null,
env: "AUTH0_DOMAIN",
},
connection: {
doc: "Auth0 connection/realm identifier",
format: String,
default: null,
env: "AUTH0_CONNECTION",
},
},
auth0_secondary: {
clientId: {
doc: "Auth0 secondary application clientID",
format: String,
default: null,
env: "AUTH0_CLIENT_ID_SECONDARY",
},
clientSecret: {
doc: "Auth0 secondary application Secret",
format: String,
default: null,
env: "AUTH0_CLIENT_SECRET_SECONDARY",
port: {
doc: 'db port',
format: Number,
default: 3306,
},
},
});

// Load environment dependent configuration
let env = config.get("env");
let env = config.get('env');
if (env) {
config.loadFile(__dirname + "/environments/" + env + ".json");
config.loadFile(__dirname + '/environments/' + env + '.json');
}

// Perform validation
config.validate({ allowed: "strict" });
config.validate({ allowed: 'strict' });

module.exports = config;
71 changes: 27 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start-test": "./node_modules/pm2/bin/pm2 start server.js --no-daemon --watch --no-autorestart --env test",
"stop-server": "./node_modules/pm2/bin/pm2 stop server.js",
"logs": "./node_modules/pm2/bin/pm2 logs",
"test": "NODE_ENV=test mocha test",
"test": "mocha test",
"test-coverage": "nyc npm run test",
"lint": "npx eslint .",
"prettier": "npx prettier -c .",
Expand All @@ -29,7 +29,7 @@
"express-jwt": "^6.0.0",
"express-jwt-authz": "^2.4.1",
"lodash": "^4.17.20",
"mysql2": "^2.1.0",
"mysql2": "^2.3.3",
"pm2": "^4.4.0",
"sequelize": "^5.21.7"
},
Expand Down
18 changes: 11 additions & 7 deletions test/setup/hook.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
const chai = require("chai");
const chaiHttp = require("chai-http");

const { migrate, revert } = require("./migration-runner");

process.env.NODE_ENV = 'test';
global.config = require('../../config');
const chai = require('chai');
const chaiHttp = require('chai-http');
const { migrate, revert } = require('./migration-runner');
const { server } = require('../setup/testHelper');
chai.use(chaiHttp);

exports.mochaHooks = {
beforeAll: async function () {
// do something before all test once
console.log("running migrations...");
console.log('running migrations...');
await migrate();
},
afterAll: async function () {
// do something after all test once
console.log("reverting migrations...");
console.log('closing server');
server.close();

console.log('reverting migrations...');
await revert();
},
};
Loading