diff --git a/__refactor_tests__/userController.tests.ts b/__tests__/userController.tests.ts similarity index 92% rename from __refactor_tests__/userController.tests.ts rename to __tests__/userController.tests.ts index 9bc3852..c4533ef 100644 --- a/__refactor_tests__/userController.tests.ts +++ b/__tests__/userController.tests.ts @@ -29,9 +29,8 @@ describe("User Controller Tests", () => { }; }); - //TODO This test needs to be refactored to accomodate new controller code describe("registerUser function", () => { - xit("should handle user registration", async () => { + it("should handle user registration", async () => { (User.findOne as jest.Mock).mockResolvedValue(null); (User.create as jest.Mock).mockResolvedValue({ _id: "someId", @@ -67,7 +66,7 @@ describe("User Controller Tests", () => { }); describe("authUser function", () => { - xit("should handle user authentication", async () => { + it("should handle user authentication", async () => { (User.findOne as jest.Mock).mockResolvedValue({ _id: "someId", firstName: "John", @@ -98,7 +97,7 @@ describe("User Controller Tests", () => { }); describe("getUserById function", () => { - xit("should get a user by ID", async () => { + it("should get a user by ID", async () => { (User.findOne as jest.Mock).mockResolvedValue({ _id: "someId", firstName: "John", @@ -126,7 +125,7 @@ describe("User Controller Tests", () => { }); describe("deleteUserByEmail function", () => { - xit("should delete a user by email", async () => { + it("should delete a user by email", async () => { (User.findOneAndRemove as jest.Mock).mockResolvedValue({ _id: "someId", firstName: "John", diff --git a/__refactor_tests__/userRoutes.test.ts b/__tests__/userRoutes.test.ts similarity index 91% rename from __refactor_tests__/userRoutes.test.ts rename to __tests__/userRoutes.test.ts index 8470bb1..61b3272 100644 --- a/__refactor_tests__/userRoutes.test.ts +++ b/__tests__/userRoutes.test.ts @@ -22,7 +22,7 @@ afterAll(async () => { describe("User Routes", () => { describe("POST /api/users/register", () => { - xit("should register a user", async () => { + it("should register a user", async () => { const mockNewUserData = { firstName: "John", lastName: "Doh", @@ -40,7 +40,7 @@ describe("User Routes", () => { }); describe("POST /api/users/login", () => { - xit("should login a user", async () => { + it("should login a user", async () => { const mockUserData = { email: "john@test.com", password: "testpassword", @@ -56,7 +56,7 @@ describe("User Routes", () => { }); describe("GET /api/users/:id", () => { - xit("should get a specific user", async () => { + it("should get a specific user", async () => { // Create a user first const newUser = { firstName: "Test", @@ -82,7 +82,7 @@ describe("User Routes", () => { }); describe("DELETE /api/users/:email", () => { - xit("should delete a specific user by email", async () => { + it("should delete a specific user by email", async () => { const email = "john@test.com"; const res = await request(app).delete(`/api/users/${email}`); diff --git a/client/src/App.tsx b/client/src/App.tsx index 8e25d45..8eeb2d0 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -2,15 +2,13 @@ import React from "react"; import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; import LandingPage from "./pages/LandingPage"; import NotFoundPage from "./pages/NotFoundPage/NotFoundPage"; -import AuthenticatedApp from "./AuthenticatedApp"; -import RegistrationPage from "./pages/RegistrationPage/RegistrationPage"; +import AuthenticatedApp from "./AuthenticatedApp" const App = (): JSX.Element => { return ( } /> - } /> } /> } /> diff --git a/client/src/pages/RegistrationPage/RegistrationPage.tsx b/client/src/pages/RegistrationPage/RegistrationPage.tsx deleted file mode 100644 index 002e491..0000000 --- a/client/src/pages/RegistrationPage/RegistrationPage.tsx +++ /dev/null @@ -1,144 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { useLocation } from "react-router-dom"; - -const RegistrationPage: React.FC = () => { - const [formData, setFormData] = useState({ - firstName: "", - lastName: "", - email: "", - password: "", - }); - - const location = useLocation(); - - const query = new URLSearchParams(location.search); - const token = query.get("token"); - - const handleChange = (e: React.ChangeEvent) => { - setFormData({ - ...formData, - [e.target.name]: e.target.value, - }); - }; - - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - if (!token) { - console.error("Token is missing."); - return; //TODO Display error feedback for user - } - try { - const response = await fetch(`/api/users/register?token=${token}`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(formData), - }); - const data = await response.json(); - if (!response.ok) { - throw new Error( - data.message || "An error occurred during registration." - ); - } - console.log("Registration successful", data); - //TODO Handle redirect here - } catch (error) { - //TODO Needs better error handling - console.error("Registration error:", error); - } - }; - - return ( -
-
-

