Skip to content

Commit

Permalink
Transition more queries to Sequelize Raw Queries and fix up a majorit…
Browse files Browse the repository at this point in the history
…y of the tests to not fail
  • Loading branch information
malee31 committed Oct 7, 2024
1 parent 77c657b commit 2ca2763
Show file tree
Hide file tree
Showing 13 changed files with 645 additions and 231 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { API_PORT } from "./config.js";
import app, { activateApiRouter } from "./src/app.js";
import database from "./src/database/database.js";
import * as database from "./src/database/database.js";

app.listen(API_PORT, () => {
console.log("Server Active");
Expand Down
4 changes: 2 additions & 2 deletions jest-global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath } from "url";
import { v4 as uuidv4 } from "uuid";
import { _globalTeardown } from "./jest-global-teardown.js";
import * as CONFIG from "./config.js";
import database from "./src/database/database.js";
import {start as databaseStart} from "./src/database/database.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand All @@ -21,7 +21,7 @@ export default async function globalSetup() {
await _setupNonce();

// Creates tables
await database.start();
await databaseStart();
// All tests can now instantiate their own data with createUser() and createSession()
// Tests may import convenience methods from testUtils.js
}
Expand Down
8 changes: 4 additions & 4 deletions jest-global-teardown.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import database from "./src/database/database.js";
import {start as databaseStart, end as databaseEnd, _dropTables} from "./src/database/database.js";

export default async function globalTeardown() {
// TODO: Tear down the test environment in its entirety
Expand All @@ -22,10 +22,10 @@ export async function _globalTeardown(nonceDir, nonceFile = "") {

// TODO: Take a snapshot of the database
// Tears down the test database
await database.start(true);
await database._dropTables();
await databaseStart(true);
await _dropTables();
if(global.setupUsed || global.teardownOnly) {
await database.end();
await databaseEnd();
}

_clearNonce(nonceDir, nonceFile);
Expand Down
2 changes: 1 addition & 1 deletion jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as matchers from "jest-extended";
import * as testUtils from "./src/utils/testUtils.js";
import database from "./src/database/database.js";
import * as database from "./src/database/database.js";

global._utils = testUtils;

Expand Down
183 changes: 177 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dotenv": "^16.4.5",
"express": "^4.21.0",
"mysql2": "^3.11.3",
"sequelize": "^6.37.4",
"uuid": "^10.0.0"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion setup/setup-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ CREATE USER 'INSERT_API_USER_NAME_HERE'@'localhost' IDENTIFIED BY 'INSERT_API_US
-- Select from Tables
-- Insert to Tables
-- Update to Tables
-- Delete from Tables
-- Delete from Tables
GRANT ALL PRIVILEGES ON `INSERT_DATABASE_NAME_HERE`.* TO 'INSERT_API_USER_NAME_HERE'@'localhost';
FLUSH PRIVILEGES;
4 changes: 2 additions & 2 deletions src/database/__mocks__/database-interface.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { TESTING } = require("../../../config.js");
const actualDatabase = require("../database.js").default;
const actualDatabaseStart = require("../database.js").start;
const actualDBI = jest.requireActual("../database-interface.js");
const mockedDBI = jest.createMockFromModule("../database-interface.js");

Expand All @@ -14,7 +14,7 @@ mockedDBI.setupTestingDatabase = async () => {
throw new Error("Refusing to connect to Production DB in testing");
}
Object.assign(mockedDBI, actualDBI);
await actualDatabase.start();
await actualDatabaseStart();
}

module.exports = mockedDBI;
Loading

0 comments on commit 2ca2763

Please sign in to comment.