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.

1.8 KB
Raw Blame
import { AddContactFormSchema } from "@/models/addContactForm.schema";

const valid = { name: "Dave Patel" };

describe("AddContactFormSchema", () => {
  it("accepts a name on its own", () => {
    expect(AddContactFormSchema.safeParse(valid).success).toBe(true);
  });

  it("rejects an empty name", () => {
    expect(AddContactFormSchema.safeParse({ name: "" }).success).toBe(false);
  });

  it("accepts an empty email, because a panelist is often just a name", () => {
    expect(
      AddContactFormSchema.safeParse({ ...valid, email: "" }).success,
    ).toBe(true);
  });

  it("rejects a malformed email when one is given", () => {
    expect(
      AddContactFormSchema.safeParse({ ...valid, email: "not-an-email" }).success,
    ).toBe(false);
  });

  it("rejects a LinkedIn URL that is not http(s)", () => {
    expect(
      AddContactFormSchema.safeParse({ ...valid, linkedinUrl: "ftp://x.com" })
        .success,
    ).toBe(false);
  });

  it("rejects an overlap that ends before it starts", () => {
    const res = AddContactFormSchema.safeParse({
      ...valid,
      workedFrom: new Date("2021-01-01"),
      workedTo: new Date("2019-01-01"),
    });
    expect(res.success).toBe(false);
  });

  it("rejects a last-contacted date in the future", () => {
    const tomorrow = new Date();
    tomorrow.setDate(tomorrow.getDate() + 1);
    expect(
      AddContactFormSchema.safeParse({ ...valid, lastContactedAt: tomorrow })
        .success,
    ).toBe(false);
  });

  it("accepts a last-contacted date of today", () => {
    expect(
      AddContactFormSchema.safeParse({ ...valid, lastContactedAt: new Date() })
        .success,
    ).toBe(true);
  });

  it("accepts an open-ended overlap", () => {
    expect(
      AddContactFormSchema.safeParse({
        ...valid,
        workedFrom: new Date("2019-01-01"),
      }).success,
    ).toBe(true);
  });
});