-
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
1 parent
00176a7
commit 8423abb
Showing
15 changed files
with
823 additions
and
707 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
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 |
---|---|---|
|
@@ -3,16 +3,24 @@ import { PrismaClient } from "@prisma/client"; | |
const prisma = new PrismaClient(); | ||
|
||
export default async function resetDb() { | ||
Check failure on line 5 in v1/tests/helpers/reset-db.ts GitHub Actions / testv1/tests/users/main.test.ts
|
||
await prisma.$transaction([ | ||
prisma.users.deleteMany({ | ||
where: { | ||
email: "[email protected]", | ||
}, | ||
}), | ||
prisma.blacklist.deleteMany({ | ||
where: { | ||
token: "test-token", | ||
}, | ||
}), | ||
]); | ||
await prisma.users.delete({ | ||
where: { | ||
email: "[email protected]", | ||
}, | ||
}); | ||
|
||
await prisma.users.delete({ | ||
where: { | ||
user_id: "00000000-0000-0000-0000-000000000001", | ||
}, | ||
}); | ||
|
||
await prisma.users.create({ | ||
data: { | ||
email: "[email protected]", | ||
password_hash: "testpassword", | ||
user_id: "00000000-0000-0000-0000-000000000001", | ||
email_verified: false, | ||
}, | ||
}); | ||
} |
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,14 +1,20 @@ | ||
import resetDb from "./reset-db.js"; | ||
import { beforeAll } from "vitest"; | ||
import { beforeAll, afterAll, afterEach } from "vitest"; | ||
import { createServer } from "../../utils/express.utils.js"; | ||
import { UserInput } from "../../types/user.types.js"; | ||
import { UserInput, User } from "../../types/user.types.js"; | ||
import { Config } from "../../utils/options.js"; | ||
|
||
export const exampleUser: UserInput = { | ||
email: "[email protected]", | ||
password: "testpassword", | ||
}; | ||
|
||
export const exampleUser2: User = { | ||
userId: "00000000-0000-0000-0000-000000000001", | ||
email: "[email protected]", | ||
emailVerified: false, | ||
}; | ||
|
||
export const app = createServer(); | ||
|
||
export const apiKey = Config.API_KEY; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { describe, expect, expectTypeOf, it } from "vitest"; | ||
import request from "supertest"; | ||
import { | ||
exampleUser2, | ||
exampleUser, | ||
apiKey, | ||
appId, | ||
app, | ||
} from "../helpers/setup"; | ||
import { Endpoints } from "../../utils/options"; | ||
import { ZodIssue } from "zod"; | ||
|
||
export const updateEmailRouteTest = () => | ||
describe("[PUT] /api/v1/users/:userId/update-email", () => { | ||
const endpoint = Endpoints.UPDATE_EMAIL; | ||
|
||
it("should respond with a `204` status code when a valid api key and app id is present", async () => { | ||
const { status } = await request(app) | ||
.put(endpoint.replace(":userId", exampleUser2.userId)) | ||
.send({ newEmail: "[email protected]" }) | ||
.set("x-gator-api-key", apiKey) | ||
.set("x-gator-app-id", appId); | ||
|
||
expect(status).toBe(204); | ||
}); | ||
|
||
it("should respond with a `404` status code when the user does not exist", async () => { | ||
const invalidUserId = "00000000-0000-0000-0000-000000000000"; | ||
const { status, body } = await request(app) | ||
.put(endpoint.replace(":userId", invalidUserId)) | ||
.send({ newEmail: "[email protected]" }) | ||
.set("x-gator-api-key", apiKey) | ||
.set("x-gator-app-id", appId); | ||
|
||
expect(status).toBe(404); | ||
|
||
expect(body).toMatchObject({ | ||
error: { | ||
name: "UserNotFoundError", | ||
message: `User not found with ID: ${invalidUserId}`, | ||
errorCode: "USER_NOT_FOUND", | ||
}, | ||
}); | ||
}); | ||
|
||
it("should respond with a `400` status code and Zod errors when the request body is invalid", async () => { | ||
const { status, body } = await request(app) | ||
.put(endpoint.replace(":userId", exampleUser2.userId)) | ||
.send({ newEmail: "invalid-email" }) | ||
.set("x-gator-api-key", apiKey) | ||
.set("x-gator-app-id", appId); | ||
|
||
expect(status).toBe(400); | ||
|
||
expectTypeOf(body).toMatchTypeOf<ZodIssue[]>(); | ||
|
||
expect(body).toMatchObject([ | ||
{ | ||
validation: "email", | ||
code: "invalid_string", | ||
message: "Please enter a valid email address.", | ||
path: ["body", "newEmail"], | ||
}, | ||
]); | ||
}); | ||
|
||
it("should respond with a `400` status code and Zod errors when the user id is invalid", async () => { | ||
const { status, body } = await request(app) | ||
.put(endpoint.replace(":userId", "invalid-id")) | ||
.send({ newEmail: "[email protected]" }) | ||
.set("x-gator-api-key", apiKey) | ||
.set("x-gator-app-id", appId); | ||
|
||
console.log(status, body); | ||
|
||
expect(status).toBe(400); | ||
|
||
expectTypeOf(body).toMatchTypeOf<ZodIssue[]>(); | ||
|
||
expect(body).toMatchObject([ | ||
{ | ||
validation: "regex", | ||
code: "invalid_string", | ||
message: "ID must be a valid UUID.", | ||
path: ["params", "userId"], | ||
}, | ||
]); | ||
}); | ||
}); |
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
Oops, something went wrong.