import { required } from "@/helpers/validation-rules";
import { regex } from "@/helpers/validation-rules";

describe("validation-rules.vue", () => {
    test("required rules should return error if value missing", () => {
        //Arrange
        const testFn = required("an error");

        //Act
        const testResponse = testFn();

        //Assert
        expect(testResponse).toBe("an error");
    });
});

describe("validation-rules.vue", () => {
    test("required rules should return true if value present", () => {
        //Arrange
        const testFn = required("an error");

        //Act
        const testResponse = testFn("some value");

        //Assert
        expect(testResponse).toBe(true);
    });
});

describe("validation-rules.vue", () => {
    test("regex rules should return true if value is not present", () => {
        //Arrange
        const testFn = regex(/(^\d{5}$)|(^\d{5}-\d{4}$)/, "an error"); // Using Zip regex

        //Act
        const testResponse = testFn();

        //Assert
        expect(testResponse).toBe(true);
    });
});

describe("validation-rules.vue", () => {
    test("regex rules should return false if value is present but does not match regular expression", () => {
        //Arrange
        const testFn = regex(/(^\d{5}$)|(^\d{5}-\d{4}$)/, "an error"); // Using Zip regex

        //Act
        const testResponse = testFn("4321"); // needs to be 5 numbers

        //Assert
        expect(testResponse).toBe("an error");
    });
});

describe("validation-rules.vue", () => {
    test("regex rules should return true if value is present and does match regular expression", () => {
        //Arrange
        const testFn = regex(/(^\d{5}$)|(^\d{5}-\d{4}$)/, "an error"); // Using Zip regex

        //Act
        const testResponse = testFn("43213"); // needs to be 5 numbers

        //Assert
        expect(testResponse).toBe(true);
    });
});
