"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const shared_1 = require("../../shared");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test videos history API validator', function () {
    const myHistoryPath = '/api/v1/users/me/history/videos';
    const myHistoryRemove = myHistoryPath + '/remove';
    let viewPath;
    let server;
    let videoId;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(30000);
            server = yield (0, server_commands_1.createSingleServer)(1);
            yield (0, server_commands_1.setAccessTokensToServers)([server]);
            const { id, uuid } = yield server.videos.upload();
            viewPath = '/api/v1/videos/' + uuid + '/views';
            videoId = id;
        });
    });
    describe('When notifying a user is watching a video', function () {
        it('Should fail with a bad token', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const fields = { currentTime: 5 };
                yield (0, server_commands_1.makePutBodyRequest)({ url: server.url, path: viewPath, fields, token: 'bad', expectedStatus: 401 });
            });
        });
        it('Should succeed with the correct parameters', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const fields = { currentTime: 5 };
                yield (0, server_commands_1.makePutBodyRequest)({
                    url: server.url,
                    path: viewPath,
                    fields,
                    token: server.accessToken,
                    expectedStatus: 204
                });
            });
        });
    });
    describe('When listing user videos history', function () {
        it('Should fail with a bad start pagination', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, shared_1.checkBadStartPagination)(server.url, myHistoryPath, server.accessToken);
            });
        });
        it('Should fail with a bad count pagination', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, shared_1.checkBadCountPagination)(server.url, myHistoryPath, server.accessToken);
            });
        });
        it('Should fail with an unauthenticated user', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeGetRequest)({ url: server.url, path: myHistoryPath, expectedStatus: 401 });
            });
        });
        it('Should succeed with the correct params', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeGetRequest)({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: 200 });
            });
        });
    });
    describe('When removing a specific user video history element', function () {
        let path;
        before(function () {
            path = myHistoryPath + '/' + videoId;
        });
        it('Should fail with an unauthenticated user', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeDeleteRequest)({ url: server.url, path, expectedStatus: 401 });
            });
        });
        it('Should fail with a bad videoId parameter', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeDeleteRequest)({
                    url: server.url,
                    token: server.accessToken,
                    path: myHistoryRemove + '/hi',
                    expectedStatus: 400
                });
            });
        });
        it('Should succeed with the correct parameters', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makeDeleteRequest)({
                    url: server.url,
                    token: server.accessToken,
                    path,
                    expectedStatus: 204
                });
            });
        });
    });
    describe('When removing all user videos history', function () {
        it('Should fail with an unauthenticated user', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: 401 });
            });
        });
        it('Should fail with a bad beforeDate parameter', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const body = { beforeDate: '15' };
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    token: server.accessToken,
                    path: myHistoryRemove,
                    fields: body,
                    expectedStatus: 400
                });
            });
        });
        it('Should succeed with a valid beforeDate param', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                const body = { beforeDate: new Date().toISOString() };
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    token: server.accessToken,
                    path: myHistoryRemove,
                    fields: body,
                    expectedStatus: 204
                });
            });
        });
        it('Should succeed without body', function () {
            return tslib_1.__awaiter(this, void 0, void 0, function* () {
                yield (0, server_commands_1.makePostBodyRequest)({
                    url: server.url,
                    token: server.accessToken,
                    path: myHistoryRemove,
                    expectedStatus: 204
                });
            });
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=videos-history.js.map