import { Assert } from '@japa/assert';
import _ from 'lodash';
import { AKEventService } from '../events/event_service.js';
export const assertAKEvent = () => function () {
    if (AKEventService.synchronous)
        Assert.macro('jobsCompleted', async function () { });
    Assert.macro('emailSent', async function (faker, notifClass, countOrValidator = 1) {
        await this.jobsCompleted(notifClass.jobQueueName);
        if (_.isNumber(countOrValidator)) {
            const validMailsCount = _.size(_.filter(faker.mails, (mail) => mail.constructor === notifClass));
            this.equal(validMailsCount, countOrValidator);
        }
        else {
            for (const mail of faker.mails) {
                if (mail.constructor === notifClass && countOrValidator(mail))
                    return;
            }
            this.fail(`Mail ${notifClass.name} was not sent`);
        }
    });
    Assert.macro('emailNotSent', async function (faker, notifClass, validator = (_n) => true) {
        if (notifClass)
            await this.jobsCompleted(notifClass.jobQueueName);
        for (const push of faker.mails) {
            if ((!notifClass || push.constructor === notifClass) && validator(push)) {
                this.fail(`Mail ${notifClass?.name} was sent`);
            }
        }
    });
    Assert.macro('webPushSent', async function (faker, notifClass, countOrValidator = 1) {
        await this.jobsCompleted(notifClass.jobQueueName);
        if (_.isNumber(countOrValidator)) {
            const validWebPushCount = _.size(_.filter(faker.pushNotifications, (push) => push.constructor === notifClass));
            this.equal(validWebPushCount, countOrValidator);
        }
        else {
            for (const push of faker.pushNotifications) {
                if (push.constructor === notifClass && countOrValidator(push))
                    return;
            }
            this.fail(`Web push ${notifClass.name} was not sent`);
        }
    });
    Assert.macro('webPushNotSent', async function (faker, notifClass) {
        await this.jobsCompleted(notifClass.jobQueueName);
        for (const push of faker.pushNotifications) {
            if (push.constructor === notifClass)
                this.fail(`Web push ${notifClass.name} was sent`);
        }
    });
};
//# sourceMappingURL=assert_event.js.map