<commit_before>/*
 *  Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *  WSO2 Inc. licenses this file to you 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.
 *
 */

import {describe, it} from "mocha";
import DashboardsAPIs from '../src/utils/dashboard-apis';
import {assert} from 'chai';
import TestUtils from './utils/test-utils';

TestUtils.setupMockEnvironment();

describe('Dashboard',
    function () {

        let sampleDashboardJson = {
            "url": "sampledashboard",
            "name": "Sample Dashboard",
            "description": "Lorem ipsum dolor sit amet DAS",
            "landingPage": "page0",
            "parentId": "1",
            "pages": {}
        };

        const HTTP_STATUS_CODE_OK = 200;
        const HTTP_STATUS_CODE_CREATED = 201;

        describe('#createDashboard()',
            function () {
                it('Should return HTTP 201 status code for newly created Dashboard',
                    function () {
                        let dashboardsAPIs = new DashboardsAPIs();
                        let promised_create = dashboardsAPIs.createDashboard(sampleDashboardJson);
                        return promised_create.then((response) => {
                            assert.equal(response.status, HTTP_STATUS_CODE_CREATED, 'Error in creating the dashboard -' +
                                ' Failed !');
                        });
                    }
                );
            }
        );
        describe('#getDashboardList()',
            function () {
                it('Should return HTTP 200 status code with dashboard list',
                    function () {
                        let dashboardsAPIs = new DashboardsAPIs();
                        let promised_get_list = dashboardsAPIs.getDashboardList();
                        return promised_get_list.then((response) => {
                            assert.equal(response.status, HTTP_STATUS_CODE_OK, 'Error in retrieving dashboard list -' +
                                ' Failed !');
                        });
                    }
                );
            }
        );
        describe('#getDashboardById()',
            function () {
                it('Should return HTTP 200 status code with dashboard content with given ID',
                    function () {
                        let dashboardsAPIs = new DashboardsAPIs();
                        let promised_get_dashboard = dashboardsAPIs.getDashboardByID("sampledashboard");
                        return promised_get_dashboard.then((response) => {
                            assert.equal(response.status, HTTP_STATUS_CODE_OK, 'Error in retrieving dashboard list - ' +
                                'Failed !');
                            assert.equal(response.data.url, sampleDashboardJson.url, 'Dashboard content - URL is' +
                                ' different' +
                                ' - Failed !');
                            assert.equal(response.data.name, sampleDashboardJson.name, 'Dashboard content - Name is' +
                                ' different' +
                                ' - Failed !');
                            assert.equal(response.data.description, sampleDashboardJson.description, 'Dashboard content' +
                                ' Description is different - Failed !');
                            assert.equal(response.data.landingPage, sampleDashboardJson.landingPage, 'Dashboard content' +
                                ' LandingPage is different - Failed !');
                            assert.equal(response.data.parentId, sampleDashboardJson.parentId, 'Dashboard content' +
                                ' ParentId is different - Failed !');
                        });
                    }
                );
            }
        );
        describe('#updateDashboardByID()',
            function () {
                it('Should return HTTP 200 status code for given dashboard ID',
                    function () {
                        let dashboardsAPIs = new DashboardsAPIs();
                        sampleDashboardJson.landingPage = "page1";
                        let promised_update_dashboard = dashboardsAPIs.updateDashboardByID(sampleDashboardJson.url,
                            sampleDashboardJson);
                        return promised_update_dashboard.then((response) => {
                            assert.equal(response.status, HTTP_STATUS_CODE_OK, 'Error in updating dashboard - Failed !');
                        });
                    }
                );
            }
        );
        describe('#deleteDashboardByID()',
            function () {
                it('Should return HTTP 200 status code by deleting the dashboard with given ID',
                    function () {
                        let dashboardsAPIs = new DashboardsAPIs();
                        let promised_deleted = dashboardsAPIs.deleteDashboardByID(sampleDashboardJson.url);
                        return promised_deleted.then((response) => {
                            assert.equal(response.status, HTTP_STATUS_CODE_OK, 'Error in deleting the dashboard - ' +
                                'Failed !');
                        });
                    }
                );
            }
        );
    }
);<commit_msg>Update REST APIS's test-cases<commit_after>/*
 *  Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *  WSO2 Inc. licenses this file to you 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.
 *
 */

import {describe, it} from "mocha";
import DashboardsAPIs from '../src/utils/dashboard-apis';
import {assert} from 'chai';
import TestUtils from './utils/test-utils';

TestUtils.setupMockEnvironment();

