"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 ActivityPub fetcher', function () {
    let servers;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(60000);
            servers = yield (0, server_commands_1.createMultipleServers)(3);
            yield (0, server_commands_1.setAccessTokensToServers)(servers);
            const user = { username: 'user1', password: 'password' };
            for (const server of servers) {
                yield server.users.create({ username: user.username, password: user.password });
            }
            const userAccessToken = yield servers[0].login.getAccessToken(user);
            yield servers[0].videos.upload({ attributes: { name: 'video root' } });
            const { uuid } = yield servers[0].videos.upload({ attributes: { name: 'bad video root' } });
            yield servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'video user' } });
            {
                const to = servers[0].url + '/accounts/user1';
                const value = servers[1].url + '/accounts/user1';
                yield servers[0].sql.setActorField(to, 'url', value);
            }
            {
                const value = servers[2].url + '/videos/watch/' + uuid;
                yield servers[0].sql.setVideoField(uuid, 'url', value);
            }
        });
    });
    it('Should add only the video with a valid actor URL', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(60000);
            yield (0, server_commands_1.doubleFollow)(servers[0], servers[1]);
            yield (0, server_commands_1.waitJobs)(servers);
            {
                const { total, data } = yield servers[0].videos.list({ sort: 'createdAt' });
                (0, chai_1.expect)(total).to.equal(3);
                (0, chai_1.expect)(data[0].name).to.equal('video root');
                (0, chai_1.expect)(data[1].name).to.equal('bad video root');
                (0, chai_1.expect)(data[2].name).to.equal('video user');
            }
            {
                const { total, data } = yield servers[1].videos.list({ sort: 'createdAt' });
                (0, chai_1.expect)(total).to.equal(1);
                (0, chai_1.expect)(data[0].name).to.equal('video root');
            }
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(20000);
            yield (0, server_commands_1.cleanupTests)(servers);
        });
    });
});
//# sourceMappingURL=fetch.js.map