Skip to content

Commit

Permalink
tests written
Browse files Browse the repository at this point in the history
  • Loading branch information
pks03 authored and thenicekat committed Feb 26, 2024
1 parent 61c4624 commit 6a0c7ed
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 39 deletions.
1 change: 0 additions & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ app.use(express.urlencoded({ extended: true }))
app.use(cors({
optionsSuccessStatus: 200,
credentials: true,
origin: "http://localhost:3000"
}))

// Add session middleware
Expand Down
4 changes: 1 addition & 3 deletions backend/src/routes/user.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { Router } from "express";
import { HttpCodes } from "../types/HttpCodes";
import { CustomResponse } from "../types/CustomResponse";
import { newUser } from "../service/user.service";

export const userRouter = Router();

userRouter.post("/signup", async (req, res) => {
console.log(req.session)
userRouter.post("/create", async (req, res) => {
const data = req.body;
const userEmail = req.session.email as string;

Expand Down
59 changes: 59 additions & 0 deletions backend/tests/user.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { describe, expect } from "@jest/globals";
import { prismaMock } from "./_mockdb";
import { newUser } from "../src/service/user.service";


describe("Create a new user", () => {
// it("should create a new post", () => {
// const post = {
// id: "1",
// authorId: "1",
// authorEmail: "authorEmail",
// source: "source",
// destination: "destination",
// costInPoints: 10,
// service: "service",
// }

// prismaMock.post.create.mockResolvedValue(post);

// expect(createPost(post)).resolves.toEqual({
// error: false,
// data: post
// });
// });

it("should return an error if name is not given", () => {
const user = {
id: "1",
name: "",
email: "email",
phoneNumber: "phoneNumber",
karmaPoints: 0
}

prismaMock.user.create.mockResolvedValue(user);

expect(newUser(user)).resolves.toEqual({
error: true,
data: "User name is required to create profile."
});
})

it("should return an error if name is not given", () => {
const user = {
id: "1",
name: "name",
email: "email",
phoneNumber: "",
karmaPoints: 0
}

prismaMock.user.create.mockResolvedValue(user);

expect(newUser(user)).resolves.toEqual({
error: true,
data: "Phone Number is required to create profile."
});
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ type FormData = {
phoneNumber: string
}

export default function CreatePost() {
export default function CreateUser() {
const { register, handleSubmit, formState: { errors }, control } = useForm<FormData>()

const [message, setMessage] = useState<string | null>(null)
const [error, setError] = useState<string | null>(null)

const onSubmit = async (data: FormData) => {
try {
const res = await axios.post(siteConfig.server_url + "/user/signup", {
Expand Down
33 changes: 0 additions & 33 deletions frontend/components/signup.tsx

This file was deleted.

0 comments on commit 6a0c7ed

Please sign in to comment.