- Registration Page -

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
-
-
- ); -}; - -export default RegistrationPage; diff --git a/dev-tools/scripts/alumniDatabaseSeeder.ts b/dev-tools/scripts/alumniDatabaseSeeder.ts deleted file mode 100644 index b08f97b..0000000 --- a/dev-tools/scripts/alumniDatabaseSeeder.ts +++ /dev/null @@ -1,33 +0,0 @@ -import mongoose from "mongoose"; -import GraduateInvitation from "../../server/models/graduateInvitationModel"; -import crypto from "crypto"; - -const alumniList = [ - { email: "J@email.com", name: "Jane Doe" }, - { email: "Jh@email.com", name: "John Doe" }, -]; - -const generateToken = () => { - return crypto.randomBytes(20).toString("hex"); -}; - -export const seedDatabase = async () => { - await GraduateInvitation.deleteMany(); - - const invitations = alumniList.map((alumnus) => ({ - email: alumnus.email, - token: generateToken(), - tokenExpiry: new Date(Date.now() + 48 * 60 * 60 * 1000), - isRegistered: false, - createdAt: new Date(), - name: alumnus.name, - lastEmailSent: new Date(), - })); - - try { - await GraduateInvitation.insertMany(invitations); - console.log("Database seeded successfully."); - } catch (error) { - console.error("Error seeding database:", error); - } -}; diff --git a/server/controllers/devControllers.ts b/server/controllers/devControllers.ts deleted file mode 100644 index 44411a4..0000000 --- a/server/controllers/devControllers.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Request, Response, NextFunction } from "express"; -import { seedDatabase } from "../../dev-tools/scripts/alumniDatabaseSeeder"; - -const seedRegistrationDatabase = async ( - req: Request, - res: Response, - next: NextFunction -) => { - try { - await seedDatabase(); - res.status(200).send("Database seeded successfully."); - } catch (error) { - console.error("Error seeding database:", error); - res.status(500).send("Error seeding database."); - } -}; - -export { seedRegistrationDatabase }; diff --git a/server/controllers/userController.ts b/server/controllers/userController.ts index 9fd37fd..d22a087 100644 --- a/server/controllers/userController.ts +++ b/server/controllers/userController.ts @@ -2,7 +2,6 @@ import User from "../models/userModel"; import generateToken from "../utils/generateToken"; import { Request, Response, NextFunction } from "express"; import { UserType } from "../types/user"; -import GraduateInvitation from "../models/graduateInvitationModel"; // ENDPOINT POST api/users/register // PURPOSE Register a new user @@ -13,27 +12,12 @@ const registerUser = async ( next: NextFunction ) => { const { firstName, lastName, email, password } = req.body; - const { token } = req.query; try { const isValidEmail = email.match(/[\w\d\.]+@[a-z]+\.[\w]+$/gim); if (!isValidEmail) { return res.status(400).json("Invalid Email"); } - - const invitation = await GraduateInvitation.findOne({ - email, - token, - tokenExpiry: { $gt: new Date() }, - isRegistered: false, - }); - - //TODO Needs better error handling - this can trigger with situaions other than bad or missing token - if (!invitation) { - return res - .status(400) - .json({ message: "Invalid or expired registration token" }); - } const userExists: UserType | null = await User.findOne({ email }); if (userExists) { return res.status(400).json({ message: "User already exists!" }); @@ -46,8 +30,6 @@ const registerUser = async ( }); if (user) { - invitation.isRegistered = true; - await invitation?.save(); res.locals.user = { _id: user._id, firstName: user.firstName, diff --git a/server/index.ts b/server/index.ts index a89bf0d..7cff99b 100644 --- a/server/index.ts +++ b/server/index.ts @@ -2,7 +2,6 @@ import path from "path"; import express, { Request, Response, Application, NextFunction } from "express"; import userRoutes from "./routes/userRoutes"; import profileRoutes from "./routes/profileRoutes"; -import devRoutes from "./routes/devRoutes"; import connectDB from "./config/db"; import dotenv from "dotenv"; import { notFound, errorHandler } from "./controllers/errorControllers"; @@ -17,7 +16,6 @@ connectDB(); app.use("/api/users", userRoutes); app.use("/api/profiles", profileRoutes); -app.use("/api/devRoutes", devRoutes); console.log(`ENV BEFORE CHECK: ${process.env.NODE_ENV}`); diff --git a/server/models/graduateInvitationModel.ts b/server/models/graduateInvitationModel.ts deleted file mode 100644 index 8dafe8f..0000000 --- a/server/models/graduateInvitationModel.ts +++ /dev/null @@ -1,40 +0,0 @@ -import mongoose from "mongoose"; -import { IGraduateInvitation } from "../types/graduateInvitation"; - -const graduateInvitationSchema = new mongoose.Schema({ - email: { - type: String, - required: true, - unique: true, - }, - token: { - type: String, - required: true, - }, - tokenExpiry: { - type: Date, - required: true, - }, - isRegistered: { - type: Boolean, - required: true, - default: false, - }, - createdAt: { - type: Date, - default: Date.now, - }, - name: String, - registeredAt: Date, - lastEmailSent: { - type: Date, - default: Date.now, - }, -}); - -const GraduateInvitation = mongoose.model( - "GraduateInvitation", - graduateInvitationSchema -); - -export default GraduateInvitation; diff --git a/server/routes/devRoutes.ts b/server/routes/devRoutes.ts deleted file mode 100644 index 0741773..0000000 --- a/server/routes/devRoutes.ts +++ /dev/null @@ -1,9 +0,0 @@ -import express from "express"; - -import { seedRegistrationDatabase } from "../controllers/devControllers"; - -const router = express.Router(); - -router.get("/", seedRegistrationDatabase); - -export default router; diff --git a/server/types/graduateInvitation.ts b/server/types/graduateInvitation.ts deleted file mode 100644 index 79c4020..0000000 --- a/server/types/graduateInvitation.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Document } from "mongoose"; - -export interface IGraduateInvitation extends Document { - email: string; - token: string; - tokenExpiry: Date; - isRegistered: boolean; - createdAt?: Date; - name?: string; - registeredAt?: Date; - lastEmailSent?: Date; -}