describe('Dashboard',
    function () {

        let sampleDashboardArray = [{
            "url": "sampledashboard",
            "name": "Sample Dashboard",
            "description": "Lorem ipsum dolor sit amet DAS",
            "landingPage": "page0",
            "parentId": "1",
            "pages": {}
        }, {
            "url": "sampledashboard2",
            "name": "Sample Dashboard 2",
            "description": "Lorem ipsum dolor sit amet DAS",
            "landingPage": "page0",
            "parentId": "1",
            "pages": {}
        }];

        let sampleDashboardJson = sampleDashboardArray[0];
        const HTTP_STATUS_CODE_OK = 200;
        const HTTP_STATUS_CODE_CREATED = 201;
        let dashboardsAPIs = new DashboardsAPIs();

        describe('#createDashboard()',
            function () {
                it('Should return HTTP 201 status code for newly created Dashboard',
                    function () {
                        sampleDashboardArray.forEach(dashboardJSON => {
                            let promised_create = dashboardsAPIs.createDashboard(dashboardJSON);
                            return promised_create.then((response) => {
                                assert.equal(response.status, HTTP_STATUS_CODE_CREATED, 'Error in creating the dashboard -' +
                                    ' Failed !');
                            });
                        });
                    }
                );
            }
        );
        describe('#getDashboardList()',
            function () {
                it('Should return HTTP 200 status code with dashboard list',
                    function () {
                        let promised_get_list = dashboardsAPIs.getDashboardList();
                        return promised_get_list.then((response) => {
                            assert.equal(response.status, HTTP_STATUS_CODE_OK, 'Error in retrieving dashboard list -' +
                                ' Failed !');
                            assert.equal(response.data.length, 2, 'Error in retrieving dashboard' +
                                ' list -' +
                                ' Failed !');
                            assert.equal(response.data[0].url, "sampledashboard2", 'Error in retrieving dashboard' +
                                ' list -' +
                                ' Failed !');
                            assert.equal(response.data[1].url, "sampledashboard", 'Error in retrieving dashboard' +
                                ' list -' +
                                ' Failed !');
                        });
                    }
                );
            }
        );
        describe('#getDashboardById()',
            function () {
                it('Should return HTTP 200 status code with dashboard content with given ID',
                    function () {
                        let promised_get_dashboard = dashboardsAPIs.getDashboardByID("sampledashboard");
                        return promised_get_dashboard.then((response) => {
                            assert.equal(response.status, HTTP_STATUS_CODE_OK, 'Error in retrieving dashboard list - ' +
                                'Failed !');
                            assert.equal(response.data.url, sampleDashboardJson.url, 'Dashboard content - URL is' +
                                ' different' +
                                ' - Failed !');
                            assert.equal(response.data.name, sampleDashboardJson.name, 'Dashboard content - Name is' +
                                ' different' +
                                ' - Failed !');
                            assert.equal(response.data.description, sampleDashboardJson.description, 'Dashboard content' +
                                ' Description is different - Failed !');
                            assert.equal(response.data.landingPage, sampleDashboardJson.landingPage, 'Dashboard content' +
                                ' LandingPage is different - Failed !');
                            assert.equal(response.data.parentId, sampleDashboardJson.parentId, 'Dashboard content' +
                                ' ParentId is different - Failed !');
                        });
                    }
                );
            }
        );
        describe('#updateDashboardByID()',
            function () {
                it('Should return HTTP 200 status code for given dashboard ID',
                    function () {
                        sampleDashboardJson.landingPage = "page1";
                        let promised_update_dashboard = dashboardsAPIs.updateDashboardByID(sampleDashboardJson.url,
                            sampleDashboardJson);
                        return promised_update_dashboard.then((response) => {
                            assert.equal(response.status, HTTP_STATUS_CODE_OK, 'Error in updating dashboard - Failed !');
                        });
                    }
                );
            }
        );
        describe('#deleteDashboardByID()',
            function () {
                it('Should return HTTP 200 status code by deleting the dashboard with given ID',
                    function () {
                        sampleDashboardArray.forEach(dashboardJSON => {
                            let promised_deleted = dashboardsAPIs.deleteDashboardByID(dashboardJSON.url);
                            return promised_deleted.then((response) => {
                                assert.equal(response.status, HTTP_STATUS_CODE_OK, 'Error in deleting the dashboard - ' +
                                    'Failed !');
                            });
                        });
                    }
                );
            }
        );
    }
);
{'fraction_non_alphanumeric': 0.09117670459065956, 'fraction_numerical': 0.0062853051157609995, 'mean_word_length': 1.3618940248027058, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6888304', 'n_tokens_mistral': 3006, 'n_tokens_neox': 2856, 'n_words': 704}