import {Valid} from "../../../source/constraints/valid.mjs";
import {Invalid} from "../../../source/constraints/invalid.mjs";
import {AndOperator} from "../../../source/constraints/andoperator.mjs";

describe('AndOperator', function () {

    describe('.isValid()', function () {

        [
            [new Valid(), new Valid(), true],
            [new Valid(), new Invalid(), false],
            [new Invalid(), new Valid(), false],
            [new Invalid(), new Invalid(), false]
        ].forEach(function (data) {

            let a = data.shift()
            let b = data.shift()
            let c = data.shift()

            it('constraint.isValid() should return ' + c, function (done) {

                let constraint = new AndOperator(a, b);
                constraint.isValid().then(() => {
                    c === true ? done() : done(new Error());
                }).catch(() => {
                    c === true ? done(new Error()) : done();
                })

            });

        });

    });
});

