Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Add unit tests for job title and location

Khuram Niaz142b7f3a07fe
diff --git a/README.md b/README.md
index 88f22a0..9d06cdf 100644
--- a/README.md
+++ b/README.md
@@ -123,7 +123,7 @@ curl -fsSL https://raw.githubusercontent.com/Gsync/jobsync/main/deploy.sh | sudo
- <a href="https://github.com/ueberdosis/tiptap">Tiptap</a>
- <a href="https://github.com/plouc/nivo">Nivo</a>
- <a href="https://github.com/sqlite/sqlite">Sqlite</a>
-- <a href="https://github.com/langchain-ai">LangChain</a>
+- <a href="https://github.com/vercel/ai">Vercel AI-SDK</a>
- <a href="https://github.com/ollama/ollama">Ollama</a>
### AI Integration
diff --git a/__tests__/AdminTabsContainer.spec.tsx b/__tests__/AdminTabsContainer.spec.tsx
new file mode 100644
index 0000000..17d5f29
--- /dev/null
+++ b/__tests__/AdminTabsContainer.spec.tsx
@@ -0,0 +1,82 @@
+import "@testing-library/jest-dom";
+import { screen, render, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import AdminTabsContainer from "@/components/admin/AdminTabsContainer";
+
+const mockPush = jest.fn();
+
+jest.mock("next/navigation", () => ({
+ useRouter: () => ({ push: mockPush }),
+ usePathname: () => "/dashboard/admin",
+ useSearchParams: () => new URLSearchParams(""),
+}));
+
+jest.mock("@/actions/company.actions", () => ({
+ getCompanyList: jest.fn().mockResolvedValue({ data: [], total: 0 }),
+ getCompanyById: jest.fn(),
+}));
+
+jest.mock("@/actions/jobtitle.actions", () => ({
+ getJobTitleList: jest.fn().mockResolvedValue({ data: [], total: 0 }),
+}));
+
+jest.mock("@/actions/jobLocation.actions", () => ({
+ getJobLocationsList: jest.fn().mockResolvedValue({ data: [], total: 0 }),
+}));
+
+describe("AdminTabsContainer", () => {
+ const user = userEvent.setup({ skipHover: true });
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it("should render all three tabs", () => {
+ render(<AdminTabsContainer />);
+
+ expect(screen.getByRole("tab", { name: "Companies" })).toBeInTheDocument();
+ expect(
+ screen.getByRole("tab", { name: "Job Titles" })
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("tab", { name: "Locations" })
+ ).toBeInTheDocument();
+ });
+
+ it("should default to companies tab", () => {
+ render(<AdminTabsContainer />);
+
+ const companiesTab = screen.getByRole("tab", { name: "Companies" });
+ expect(companiesTab).toHaveAttribute("data-state", "active");
+ });
+
+ it("should switch tabs and update URL", async () => {
+ render(<AdminTabsContainer />);
+
+ const jobTitlesTab = screen.getByRole("tab", { name: "Job Titles" });
+ await user.click(jobTitlesTab);
+
+ expect(mockPush).toHaveBeenCalledWith(
+ "/dashboard/admin?tab=job-titles"
+ );
+ });
+
+ it("should switch to locations tab and update URL", async () => {
+ render(<AdminTabsContainer />);
+
+ const locationsTab = screen.getByRole("tab", { name: "Locations" });
+ await user.click(locationsTab);
+
+ expect(mockPush).toHaveBeenCalledWith(
+ "/dashboard/admin?tab=locations"
+ );
+ });
+
+ it("should render companies tab panel content by default", async () => {
+ render(<AdminTabsContainer />);
+
+ await waitFor(() => {
+ expect(screen.getByTestId("add-company-btn")).toBeInTheDocument();
+ });
+ });
+});
diff --git a/__tests__/company.actions.spec.ts b/__tests__/company.actions.spec.ts
index 7f83654..cf62d27 100644
--- a/__tests__/company.actions.spec.ts
+++ b/__tests__/company.actions.spec.ts
@@ -1,5 +1,6 @@
import {
addCompany,
+ deleteCompanyById,
getAllCompanies,
getCompanyById,
getCompanyList,
@@ -20,6 +21,13 @@ jest.mock("@prisma/client", () => {
findUnique: jest.fn(),
create: jest.fn(),
update: jest.fn(),
+ delete: jest.fn(),
+ },
+ workExperience: {
+ count: jest.fn(),
+ },
+ job: {
+ count: jest.fn(),
},
};
return { PrismaClient: jest.fn(() => mPrismaClient) };
@@ -557,4 +565,73 @@ describe("Company Actions", () => {
});
});
});
+
+ describe("deleteCompanyById", () => {
+ it("should delete a company successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+ const mockDeleted = { id: "company-id", label: "Test Company" };
+ (prisma.company.delete as jest.Mock).mockResolvedValue(mockDeleted);
+
+ const result = await deleteCompanyById("company-id");
+
+ expect(result).toEqual({ res: mockDeleted, success: true });
+ expect(prisma.company.delete).toHaveBeenCalledWith({
+ where: { id: "company-id", createdBy: mockUser.id },
+ });
+ });
+
+ it("should return error for unauthenticated user", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await deleteCompanyById("company-id");
+
+ expect(result).toEqual({ success: false, message: "Not authenticated" });
+ expect(prisma.company.delete).not.toHaveBeenCalled();
+ });
+
+ it("should prevent deletion when work experiences exist", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(1);
+
+ const result = await deleteCompanyById("company-id");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Company cannot be deleted due to its use in experience section of one of the resume! ",
+ });
+ expect(prisma.job.count).not.toHaveBeenCalled();
+ expect(prisma.company.delete).not.toHaveBeenCalled();
+ });
+
+ it("should prevent deletion when associated jobs exist", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(3);
+
+ const result = await deleteCompanyById("company-id");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Company cannot be deleted due to 3 number of associated jobs! ",
+ });
+ expect(prisma.company.delete).not.toHaveBeenCalled();
+ });
+
+ it("should handle unexpected errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+ (prisma.company.delete as jest.Mock).mockRejectedValue(
+ new Error("Delete failed"),
+ );
+
+ const result = await deleteCompanyById("company-id");
+
+ expect(result).toEqual({ success: false, message: "Delete failed" });
+ });
+ });
});
diff --git a/__tests__/jobLocation.actions.spec.ts b/__tests__/jobLocation.actions.spec.ts
new file mode 100644
index 0000000..e99b474
--- /dev/null
+++ b/__tests__/jobLocation.actions.spec.ts
@@ -0,0 +1,246 @@
+import {
+ getAllJobLocations,
+ getJobLocationsList,
+ deleteJobLocationById,
+} from "@/actions/jobLocation.actions";
+import { getCurrentUser } from "@/utils/user.utils";
+import { PrismaClient } from "@prisma/client";
+
+const prisma = new PrismaClient();
+
+jest.mock("@prisma/client", () => {
+ const mPrismaClient = {
+ location: {
+ findMany: jest.fn(),
+ count: jest.fn(),
+ delete: jest.fn(),
+ },
+ workExperience: {
+ count: jest.fn(),
+ },
+ education: {
+ count: jest.fn(),
+ },
+ job: {
+ count: jest.fn(),
+ },
+ };
+ return { PrismaClient: jest.fn(() => mPrismaClient) };
+});
+
+jest.mock("@/utils/user.utils", () => ({
+ getCurrentUser: jest.fn(),
+}));
+
+jest.mock("next/cache", () => ({
+ revalidatePath: jest.fn(),
+}));
+
+describe("Job Location Actions", () => {
+ const mockUser = { id: "user-id" };
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe("getAllJobLocations", () => {
+ it("should return all job locations", async () => {
+ const mockLocations = [
+ { id: "loc-1", label: "New York", value: "new york" },
+ { id: "loc-2", label: "Remote", value: "remote" },
+ ];
+ (prisma.location.findMany as jest.Mock).mockResolvedValue(mockLocations);
+
+ const result = await getAllJobLocations();
+
+ expect(result).toEqual(mockLocations);
+ expect(prisma.location.findMany).toHaveBeenCalled();
+ });
+
+ it("should handle errors", async () => {
+ (prisma.location.findMany as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await getAllJobLocations();
+
+ expect(result).toEqual({ success: false, message: "Database error" });
+ });
+ });
+
+ describe("getJobLocationsList", () => {
+ it("should return paginated location list", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const mockData = [
+ { id: "loc-1", label: "New York", value: "new york" },
+ ];
+ const mockTotal = 1;
+
+ (prisma.location.findMany as jest.Mock).mockResolvedValue(mockData);
+ (prisma.location.count as jest.Mock).mockResolvedValue(mockTotal);
+
+ const result = await getJobLocationsList(1, 10);
+
+ expect(result).toEqual({ data: mockData, total: mockTotal });
+ expect(prisma.location.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ skip: 0,
+ take: 10,
+ orderBy: { jobsApplied: { _count: "desc" } },
+ });
+ expect(prisma.location.count).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ });
+ });
+
+ it("should filter by countBy when provided", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const mockData = [
+ { id: "loc-1", label: "New York", value: "new york" },
+ ];
+ (prisma.location.findMany as jest.Mock).mockResolvedValue(mockData);
+ (prisma.location.count as jest.Mock).mockResolvedValue(1);
+
+ const result = await getJobLocationsList(1, 10, "applied");
+
+ expect(result).toEqual({ data: mockData, total: 1 });
+ expect(prisma.location.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ skip: 0,
+ take: 10,
+ select: {
+ id: true,
+ label: true,
+ value: true,
+ _count: {
+ select: {
+ jobsApplied: {
+ where: { applied: true },
+ },
+ },
+ },
+ },
+ orderBy: { jobsApplied: { _count: "desc" } },
+ });
+ });
+
+ it("should calculate skip correctly for page 3", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.location.findMany as jest.Mock).mockResolvedValue([]);
+ (prisma.location.count as jest.Mock).mockResolvedValue(0);
+
+ await getJobLocationsList(3, 5);
+
+ expect(prisma.location.findMany).toHaveBeenCalledWith(
+ expect.objectContaining({ skip: 10, take: 5 })
+ );
+ });
+
+ it("should return error for unauthenticated user", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await getJobLocationsList(1, 10);
+
+ expect(result).toEqual({ success: false, message: "Not authenticated" });
+ expect(prisma.location.findMany).not.toHaveBeenCalled();
+ });
+
+ it("should handle errors", async () => {
+ (getCurrentUser as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await getJobLocationsList(1, 10);
+
+ expect(result).toEqual({ success: false, message: "Database error" });
+ });
+ });
+
+ describe("deleteJobLocationById", () => {
+ it("should delete a location successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.education.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+ const mockDeleted = { id: "loc-1", label: "New York" };
+ (prisma.location.delete as jest.Mock).mockResolvedValue(mockDeleted);
+
+ const result = await deleteJobLocationById("loc-1");
+
+ expect(result).toEqual({ res: mockDeleted, success: true });
+ expect(prisma.location.delete).toHaveBeenCalledWith({
+ where: { id: "loc-1", createdBy: mockUser.id },
+ });
+ });
+
+ it("should return error for unauthenticated user", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await deleteJobLocationById("loc-1");
+
+ expect(result).toEqual({ success: false, message: "Not authenticated" });
+ expect(prisma.location.delete).not.toHaveBeenCalled();
+ });
+
+ it("should prevent deletion when work experiences exist", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(1);
+
+ const result = await deleteJobLocationById("loc-1");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Job location cannot be deleted due to its use in experience section of one of the resume! ",
+ });
+ expect(prisma.education.count).not.toHaveBeenCalled();
+ expect(prisma.location.delete).not.toHaveBeenCalled();
+ });
+
+ it("should prevent deletion when education records exist", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.education.count as jest.Mock).mockResolvedValue(2);
+
+ const result = await deleteJobLocationById("loc-1");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Job location cannot be deleted due to its use in education section of one of the resume! ",
+ });
+ expect(prisma.job.count).not.toHaveBeenCalled();
+ expect(prisma.location.delete).not.toHaveBeenCalled();
+ });
+
+ it("should prevent deletion when associated jobs exist", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.education.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(5);
+
+ const result = await deleteJobLocationById("loc-1");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Location cannot be deleted due to 5 number of associated jobs! ",
+ });
+ expect(prisma.location.delete).not.toHaveBeenCalled();
+ });
+
+ it("should handle unexpected errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.education.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+ (prisma.location.delete as jest.Mock).mockRejectedValue(
+ new Error("Delete failed")
+ );
+
+ const result = await deleteJobLocationById("loc-1");
+
+ expect(result).toEqual({ success: false, message: "Delete failed" });
+ });
+ });
+});
diff --git a/__tests__/jobtitle.actions.spec.ts b/__tests__/jobtitle.actions.spec.ts
new file mode 100644
index 0000000..9775510
--- /dev/null
+++ b/__tests__/jobtitle.actions.spec.ts
@@ -0,0 +1,285 @@
+import {
+ getAllJobTitles,
+ getJobTitleList,
+ createJobTitle,
+ deleteJobTitleById,
+} from "@/actions/jobtitle.actions";
+import { getCurrentUser } from "@/utils/user.utils";
+import { PrismaClient } from "@prisma/client";
+
+const prisma = new PrismaClient();
+
+jest.mock("@prisma/client", () => {
+ const mPrismaClient = {
+ jobTitle: {
+ findMany: jest.fn(),
+ count: jest.fn(),
+ upsert: jest.fn(),
+ delete: jest.fn(),
+ },
+ workExperience: {
+ count: jest.fn(),
+ },
+ job: {
+ count: jest.fn(),
+ },
+ };
+ return { PrismaClient: jest.fn(() => mPrismaClient) };
+});
+
+jest.mock("@/utils/user.utils", () => ({
+ getCurrentUser: jest.fn(),
+}));
+
+jest.mock("next/cache", () => ({
+ revalidatePath: jest.fn(),
+}));
+
+describe("Job Title Actions", () => {
+ const mockUser = { id: "user-id" };
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe("getAllJobTitles", () => {
+ it("should return all job titles for authenticated user", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const mockTitles = [
+ { id: "title-1", label: "Developer", value: "developer" },
+ { id: "title-2", label: "Designer", value: "designer" },
+ ];
+ (prisma.jobTitle.findMany as jest.Mock).mockResolvedValue(mockTitles);
+
+ const result = await getAllJobTitles();
+
+ expect(result).toEqual(mockTitles);
+ expect(prisma.jobTitle.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ });
+ });
+
+ it("should return error for unauthenticated user", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await getAllJobTitles();
+
+ expect(result).toEqual({ success: false, message: "Not authenticated" });
+ expect(prisma.jobTitle.findMany).not.toHaveBeenCalled();
+ });
+
+ it("should handle unexpected errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.jobTitle.findMany as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await getAllJobTitles();
+
+ expect(result).toEqual({ success: false, message: "Database error" });
+ });
+ });
+
+ describe("getJobTitleList", () => {
+ it("should return paginated job title list", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const mockData = [
+ { id: "title-1", label: "Developer", value: "developer" },
+ ];
+ const mockTotal = 1;
+
+ (prisma.jobTitle.findMany as jest.Mock).mockResolvedValue(mockData);
+ (prisma.jobTitle.count as jest.Mock).mockResolvedValue(mockTotal);
+
+ const result = await getJobTitleList(1, 10);
+
+ expect(result).toEqual({ data: mockData, total: mockTotal });
+ expect(prisma.jobTitle.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ skip: 0,
+ take: 10,
+ orderBy: { jobs: { _count: "desc" } },
+ });
+ expect(prisma.jobTitle.count).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ });
+ });
+
+ it("should filter by countBy when provided", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const mockData = [
+ { id: "title-1", label: "Developer", value: "developer" },
+ ];
+ (prisma.jobTitle.findMany as jest.Mock).mockResolvedValue(mockData);
+ (prisma.jobTitle.count as jest.Mock).mockResolvedValue(1);
+
+ const result = await getJobTitleList(1, 10, "applied");
+
+ expect(result).toEqual({ data: mockData, total: 1 });
+ expect(prisma.jobTitle.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ skip: 0,
+ take: 10,
+ select: {
+ id: true,
+ label: true,
+ value: true,
+ _count: {
+ select: {
+ jobs: {
+ where: { applied: true },
+ },
+ },
+ },
+ },
+ orderBy: { jobs: { _count: "desc" } },
+ });
+ });
+
+ it("should calculate skip correctly for page 2", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.jobTitle.findMany as jest.Mock).mockResolvedValue([]);
+ (prisma.jobTitle.count as jest.Mock).mockResolvedValue(0);
+
+ await getJobTitleList(2, 10);
+
+ expect(prisma.jobTitle.findMany).toHaveBeenCalledWith(
+ expect.objectContaining({ skip: 10, take: 10 })
+ );
+ });
+
+ it("should return error for unauthenticated user", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await getJobTitleList(1, 10);
+
+ expect(result).toEqual({ success: false, message: "Not authenticated" });
+ expect(prisma.jobTitle.findMany).not.toHaveBeenCalled();
+ });
+
+ it("should handle errors", async () => {
+ (getCurrentUser as jest.Mock).mockRejectedValue(
+ new Error("Database error")
+ );
+
+ const result = await getJobTitleList(1, 10);
+
+ expect(result).toEqual({ success: false, message: "Database error" });
+ });
+ });
+
+ describe("createJobTitle", () => {
+ it("should upsert a job title successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ const mockTitle = {
+ id: "title-1",
+ label: "Senior Developer",
+ value: "senior developer",
+ createdBy: mockUser.id,
+ };
+ (prisma.jobTitle.upsert as jest.Mock).mockResolvedValue(mockTitle);
+
+ const result = await createJobTitle("Senior Developer");
+
+ expect(result).toEqual(mockTitle);
+ expect(prisma.jobTitle.upsert).toHaveBeenCalledWith({
+ where: { value: "senior developer", createdBy: mockUser.id },
+ update: { label: "Senior Developer" },
+ create: {
+ label: "Senior Developer",
+ value: "senior developer",
+ createdBy: mockUser.id,
+ },
+ });
+ });
+
+ it("should return error for unauthenticated user", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await createJobTitle("Developer");
+
+ expect(result).toEqual({ success: false, message: "Not authenticated" });
+ expect(prisma.jobTitle.upsert).not.toHaveBeenCalled();
+ });
+
+ it("should handle unexpected errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.jobTitle.upsert as jest.Mock).mockRejectedValue(
+ new Error("Upsert failed")
+ );
+
+ const result = await createJobTitle("Developer");
+
+ expect(result).toEqual({ success: false, message: "Upsert failed" });
+ });
+ });
+
+ describe("deleteJobTitleById", () => {
+ it("should delete a job title successfully", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+ const mockDeleted = { id: "title-1", label: "Developer" };
+ (prisma.jobTitle.delete as jest.Mock).mockResolvedValue(mockDeleted);
+
+ const result = await deleteJobTitleById("title-1");
+
+ expect(result).toEqual({ res: mockDeleted, success: true });
+ expect(prisma.jobTitle.delete).toHaveBeenCalledWith({
+ where: { id: "title-1", createdBy: mockUser.id },
+ });
+ });
+
+ it("should return error for unauthenticated user", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(null);
+
+ const result = await deleteJobTitleById("title-1");
+
+ expect(result).toEqual({ success: false, message: "Not authenticated" });
+ expect(prisma.jobTitle.delete).not.toHaveBeenCalled();
+ });
+
+ it("should prevent deletion when work experiences exist", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(2);
+
+ const result = await deleteJobTitleById("title-1");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Job title cannot be deleted due to its use in experience section of one of the resume! ",
+ });
+ expect(prisma.job.count).not.toHaveBeenCalled();
+ expect(prisma.jobTitle.delete).not.toHaveBeenCalled();
+ });
+
+ it("should prevent deletion when associated jobs exist", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(3);
+
+ const result = await deleteJobTitleById("title-1");
+
+ expect(result).toEqual({
+ success: false,
+ message:
+ "Job title cannot be deleted due to 3 number of associated jobs! ",
+ });
+ expect(prisma.jobTitle.delete).not.toHaveBeenCalled();
+ });
+
+ it("should handle unexpected errors", async () => {
+ (getCurrentUser as jest.Mock).mockResolvedValue(mockUser);
+ (prisma.workExperience.count as jest.Mock).mockResolvedValue(0);
+ (prisma.job.count as jest.Mock).mockResolvedValue(0);
+ (prisma.jobTitle.delete as jest.Mock).mockRejectedValue(
+ new Error("Delete failed")
+ );
+
+ const result = await deleteJobTitleById("title-1");
+
+ expect(result).toEqual({ success: false, message: "Delete failed" });
+ });
+ });
+});
diff --git a/package.json b/package.json
index c14b0ad..139216b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jobsync",
- "version": "0.2.2",
+ "version": "0.2.3",
"private": true,
"scripts": {
"dev": "next dev --turbopack -p 3000",