mirror of
https://github.com/sasjs/server.git
synced 2026-01-11 00:10:06 +00:00
test: fixed specs
This commit is contained in:
@@ -37,22 +37,26 @@ if (MODE?.trim() !== 'server' || CORS?.trim() === 'enable') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MODE?.trim() === 'server') {
|
if (MODE?.trim() === 'server') {
|
||||||
const clientPromise = connectDB().then((conn) => conn!.getClient() as any)
|
// NOTE: when exporting app.js as agent for supertest
|
||||||
|
// we should exclude connecting to the real database
|
||||||
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
|
const clientPromise = connectDB().then((conn) => conn!.getClient() as any)
|
||||||
|
|
||||||
const { PROTOCOL } = process.env
|
const { PROTOCOL } = process.env
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
session({
|
session({
|
||||||
secret: process.env.SESSION_SECRET as string,
|
secret: process.env.SESSION_SECRET as string,
|
||||||
saveUninitialized: false, // don't create session until something stored
|
saveUninitialized: false, // don't create session until something stored
|
||||||
resave: false, //don't save session if unmodified
|
resave: false, //don't save session if unmodified
|
||||||
store: MongoStore.create({ clientPromise, collectionName: 'sessions' }),
|
store: MongoStore.create({ clientPromise, collectionName: 'sessions' }),
|
||||||
cookie: {
|
cookie: {
|
||||||
secure: PROTOCOL === 'https',
|
secure: PROTOCOL === 'https',
|
||||||
maxAge: 24 * 60 * 60 * 1000 // 24 hours
|
maxAge: 24 * 60 * 60 * 1000 // 24 hours
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(cookieParser())
|
app.use(cookieParser())
|
||||||
|
|||||||
@@ -2,19 +2,6 @@ import mongoose from 'mongoose'
|
|||||||
import { seedDB } from './seedDB'
|
import { seedDB } from './seedDB'
|
||||||
|
|
||||||
export const connectDB = async () => {
|
export const connectDB = async () => {
|
||||||
// NOTE: when exporting app.js as agent for supertest
|
|
||||||
// we should exclude connecting to the real database
|
|
||||||
if (process.env.NODE_ENV === 'test') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const { MODE } = process.env
|
|
||||||
|
|
||||||
if (MODE?.trim() !== 'server') {
|
|
||||||
console.log('Running in Desktop Mode, no DB to connect.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await mongoose.connect(process.env.DB_CONNECT as string)
|
await mongoose.connect(process.env.DB_CONNECT as string)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user