diff --git a/app.js b/app.js index 07a9422..cfc8175 100644 --- a/app.js +++ b/app.js @@ -5,18 +5,21 @@ let cookieParser = require("cookie-parser"); let logger = require("morgan"); let sassMiddleware = require("node-sass-middleware"); const session = require("express-session"); -const config = require("./config/config.json"); +let config = process.env.NODE_ENV === "test" ? {} : require("./config/config.json"); let indexRouter = require("./routes/index"); const loginRouter = require("./routes/login"); let app = express(); -const sessionMiddleware = session({secret: config.secret}); +const sessionMiddleware = session({ + secret: process.env.NODE_ENV === "test" ? "Keyboard Cat" : config.secret +}); // view engine setup app.set("views", path.join(__dirname, "views")); app.set("view engine", "pug"); app.set("sessionMiddleware", sessionMiddleware); +app.set("config", config); app.use(logger("dev")); app.use(express.json()); diff --git a/models/index.js b/models/index.js index 7f48144..0163cc8 100644 --- a/models/index.js +++ b/models/index.js @@ -4,7 +4,6 @@ const fs = require("fs"); const path = require("path"); const Sequelize = require("sequelize"); const basename = path.basename(__filename); -const config = require(__dirname + "/../config/config.json")["database"]; const db = {}; let sequelize; diff --git a/models/user.js b/models/user.js index e6b0f11..21212fc 100644 --- a/models/user.js +++ b/models/user.js @@ -1,7 +1,7 @@ "use strict"; const crypto = require("crypto"); -const privateKey = require("../config/config.json").passwordPrivateKey; +const privateKey = process.env.NODE_ENV === "test" ? require("../config/config_example.json") : require("../config/config.json").passwordPrivateKey; const { Model