diff --git a/package.json b/package.json index fbfdd9c..a39bfc6 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,14 @@ "name": "veritix-web", "version": "0.1.0", "private": true, - "scripts": { - "dev": "next dev", - "build": "next build", - "start": "next start", - "lint": "eslint", - "test": "vitest run", - "test:watch": "vitest" - }, + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "eslint", + "test": "vitest run --coverage", + "test:watch": "vitest" + }, "dependencies": { "@hookform/resolvers": "^5.2.2", "@radix-ui/react-slot": "^1.2.4", diff --git a/src/lib/contactConfig.ts b/src/lib/contactConfig.ts index 1062f5e..3057e2b 100644 --- a/src/lib/contactConfig.ts +++ b/src/lib/contactConfig.ts @@ -19,3 +19,30 @@ export const socialLinks = { github: process.env.NEXT_PUBLIC_SOCIAL_GITHUB ?? "https://github.com/veritix", }; + +/** + * Submit the contact form data to the backend API. + * @param data - The form data (name, email, subject, message) + * @returns A promise that resolves to the response JSON + * @throws An error if the submission fails + */ +export async function submitContactForm(data: { + name: string; + email: string; + subject: string; + message: string; +}) { + const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? ""; + const res = await fetch(`${API_BASE}/api/contact`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + + if (!res.ok) { + const err = await res.json().catch(() => ({})); + throw new Error(err?.message || "Failed to send your message. Please try again."); + } + + return res.json(); +} diff --git a/vitest.config.ts b/vitest.config.ts index 88ac509..8d3e751 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -8,6 +8,14 @@ export default defineConfig({ environment: "jsdom", globals: true, setupFiles: ["./src/__tests__/setup.ts"], + coverage: { + reporter: ["text", "json", "html"], + thresholds: { + lines: 60, + branches: 60, + functions: 60, + }, + }, }, resolve: { alias: {