-
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.
- Loading branch information
Showing
14 changed files
with
119 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,68 +3,90 @@ | |
*/ | ||
|
||
import { testApiHandler } from "next-test-api-route-handler"; | ||
|
||
import * as registerHandler from "../../../src/app/api/auth/register/route"; | ||
|
||
describe("/api/auth/register", () => { | ||
it("registers a new user successfully", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
it("registers a new user successfully", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
email: "[email protected]", | ||
password: "Password@123", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date("1990-01-01"), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(201); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
user: expect.objectContaining({ | ||
email: "[email protected]", | ||
password: "Password@123", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
dateOfBirth: new Date("1990-01-01"), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
expect(res.status).toBe(201); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
user: expect.objectContaining({ | ||
email: "[email protected]", | ||
username: "johndoe", | ||
name: "John", | ||
lastName: "Doe", | ||
}), | ||
}), | ||
); | ||
}, | ||
}); | ||
it("returns error for already used email", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
name: "Alice", | ||
lastName: "Prisma", | ||
email: "[email protected]", | ||
username: "aliceUserName", | ||
password: "alicePassword", | ||
dateOfBirth: new Date("1990-01-01"), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
message: "Email already in use", | ||
}), | ||
); | ||
}, | ||
}); | ||
}); | ||
|
||
it("returns error for already used email", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
name: "Alice", | ||
lastName: "Prisma", | ||
email: "[email protected]", | ||
username: "aliceUserName", | ||
password: "alicePassword", | ||
dateOfBirth: new Date("1990-01-01"), | ||
}), | ||
}); | ||
const data = await res.json(); | ||
it("returns error for bad request", async () => { | ||
await testApiHandler({ | ||
appHandler: registerHandler, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
name: "Alice", | ||
lastName: "Prisma", | ||
email: "", | ||
}), | ||
}); | ||
const data = await res.json(); | ||
|
||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
message: "Email already in use", | ||
}), | ||
); | ||
}, | ||
}); | ||
expect(res.status).toBe(400); | ||
expect(data).toEqual( | ||
expect.objectContaining({ | ||
message: "email is required", | ||
}), | ||
); | ||
}, | ||
}); | ||
}); |
Empty file.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,6 +1,7 @@ | ||
import NextAuth from "next-auth"; | ||
import { authOptions } from "@/lib/authOptions"; | ||
|
||
// @ts-ignore | ||
const handler = NextAuth(authOptions); | ||
|
||
export { handler as GET, handler as POST }; |
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
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
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