<commit_before>/*
 * (C) Copyright 2017 o2r project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/* eslint-env mocha */
const assert = require('chai').assert;
const request = require('request');
const config = require('../config/config');

require("./setup")
const cookie = 's:C0LIrsxGtHOGHld8Nv2jedjL4evGgEHo.GMsWD5Vveq0vBt7/4rGeoH5Xx7Dd2pgZR9DvhKCyDTY';
const cookie_plain = 's:yleQfdYnkh-sbj9Ez--_TWHVhXeXNEgq.qRmINNdkRuJ+iHGg5woRa9ydziuJ+DzFG9GnAZRvaaM';
const requestLoadingTimeout = 20000;


describe('Sciebo loader with workspaces', function () {
    describe('create new compendium based on a workspace in a public WebDAV', () => {
        it('should respond with a compendium ID', (done) => {
            let form = {
                share_url: 'https://uni-muenster.sciebo.de/index.php/s/96XJFrmd3cSYGko',
                content_type: 'workspace'
            };

            let j = request.jar();
            let ck = request.cookie('connect.sid=' + cookie);
            j.setCookie(ck, global.test_host);

            request({
                uri: global.test_host + '/api/v1/compendium',
                method: 'POST',
                jar: j,
                form: form,
                timeout: requestLoadingTimeout
            }, (err, res, body) => {
                assert.ifError(err);
                assert.equal(res.statusCode, 200);
                assert.isObject(JSON.parse(body), 'returned JSON');
                assert.isDefined(JSON.parse(body).id, 'returned id');
                done();
            });
        }).timeout(20000);

        it('should download the files in the workspace and list them via the API', (done) => {
            let form = {
                share_url: 'https://uni-muenster.sciebo.de/index.php/s/96XJFrmd3cSYGko',
                content_type: 'workspace'
            };

            let j = request.jar();
            let ck = request.cookie('connect.sid=' + cookie);
            j.setCookie(ck, global.test_host);

            request({
                uri: global.test_host + '/api/v1/compendium',
                method: 'POST',
                jar: j,
                form: form,
                timeout: requestLoadingTimeout
            }, (err, res, body) => {
                assert.ifError(err);
                let compendium_id = JSON.parse(body).id;

                request({
                    uri: global.test_host_read + '/api/v1/compendium/' + compendium_id,
                    method: 'GET',
                    jar: j,
                    timeout: requestLoadingTimeout
                }, (err, res, body) => {
                    assert.ifError(err);
                    assert.equal(res.statusCode, 200);
                    let response = JSON.parse(body);

                    assert.include(JSON.stringify(response), 'data/main.Rmd');
                    assert.include(JSON.stringify(response), 'data/display.html');

                    done();
                });
            });
        }).timeout(20000);
    });

    describe('create new compendium based on a workspace in a public WebDAV with workspace in a subdirectory', () => {
        let compendium_id = null;

        it('should respond with a compendium ID', (done) => {
            let form = {
                share_url: 'https://uni-muenster.sciebo.de/index.php/s/VEX8Bd88hPAm7fa',
                path: '/my-research',
                content_type: 'workspace'
            };

            let j = request.jar();
            let ck = request.cookie('connect.sid=' + cookie);
            j.setCookie(ck, global.test_host);

            request({
                uri: global.test_host + '/api/v1/compendium',
                method: 'POST',
                jar: j,
                form: form,
                timeout: requestLoadingTimeout
            }, (err, res, body) => {
                assert.ifError(err);
                assert.equal(res.statusCode, 200);<commit_msg>use new share url style of sciebo in some tests<commit_after>/*
 * (C) Copyright 2017 o2r project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/* eslint-env mocha */
const assert = require('chai').assert;
const request = require('request');
const config = require('../config/config');

require("./setup")
const cookie = 's:C0LIrsxGtHOGHld8Nv2jedjL4evGgEHo.GMsWD5Vveq0vBt7/4rGeoH5Xx7Dd2pgZR9DvhKCyDTY';
const cookie_plain = 's:yleQfdYnkh-sbj9Ez--_TWHVhXeXNEgq.qRmINNdkRuJ+iHGg5woRa9ydziuJ+DzFG9GnAZRvaaM';
const requestLoadingTimeout = 20000;


describe('Sciebo loader with workspaces', function () {
    describe('create new compendium based on a workspace in a public WebDAV', () => {
        it('should respond with a compendium ID', (done) => {
            let form = {
                share_url: 'https://uni-muenster.sciebo.de/s/96XJFrmd3cSYGko',
                content_type: 'workspace'
            };

            let j = request.jar();
            let ck = request.cookie('connect.sid=' + cookie);
            j.setCookie(ck, global.test_host);

            request({
                uri: global.test_host + '/api/v1/compendium',
                method: 'POST',
                jar: j,
                form: form,
                timeout: requestLoadingTimeout
            }, (err, res, body) => {
                assert.ifError(err);
                assert.equal(res.statusCode, 200);
                assert.isObject(JSON.parse(body), 'returned JSON');
                assert.isDefined(JSON.parse(body).id, 'returned id');
                done();
            });
        }).timeout(20000);

        it('should download the files in the workspace and list them via the API', (done) => {
            let form = {
                share_url: 'https://uni-muenster.sciebo.de/index.php/s/96XJFrmd3cSYGko',
                content_type: 'workspace'
            };

            let j = request.jar();
            let ck = request.cookie('connect.sid=' + cookie);
            j.setCookie(ck, global.test_host);

            request({
                uri: global.test_host + '/api/v1/compendium',
                method: 'POST',
                jar: j,
                form: form,
                timeout: requestLoadingTimeout
            }, (err, res, body) => {
                assert.ifError(err);
                let compendium_id = JSON.parse(body).id;

                request({
                    uri: global.test_host_read + '/api/v1/compendium/' + compendium_id,
                    method: 'GET',
                    jar: j,
                    timeout: requestLoadingTimeout
                }, (err, res, body) => {
                    assert.ifError(err);
                    assert.equal(res.statusCode, 200);
                    let response = JSON.parse(body);

                    assert.include(JSON.stringify(response), 'data/main.Rmd');
                    assert.include(JSON.stringify(response), 'data/display.html');

                    done();
                });
            });
        }).timeout(20000);
    });

    describe('create new compendium based on a workspace in a public WebDAV with workspace in a subdirectory', () => {
        let compendium_id = null;

        it('should respond with a compendium ID', (done) => {
            let form = {
                share_url: 'https://uni-muenster.sciebo.de/s/VEX8Bd88hPAm7fa',
                path: '/my-research',
                content_type: 'workspace'
            };

            let j = request.jar();
            let ck = request.cookie('connect.sid=' + cookie);
            j.setCookie(ck, global.test_host);

            request({
                uri: global.test_host + '/api/v1/compendium',
                method: 'POST',
                jar: j,
                form: form,
                timeout: requestLoadingTimeout
            }, (err, res, body) => {
                assert.ifError(err);
                assert.equal(res.statusCode, 200);
{'fraction_non_alphanumeric': 0.11711913843392416, 'fraction_numerical': 0.014135068431680503, 'mean_word_length': 1.751543209876543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7453728', 'n_tokens_mistral': 2710, 'n_tokens_neox': 2521, 'n_words': 616}