"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test slow follows', function () {
    let servers = [];
    let afterFollows;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            servers = yield (0, server_commands_1.createMultipleServers)(3);
            yield (0, server_commands_1.setAccessTokensToServers)(servers);
            yield (0, server_commands_1.doubleFollow)(servers[0], servers[1]);
            yield (0, server_commands_1.doubleFollow)(servers[0], servers[2]);
            afterFollows = new Date();
            for (let i = 0; i < 5; i++) {
                yield servers[0].videos.quickUpload({ name: 'video ' + i });
            }
            yield (0, server_commands_1.waitJobs)(servers);
        });
    });
    it('Should only have broadcast jobs', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const { data } = yield servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' });
            for (const job of data) {
                (0, chai_1.expect)(new Date(job.createdAt)).below(afterFollows);
            }
        });
    });
    it('Should process bad follower', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(30000);
            yield servers[1].kill();
            yield servers[0].videos.quickUpload({ name: 'video 6' });
            yield (0, server_commands_1.waitJobs)(servers[0]);
            afterFollows = new Date();
            const filter = (job) => new Date(job.createdAt) > afterFollows;
            yield servers[0].videos.quickUpload({ name: 'video 7' });
            yield (0, server_commands_1.waitJobs)(servers[0]);
            const resBroadcast = yield servers[0].jobs.list({ jobType: 'activitypub-http-broadcast', sort: '-createdAt' });
            const resUnicast = yield servers[0].jobs.list({ jobType: 'activitypub-http-unicast', sort: '-createdAt' });
            const broadcast = resBroadcast.data.filter(filter);
            const unicast = resUnicast.data.filter(filter);
            (0, chai_1.expect)(unicast).to.have.lengthOf(2);
            (0, chai_1.expect)(broadcast).to.have.lengthOf(2);
            for (const u of unicast) {
                (0, chai_1.expect)(u.data.uri).to.equal(servers[1].url + '/inbox');
            }
            for (const b of broadcast) {
                (0, chai_1.expect)(b.data.uris).to.have.lengthOf(1);
                (0, chai_1.expect)(b.data.uris[0]).to.equal(servers[2].url + '/inbox');
            }
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)(servers);
        });
    });
});
//# sourceMappingURL=slow-follows.js.map