-
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.
Merge branch 'main' of https://github.com/Ryan-loves-movies/ClassMate
- Loading branch information
Showing
49 changed files
with
1,705 additions
and
631 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
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
File renamed without changes.
File renamed without changes.
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,36 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import ChooseSemester from '@components/dashboard/layout/ChooseSemester'; | ||
import '@testing-library/jest-dom'; | ||
|
||
// beforeEach(function() { | ||
// global.sessionStorage = jest.genMockFunction(); | ||
// global.sessionStorage.setItem = jest.genMockFunction(); | ||
// global.sessionStorage.getItem = jest.genMockFunction(); | ||
// } | ||
|
||
test('renders status bar with correct descriptor', () => { | ||
const color = '#404040'; | ||
const height = '20px'; | ||
const descriptor = 'Test Descriptor'; | ||
|
||
const { getByText } = render(<ChooseSemester />); | ||
|
||
const descriptorElement = getByText(descriptor); | ||
expect(descriptorElement).toBeInTheDocument(); | ||
}); | ||
|
||
test('calculates the width correctly based on the descriptor length', () => { | ||
const color = '#404040'; | ||
const height = '20px'; | ||
const descriptor = 'Test Descriptor sdjknjdnkadnsnkjnasfnn'; | ||
|
||
const { container } = render(<ChooseSemester />); | ||
|
||
const wrapperElement = container.firstChild; | ||
const backgroundElement = container.firstChild?.firstChild; | ||
|
||
// Check if the width is dynamically calculated based on the descriptor length | ||
expect(wrapperElement).toHaveStyle({ width: '47px' }); // Expected width: (descriptor length + 25)px + 5px for padding | ||
expect(backgroundElement).toHaveStyle({ width: '42px' }); // Expected width: descriptor length + 5px for padding | ||
}); |
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,64 +1,59 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"outDir": ".next", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "react", | ||
"incremental": true, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
], | ||
"paths": { | ||
"@app/*": [ | ||
"./src/app/*" | ||
], | ||
"@models/*": [ | ||
"./src/models/*" | ||
], | ||
"@components/*": [ | ||
"./src/components/*" | ||
], | ||
"@server/*": [ | ||
"./src/server/*" | ||
], | ||
"@/*": [ | ||
"./src/*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx", | ||
".next/types/**/*.ts", | ||
"src/**/*", | ||
"src/tests/setupTests.ts" | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"outDir": ".next", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
], | ||
"jest": { | ||
"moduleNameMapper": { | ||
"^@app/(.*)$": "<rootDir>/src/app/$1", | ||
"^@models/(.*)$": "<rootDir>/src/models/$1", | ||
"^@components/(.*)$": "<rootDir>/src/components/", | ||
"^@/(.*)$": "<rootDir>/src/$1" | ||
} | ||
"paths": { | ||
"@app/*": [ | ||
"./src/app/*" | ||
], | ||
"@models/*": [ | ||
"./src/models/*" | ||
], | ||
"@components/*": [ | ||
"./src/components/*" | ||
], | ||
"@/*": [ | ||
"./src/*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx", | ||
".next/types/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
], | ||
"jest": { | ||
"moduleNameMapper": { | ||
"^@app/(.*)$": "<rootDir>/src/app/$1", | ||
"^@models/(.*)$": "<rootDir>/src/models/$1", | ||
"^@components/(.*)$": "<rootDir>/src/components/", | ||
"^@/(.*)$": "<rootDir>/src/$1" | ||
} | ||
} | ||
} |
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,41 @@ | ||
import { Sequelize } from 'sequelize'; | ||
|
||
// // For development | ||
// const sequelize = new Sequelize('ClassMate', 'postgres', 'postgres', { | ||
// host: 'localhost', | ||
// port: 5432, | ||
// dialect: 'postgres', | ||
// // logging: false | ||
// // logging: process.env.NODE_ENV === 'production' ? false : console.log, | ||
// }); | ||
|
||
// For testing | ||
const sequelize = new Sequelize('ClassMateTest', 'postgres', 'postgres', { | ||
host: 'localhost', | ||
port: 5432, | ||
dialect: 'postgres', | ||
logging: false | ||
// logging: process.env.NODE_ENV === 'production' ? false : console.log, | ||
}); | ||
|
||
// For Production | ||
// const sequelize = new Sequelize('postgres', 'postgres', 'ClassMate123!1', { | ||
// host: 'db.tubxvcrohjakulghoizg.supabase.co', | ||
// port: 6543, | ||
// dialect: 'postgres' | ||
// }); | ||
|
||
|
||
export async function createSequelizeConnection(instance: Sequelize) { | ||
try { | ||
await instance.authenticate(); | ||
console.log('Connection to database established!'); | ||
return 'Connection to database established!'; | ||
} catch (err) { | ||
console.error('Unable to connect to database', err); | ||
return 'Failed to connect to database!'; | ||
} | ||
} | ||
|
||
// createSequelizeConnection(sequelize); | ||
export default sequelize; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Request, Response } from 'express'; | ||
import jwt, { JwtPayload } from 'jsonwebtoken'; | ||
import bcrypt from 'bcrypt'; | ||
import config from '@server/config'; | ||
import Users from '@models/Users'; | ||
|
||
/** | ||
req: { | ||
headers: { | ||
Authorization: ~token~ | ||
}, | ||
} | ||
Verifies the JSON web token passed in request headers | ||
**/ | ||
async function validateRequest(req: Request, res: Response) { | ||
const token = req.headers.authorization as string; | ||
|
||
if (!token || !token.trim()) { | ||
return res.status(404).json({ message: 'Token required!' }); | ||
} | ||
|
||
return await new Promise((resolve, reject) => | ||
jwt.verify(token, config.JWT_SECRET, async (err, decoded) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
// Check if decoded password is correct for user | ||
if (decoded) { | ||
const username = (decoded as JwtPayload).username as string; | ||
const password = (decoded as JwtPayload).password as string; | ||
const user = await Users.findByPk(username, { | ||
attributes: ['password'] | ||
}).catch((err) => reject(err)); | ||
await bcrypt | ||
.compare(password, user?.password as string) | ||
.then((authenticated) => { | ||
if (authenticated) { | ||
resolve(''); | ||
} else { | ||
reject('Wrong password!'); | ||
} | ||
}) | ||
.catch((err) => reject(err)); | ||
} else { | ||
reject('False JWT hash!'); | ||
} | ||
}) | ||
) | ||
.then(() => res.status(200).json({ message: 'User authorized!' })) | ||
.catch((err) => | ||
res.status(401).json({ message: 'Unauthorized!', error: err }) | ||
); | ||
} | ||
|
||
export default validateRequest; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.