"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const shared_1 = require("../../shared");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test views retention stats', function () {
    let servers;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            servers = yield (0, shared_1.prepareViewsServers)();
        });
    });
    describe('Test retention stats on VOD', function () {
        let vodVideoId;
        before(function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                this.timeout(240000);
                ({ vodVideoId } = yield (0, shared_1.prepareViewsVideos)({ servers, live: false, vod: true }));
            });
        });
        it('Should display empty retention', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const { data } = yield servers[0].videoStats.getRetentionStats({ videoId: vodVideoId });
                (0, chai_1.expect)(data).to.have.lengthOf(6);
                for (let i = 0; i < 6; i++) {
                    (0, chai_1.expect)(data[i].second).to.equal(i);
                    (0, chai_1.expect)(data[i].retentionPercent).to.equal(0);
                }
            });
        });
        it('Should display appropriate retention metrics', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].views.simulateViewer({ xForwardedFor: '127.0.0.2,127.0.0.1', id: vodVideoId, currentTimes: [0, 1] });
                yield servers[0].views.simulateViewer({ xForwardedFor: '127.0.0.3,127.0.0.1', id: vodVideoId, currentTimes: [1, 3] });
                yield servers[1].views.simulateViewer({ xForwardedFor: '127.0.0.2,127.0.0.1', id: vodVideoId, currentTimes: [4] });
                yield servers[1].views.simulateViewer({ xForwardedFor: '127.0.0.3,127.0.0.1', id: vodVideoId, currentTimes: [0, 1] });
                yield (0, shared_1.processViewersStats)(servers);
                const { data } = yield servers[0].videoStats.getRetentionStats({ videoId: vodVideoId });
                (0, chai_1.expect)(data).to.have.lengthOf(6);
                (0, chai_1.expect)(data.map(d => d.retentionPercent)).to.deep.equal([50, 75, 25, 25, 25, 0]);
            });
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)(servers);
        });
    });
});
//# sourceMappingURL=video-views-retention-stats.js.map