"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_utils_1 = require("../../../../shared/core-utils");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test metrics API validators', function () {
    let server;
    let videoUUID;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            server = yield (0, server_commands_1.createSingleServer)(1, {
                open_telemetry: {
                    metrics: {
                        enabled: true
                    }
                }
            });
            yield (0, server_commands_1.setAccessTokensToServers)([server]);
            const { uuid } = yield server.videos.quickUpload({ name: 'video' });
            videoUUID = uuid;
        });
    });
    describe('When adding playback metrics', function () {
        const path = '/api/v1/metrics/playback';
        let baseParams;
        before(function () {
            baseParams = {
                playerMode: 'p2p-media-loader',
                resolution: 1080,
                fps: 30,
                resolutionChanges: 1,
                errors: 2,
                downloadedBytesP2P: 0,
                downloadedBytesHTTP: 0,
                uploadedBytesP2P: 0,
                videoId: videoUUID
            };
        });
        it('Should fail with an invalid resolution', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { resolution: 'toto' })
                });
            });
        });
        it('Should fail with an invalid fps', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { fps: 'toto' })
                });
            });
        });
        it('Should fail with a missing/invalid player mode', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: (0, core_utils_1.omit)(baseParams, ['playerMode'])
                });
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { playerMode: 'toto' })
                });
            });
        });
        it('Should fail with an missing/invalid resolution changes', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: (0, core_utils_1.omit)(baseParams, ['resolutionChanges'])
                });
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { resolutionChanges: 'toto' })
                });
            });
        });
        it('Should fail with a missing errors', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
            });
        });
        it('Should fail with an missing/invalid errors', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: (0, core_utils_1.omit)(baseParams, ['errors'])
                });
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { errors: 'toto' })
                });
            });
        });
        it('Should fail with an missing/invalid downloadedBytesP2P', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: (0, core_utils_1.omit)(baseParams, ['downloadedBytesP2P'])
                });
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { downloadedBytesP2P: 'toto' })
                });
            });
        });
        it('Should fail with an missing/invalid downloadedBytesHTTP', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: (0, core_utils_1.omit)(baseParams, ['downloadedBytesHTTP'])
                });
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { downloadedBytesHTTP: 'toto' })
                });
            });
        });
        it('Should fail with an missing/invalid uploadedBytesP2P', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: (0, core_utils_1.omit)(baseParams, ['uploadedBytesP2P'])
                });
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { uploadedBytesP2P: 'toto' })
                });
            });
        });
        it('Should fail with a bad video id', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { videoId: 'toto' })
                });
            });
        });
        it('Should fail with an unknown video', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: Object.assign(Object.assign({}, baseParams), { videoId: 42 }),
                    expectedStatus: 404
                });
            });
        });
        it('Should succeed with the correct params', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    path,
                    fields: baseParams,
                    expectedStatus: 204
                });
            });
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=metrics.js.map