-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
268d5e3
commit a14e595
Showing
1 changed file
with
70 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import prismock from "../../../../../tests/libs/__mocks__/prisma"; | ||
|
||
import type { Request, Response } from "express"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { createMocks } from "node-mocks-http"; | ||
import { describe, test, expect, vi } from "vitest"; | ||
|
||
import handler from "./setup"; | ||
|
||
type CustomNextApiRequest = NextApiRequest & Request; | ||
type CustomNextApiResponse = NextApiResponse & Response; | ||
|
||
vi.mock("@calcom/lib/server/i18n", () => { | ||
return { | ||
getTranslation: (key: string) => { | ||
return () => key; | ||
}, | ||
}; | ||
}); | ||
|
||
describe("setup", () => { | ||
test("should return a 400 error if users already exists", async () => { | ||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({ | ||
method: "POST", | ||
body: { | ||
email: "[email protected]", | ||
username: "test", | ||
}, | ||
}); | ||
|
||
await prismock.user.create({ | ||
data: { | ||
email: "[email protected]", | ||
}, | ||
}); | ||
|
||
await handler(req, res); | ||
|
||
expect(res.statusCode).toBe(400); | ||
}); | ||
|
||
test("should return 422 if request body is invalid", async () => { | ||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({ | ||
method: "POST", | ||
body: { | ||
email: "[email protected]", | ||
}, | ||
}); | ||
|
||
await handler(req, res); | ||
|
||
expect(res.statusCode).toBe(422); | ||
}); | ||
|
||
test("should create a new admin user", async () => { | ||
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({ | ||
method: "POST", | ||
body: { | ||
username: "test", | ||
full_name: "Test User", | ||
email_address: "[email protected]", | ||
password: "ADMINtestingpassword123!", | ||
}, | ||
}); | ||
|
||
await handler(req, res); | ||
|
||
expect(res.statusCode).toBe(200); | ||
}); | ||
}); |