forked from fr/deguapp
Pending
This commit is contained in:
parent
ff8cc4cccf
commit
dc1b955a8a
@ -13,7 +13,7 @@
|
||||
"clean": "rimraf dist",
|
||||
"copy-assets": "ts-node src/utils/copyAssets",
|
||||
"build": "npm-run-all clean tsc copy-assets",
|
||||
"test": "mocha --config .mocharc.json --watch src/**/*.test.ts",
|
||||
"test": "npx jest . --runInBand",
|
||||
"format": "npx prettier --write ."
|
||||
},
|
||||
"author": "Filip Rojek",
|
||||
@ -29,33 +29,38 @@
|
||||
"path": "^0.12.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.7.1",
|
||||
"@types/chai": "^4.2.22",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/inquirer": "^8.1.3",
|
||||
"@types/jest": "^29.5.12",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/morgan": "^1.9.9",
|
||||
"@types/shelljs": "^0.8.11",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
||||
"@typescript-eslint/parser": "^5.5.0",
|
||||
"chai": "^4.3.4",
|
||||
"eslint": "^8.3.0",
|
||||
"http": "^0.0.1-security",
|
||||
"jest": "^29.7.0",
|
||||
"mocha": "^9.1.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^2.7.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"shelljs": "^0.8.5",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-jest": "^29.1.2",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsx": "^4.7.3",
|
||||
"typescript": "^4.5.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/filiprojek/nork.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/filiprojek/nork/issues"
|
||||
},
|
||||
"homepage": "https://github.com/filiprojek/nork/blob/master/README.md"
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
"testEnvironment": "node",
|
||||
"setupFilesAfterEnv": [
|
||||
"./tests/_setupFile.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
|
||||
export function login_post(req: Request, res: Response) {
|
||||
export function signup_post(req: Request, res: Response) {
|
||||
res.send("logged in");
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ const router = Router();
|
||||
|
||||
//const mws = [requireAuth, handleValidation.handleValidationError];
|
||||
|
||||
router.post("/login", authController.login_post);
|
||||
router.post("/signup", authController.signup_post);
|
||||
|
||||
//router.post(
|
||||
// "/login",
|
||||
|
48
api/src/utils/test_mariadb.ts
Normal file
48
api/src/utils/test_mariadb.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { Sequelize } from 'sequelize';
|
||||
|
||||
let sequelize: Sequelize | null = null;
|
||||
|
||||
const connectDB = async () => {
|
||||
sequelize = new Sequelize({
|
||||
dialect: 'mariadb',
|
||||
host: 'localhost',
|
||||
username: 'your_username',
|
||||
password: 'your_password',
|
||||
database: 'your_database',
|
||||
});
|
||||
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection to the database has been established successfully.');
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const dropDB = async () => {
|
||||
if (sequelize) {
|
||||
try {
|
||||
await sequelize.drop();
|
||||
console.log('Database dropped successfully.');
|
||||
} catch (error) {
|
||||
console.error('Error dropping database:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const dropTables = async () => {
|
||||
if (sequelize) {
|
||||
try {
|
||||
await sequelize.sync({ force: true });
|
||||
console.log('All tables dropped successfully.');
|
||||
} catch (error) {
|
||||
console.error('Error dropping tables:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { connectDB, dropDB, dropTables };
|
9
api/tests/_setupFile.ts
Normal file
9
api/tests/_setupFile.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { connectDB, dropDB, dropCollections } from '../src/utils/test_mongodb';
|
||||
|
||||
beforeAll(async () => {
|
||||
await connectDB();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dropDB();
|
||||
});
|
17
api/tests/auth.test.ts
Normal file
17
api/tests/auth.test.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import request from "supertest"
|
||||
import {server as app} from "../server"
|
||||
|
||||
describe('Auth API Endpoints', () => {
|
||||
afterAll((done) => {
|
||||
app.close(done);
|
||||
})
|
||||
|
||||
it('should signup new user', async () => {
|
||||
const res = await request(app)
|
||||
.post('/api/auth/signup')
|
||||
.send({});
|
||||
|
||||
expect(res.statusCode).toEqual(200)
|
||||
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user