import { Assert } from '@japa/assert';
import _ from 'lodash';
export const assertMacros = () => function () {
    Assert.macro('deepEqualNotSorted', function (a, b) {
        const sortKey = 'id';
        return this.deepEqual(_.sortBy(a, sortKey), _.sortBy(b, sortKey));
    });
    Assert.macro('containsFieldsOfSubset', function (a, b, fields, strict = false, sorted = false) {
        this.containsSubset(a, _.map(b, (e) => _.pick(e, fields)));
        if (strict)
            this.lengthOf(a, b.length);
        if (sorted) {
            const aPicked = _.map(a, (e) => _.pick(e, fields));
            const bPicked = _.map(b, (e) => _.pick(e, fields));
            const aFiltred = _.filter(aPicked, (e) => _.find(bPicked, e));
            this.deepEqual(aFiltred, bPicked);
        }
    });
    Assert.macro('notContainsFieldsOfSubset', function (a, b, fields) {
        this.notContainsSubset(a, _.map(b, (i) => _.pick(i, fields)));
    });
    Assert.macro('containsIdsOfSubset', function (a, b, strict = false, sorted = false) {
        return this.containsFieldsOfSubset(a, b, 'id', strict, sorted);
    });
    Assert.macro('notContainsIdsOfSubset', function (a, b) {
        this.notContainsFieldsOfSubset(a, b, 'id');
    });
    Assert.macro('isToday', function (date) {
        const askedDate = new Date(date);
        const today = new Date();
        this.equal(askedDate.getDate(), today.getDate());
        this.equal(askedDate.getMonth(), today.getMonth());
        this.equal(askedDate.getFullYear(), today.getFullYear());
    });
    Assert.macro('isValidURL', function (url) {
        try {
            return Boolean(new URL(url));
        }
        catch (e) {
            this.assert(false, `${url} is not a valid url`);
        }
    });
};
//# sourceMappingURL=assert_macros.js.map