feat: plain-thread-tier (#19463)
* tier select * thread tier * remove console logs * requested changes to getting user tier * test * fix test error * fix type errors on test * pull latest * route middleware fix * double tierIdentifier * updated test file * build error * plain cards fix up * dayjs * change orgs check to teams isOrgs check * removed uneeded prisma calls and changed teams check
This commit is contained in:
1 parent
c31b7eaaf1
commit
1849fe7b74
8 files changed
+568
-444
No files matched your search
@@ -0,0 +1,75 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prismaMock from "../../../../tests/libs/__mocks__/prismaMock";
|
||||
|
||||
import type { NextRequest } from "next/server";
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach } from "vitest";
|
||||
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
|
||||
import { POST } from "../../app/api/plain-hash/route";
|
||||
|
||||
// Mock NextResponse
|
||||
vi.mock("next/server", () => ({
|
||||
NextResponse: {
|
||||
json: (data: any, init?: ResponseInit) => ({
|
||||
json: async () => data,
|
||||
status: init?.status || 200,
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock session
|
||||
vi.mock("@calcom/features/auth/lib/getServerSession", () => ({
|
||||
getServerSession: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("next/headers", () => ({
|
||||
headers: () => new Headers(),
|
||||
cookies: () => ({ get: () => null }),
|
||||
}));
|
||||
|
||||
vi.mock("@lib/buildLegacyCtx", () => ({
|
||||
buildLegacyRequest: vi.fn().mockReturnValue({
|
||||
headers: new Headers(),
|
||||
cookies: {},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("app/api/apiRouteMiddleware", () => ({
|
||||
apiRouteMiddleware: (handler: () => Promise<Response>) => handler,
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
default: prismaMock,
|
||||
}));
|
||||
|
||||
describe("Plain Integration API", () => {
|
||||
beforeAll(() => {
|
||||
process.env.PLAIN_CHAT_HMAC_SECRET_KEY = "test-secret";
|
||||
process.env.NEXT_PUBLIC_PLAIN_CHAT_ID = "test-chat-id";
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
const tiers = [
|
||||
{ tier: "free", teams: [] },
|
||||
{ tier: "teams", teams: [{ team: { id: 2 } }] },
|
||||
{ tier: "enterprise", teams: [{ team: { id: 3, isOrganization: true } }] },
|
||||
];
|
||||
|
||||
it.each(tiers)("should return $tier tier", async ({ tier, teams }) => {
|
||||
const userData = { id: 1, email: `${tier}@example.com`, name: `${tier} User` };
|
||||
(getServerSession as any).mockResolvedValue({ user: userData });
|
||||
prismaMock.user.findUnique.mockResolvedValue({ ...userData, teams });
|
||||
|
||||
const data = await (await POST({} as NextRequest, { params: {} })).json();
|
||||
expect(data).toMatchObject({ userTier: tier, email: userData.email, fullName: userData.name });
|
||||
});
|
||||
|
||||
it("should return 401 when no session exists", async () => {
|
||||
(getServerSession as any).mockResolvedValue(null);
|
||||
expect((await POST({} as NextRequest, { params: {} })).status).toBe(401);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user