-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Database Factory Constructor A factory constructor for the database is used to allow for unit testing. * Added Testing Infastructure * Update package.json
- Loading branch information
1 parent
f7b4963
commit 42beba9
Showing
22 changed files
with
11,178 additions
and
2,899 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
export type user_token = { username: string, admin: string } | ||
export type env_file = { | ||
PORT: number, | ||
URI?: string, | ||
DB?: string, | ||
TOKEN_KEY: string, | ||
SECRET_KEY: string, | ||
ENCRYPT_KEY: string, | ||
IV_KEY: string, | ||
DOMAIN: string, | ||
PROD: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Express } from "express" | ||
import { Server } from "http"; | ||
import supertest = require("supertest"); | ||
import { create_app } from "../app"; | ||
import { start_server } from "../server"; | ||
const request = require('supertest'); | ||
|
||
let app: Express | ||
let server: Server | ||
|
||
beforeAll(async() => { | ||
app = await create_app() | ||
}) | ||
|
||
|
||
test("should return OK response generating survey", (done) => { | ||
const survey_url = "https://raw.githubusercontent.com/Watts-Lab/surveyor/main/surveys/CRT.csv" | ||
|
||
request(app) | ||
.get(`/s/?url=${survey_url}`) | ||
.expect(200) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
return done(); | ||
}) | ||
|
||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
/** @format */ | ||
require("dotenv").config(); | ||
import { startServer } from "./server"; | ||
import express = require("express"); | ||
import cors = require("cors"); | ||
import { json, urlencoded } from "body-parser"; | ||
import session = require("express-session"); | ||
import { env_config } from "./config"; | ||
import { Express } from "express" | ||
var cookieParser = require("cookie-parser") | ||
// Router Imports | ||
const links_router = require("./routes/links") | ||
const survey_router = require("./routes/survey") | ||
const auth_router = require("./routes/auth") | ||
const encrypt_router = require("./routes/encrypt") | ||
const validate_router = require("./routes/validation") | ||
|
||
async function main(): Promise<void> { | ||
// should be updated to Load CSV from URL (we can hard code that URL for now, and can deal with dynamic coding later) | ||
startServer(); | ||
} | ||
|
||
main(); | ||
export async function create_app():Promise<Express> { | ||
const app = express() | ||
app.use(cors()) | ||
app.use( | ||
session({ | ||
secret: env_config.TOKEN_KEY, // just a long random string | ||
resave: false, | ||
saveUninitialized: true, | ||
}) | ||
); | ||
|
||
app.set("view engine", "pug"); | ||
app.use(express.static("public")); // More info on this: http://expressjs.com/en/starter/static-files.html | ||
app.use(json()); // for parsing application/json | ||
app.use(urlencoded({ extended: true })); // for parsing url | ||
app.use(cookieParser()) | ||
|
||
/** ROUTES */ | ||
app.use("/", survey_router) | ||
app.use("/", links_router) | ||
app.use("/", auth_router) | ||
app.use("/", encrypt_router) | ||
app.use("/validate", validate_router) | ||
|
||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import { Database_Wrapper } from "./interfaces"; | ||
import Mongo from "./databases/prod_db"; | ||
|
||
import Mongo from "./databases/db"; | ||
import { env_file } from "./@types"; | ||
import { MongoMemoryServer } from 'mongodb-memory-server'; | ||
|
||
|
||
const env_config = { | ||
PORT: parseInt(process.env.PORT), | ||
URI: process.env.URI, | ||
DB: process.env.PROD.toLowerCase() == "true" ? process.env.PROD_DB : process.env.TEST_DB, | ||
RANDOM: process.env.RANDOM, | ||
TOKEN_KEY: process.env.TOKEN_KEY, | ||
SECRET_KEY: process.env.SECRET_KEY, | ||
ENCRYPT_KEY: process.env.ENCRYPT_KEY, | ||
IV_KEY: process.env.IV_KEY, | ||
DOMAIN: process.env.DOMAIN | ||
const env_config: env_file = { | ||
PORT: parseInt(process.env.PORT), | ||
URI: process.env.URI, | ||
DB: process.env.PROD.toLowerCase() == "true" ? process.env.PROD_DB : process.env.TEST_DB, | ||
TOKEN_KEY: process.env.TOKEN_KEY, | ||
SECRET_KEY: process.env.SECRET_KEY, | ||
ENCRYPT_KEY: process.env.ENCRYPT_KEY, | ||
IV_KEY: process.env.IV_KEY, | ||
DOMAIN: process.env.DOMAIN, | ||
PROD: process.env.PROD.toLowerCase() == "true" | ||
} | ||
|
||
if (env_config.URI === undefined || env_config.DB === undefined) { | ||
throw new Error("Please set mongo db uri or db") | ||
} | ||
|
||
const Db_Wrapper: Database_Wrapper = new Mongo(env_config); | ||
Db_Wrapper.set_db(env_config.DB); | ||
|
||
export {Db_Wrapper, env_config} | ||
export {env_config} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { env_file } from "./@types"; | ||
|
||
export interface Database_Wrapper { | ||
set_db(db: any): void; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testPathIgnorePatterns : [ | ||
"<rootDir>/built/" | ||
], | ||
globalTeardown: '<rootDir>/teardown.js', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.