import { faker } from '@faker-js/faker';
import _ from 'lodash';
import { DateTime } from 'luxon';
export const generatePassword = () => faker.string.alphanumeric({ length: { min: 10, max: 20 } }) + '%2';
export const firstMailData = (fakeMailer, mailClass) => {
    let email;
    fakeMailer.mails.sent((m) => {
        if (m instanceof mailClass)
            email = m;
        return true;
    });
    return email?.message.nodeMailerMessage;
};
export const serializeDate = (date, atMidnight = false) => {
    if (_.isString(date))
        date = new Date(date);
    return (atMidnight ? DateTime.fromJSDate(date).startOf('day').toJSDate() : date).toISOString();
};
export const addDays = (date, days) => {
    const newDate = new Date(date);
    newDate.setDate(newDate.getDate() + days);
    return newDate;
};
export const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
export const waitFor = async (f, delay = 10, interval = 2) => {
    const NS_PER_SEC = BigInt(1e9);
    let startTime = process.hrtime.bigint();
    while ((process.hrtime.bigint() - startTime) / NS_PER_SEC < delay) {
        const result = await f();
        if (result !== undefined)
            return result;
        await sleep(interval * 1000);
    }
    return undefined;
};
//# sourceMappingURL=macros.js.map