"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test videos views', function () {
    let servers;
    let liveVideoId;
    let videoId;
    let remoteVideoId;
    let userAccessToken;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            servers = yield (0, server_commands_1.createMultipleServers)(2);
            yield (0, server_commands_1.setAccessTokensToServers)(servers);
            yield (0, server_commands_1.setDefaultVideoChannel)(servers);
            yield servers[0].config.enableLive({ allowReplay: false, transcoding: false });
            ({ uuid: videoId } = yield servers[0].videos.quickUpload({ name: 'video' }));
            ({ uuid: remoteVideoId } = yield servers[1].videos.quickUpload({ name: 'video' }));
            ({ uuid: liveVideoId } = yield servers[0].live.create({
                fields: {
                    name: 'live',
                    privacy: 1,
                    channelId: servers[0].store.channel.id
                }
            }));
            userAccessToken = yield servers[0].users.generateUserAndToken('user');
            yield (0, server_commands_1.doubleFollow)(servers[0], servers[1]);
        });
    });
    describe('When viewing a video', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            it('Should fail without current time');
            it('Should fail with an invalid current time', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    yield servers[0].views.view({ id: videoId, currentTime: -1, expectedStatus: 400 });
                    yield servers[0].views.view({ id: videoId, currentTime: 10, expectedStatus: 400 });
                });
            });
            it('Should succeed with correct parameters', function () {
                return tslib_1.__awaiter(this, void 0, void 0, function* () {
                    yield servers[0].views.view({ id: videoId, currentTime: 1 });
                });
            });
        });
    });
    describe('When getting overall stats', function () {
        it('Should fail with a remote video', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getOverallStats({ videoId: remoteVideoId, expectedStatus: 403 });
            });
        });
        it('Should fail without token', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getOverallStats({ videoId, token: null, expectedStatus: 401 });
            });
        });
        it('Should fail with another token', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getOverallStats({
                    videoId,
                    token: userAccessToken,
                    expectedStatus: 403
                });
            });
        });
        it('Should fail with an invalid start date', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getOverallStats({
                    videoId,
                    startDate: 'fake',
                    endDate: new Date().toISOString(),
                    expectedStatus: 400
                });
            });
        });
        it('Should fail with an invalid end date', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getOverallStats({
                    videoId,
                    startDate: new Date().toISOString(),
                    endDate: 'fake',
                    expectedStatus: 400
                });
            });
        });
        it('Should succeed with the correct parameters', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getOverallStats({
                    videoId,
                    startDate: new Date().toISOString(),
                    endDate: new Date().toISOString()
                });
            });
        });
    });
    describe('When getting timeserie stats', function () {
        it('Should fail with a remote video', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({
                    videoId: remoteVideoId,
                    metric: 'viewers',
                    expectedStatus: 403
                });
            });
        });
        it('Should fail without token', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({
                    videoId,
                    token: null,
                    metric: 'viewers',
                    expectedStatus: 401
                });
            });
        });
        it('Should fail with another token', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({
                    videoId,
                    token: userAccessToken,
                    metric: 'viewers',
                    expectedStatus: 403
                });
            });
        });
        it('Should fail with an invalid metric', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({ videoId, metric: 'hello', expectedStatus: 400 });
            });
        });
        it('Should fail with an invalid start date', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({
                    videoId,
                    metric: 'viewers',
                    startDate: 'fake',
                    endDate: new Date(),
                    expectedStatus: 400
                });
            });
        });
        it('Should fail with an invalid end date', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({
                    videoId,
                    metric: 'viewers',
                    startDate: new Date(),
                    endDate: 'fake',
                    expectedStatus: 400
                });
            });
        });
        it('Should fail if start date is specified but not end date', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({
                    videoId,
                    metric: 'viewers',
                    startDate: new Date(),
                    expectedStatus: 400
                });
            });
        });
        it('Should fail if end date is specified but not start date', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({
                    videoId,
                    metric: 'viewers',
                    endDate: new Date(),
                    expectedStatus: 400
                });
            });
        });
        it('Should fail with a too big interval', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({
                    videoId,
                    metric: 'viewers',
                    startDate: new Date('2000-04-07T08:31:57.126Z'),
                    endDate: new Date(),
                    expectedStatus: 400
                });
            });
        });
        it('Should succeed with the correct parameters', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getTimeserieStats({ videoId, metric: 'viewers' });
            });
        });
    });
    describe('When getting retention stats', function () {
        it('Should fail with a remote video', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getRetentionStats({
                    videoId: remoteVideoId,
                    expectedStatus: 403
                });
            });
        });
        it('Should fail without token', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getRetentionStats({
                    videoId,
                    token: null,
                    expectedStatus: 401
                });
            });
        });
        it('Should fail with another token', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getRetentionStats({
                    videoId,
                    token: userAccessToken,
                    expectedStatus: 403
                });
            });
        });
        it('Should fail on live video', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getRetentionStats({ videoId: liveVideoId, expectedStatus: 400 });
            });
        });
        it('Should succeed with the correct parameters', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield servers[0].videoStats.getRetentionStats({ videoId });
            });
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)(servers);
        });
    });
});
//# sourceMappingURL=views.js.map