/**
 * Copyright IBM Corp. 2024, 2025
 */
import { AssertionSchema } from "../../src/schemas/assertions.schema.js";
import { validAssertionData } from "../__mocks__/test-data/assertion.data.js";

jest.mock("@apic/api-model/common/Metadata.js", () => ({
  Metadata_TypeEnum: {
    REST: "REST",
    SWAGGER: "SWAGGER",
    SOAP: "SOAP",
    GRAPHQL: "GRAPHQL",
    ODATA: "ODATA",
  },
}));

describe("AssertionSchema", () => {
  it("should validate a valid assertion object", () => {
    expect(() => AssertionSchema.parse(validAssertionData)).not.toThrow();
  });

  it('should fail if kind is not "assertion"', () => {
    const input = {
      kind: "not-assertion",
      metadata: {
        name: "Test",
        version: "1.0",
        namespace: "default",
      },
      spec: [],
    };

    expect(() => AssertionSchema.parse(input)).toThrow();
  });

  it("should fail if spec is not an array of AssertionSpecSchema", () => {
    const input = {
      kind: "assertion",
      metadata: {
        name: "Test",
        version: "1.0",
        namespace: "default",
      },
      spec: [
        {
          name: "InvalidSpec",
          key: "some.key",
        },
      ],
    };

    expect(() => AssertionSchema.parse(input)).toThrow();
  });
});
