<commit_before>"use strict";
var fs = require('fs');
var assert = require('assert');
var request = require("request");
var helper = require("../helper.js");

var Mongo = require("soajs.core.modules").mongo;
var dbConfig = require("./db.config.test.js");

var dashboardConfig = dbConfig();
dashboardConfig.name = "core_provision";
var mongo = new Mongo(dashboardConfig);

var config = helper.requireModule('./config');
var extKey = 'aa39b5490c4a4ed0e56d7ec1232a428f771e8bb83cfcee16de14f735d0f5da587d5968ec4f785e38570902fd24e0b522b46cb171872d1ea038e88328e7d973ff47d9392f72b2d49566209eb88eb60aed8534a965cf30072c39565bd8d72f68ac';

var config = {
  "config": {
      "driver": "travis",
      "settings": {
          "domain": "api.travis-ci.org",
          "owner": "soajsTestAccount",
          "gitToken": ""
      },
      "recipe": "",
  }
};

var repoToUse;

function executeMyRequest(params, apiPath, method, cb) {
    requester(apiPath, method, params, function (error, body) {
        assert.ifError(error);
        assert.ok(body);
        return cb(body);
    });

    function requester(apiName, method, params, cb) {
        var options = {
            uri: 'http://localhost:4000/dashboard/' + apiName,
            headers: {
                'Content-Type': 'application/json',
                key: extKey
            },
            json: true
        };

        if (params.headers) {
            for (var h in params.headers) {
                if (params.headers.hasOwnProperty(h)) {
                    options.headers[h] = params.headers[h];
                }
            }
        }

        if (params.form) {
            options.body = params.form;
        }

        if (params.qs) {
            options.qs = params.qs;
        }
	    
        request[method](options, function (error, response, body) {
            assert.ifError(error);
            assert.ok(body);
            return cb(null, body);
        });
    }
}

describe("DASHBOARD TESTS: Continuous integration", function (){

	before(function(done){
		setTimeout(function(){
			done();
		}, 1500);
	});
	
	afterEach(function(done){
		setTimeout(function(){
			done();
		}, 700);
	});
	
	it("success - login to github", function(done){
		var passwordPersonal = '<PASSWORD>';
		var usernamePersonal = 'soajsTestAccount';
		
		var params = {
			form: {
				"username": usernamePersonal,
				"password": <PASSWORD>,
				"label": "soajs Test Account",
				"provider": "github",
				"domain": "github.com",
				"type": "personal",
				"access": "private"
			}
		};
		executeMyRequest(params, 'gitAccounts/login', 'post', function (body) {
			assert.ok(body);
			
			mongo.findOne("git_accounts", {"owner": usernamePersonal}, function(error, response){
				assert.ifError(error);
				assert.ok(response);
				assert.ok(response.token);
				config.config.settings.gitToken = response.token;
				done();
			});
		});
	});
	
    it("Success - Save config (without recipe)", function(done){
        var params = {};
        params.form = config;

        executeMyRequest(params, 'ci', 'post', function (body) {
        	console.log(JSON.stringify(body, null, 2));
            assert.ok(body.data);
            assert.ok(body.result);
            done();<commit_msg>removed github login and changed token value to become an environment variable.<commit_after>"use strict";
var fs = require('fs');
var assert = require('assert');
var request = require("request");
var helper = require("../helper.js");

var Mongo = require("soajs.core.modules").mongo;
var dbConfig = require("./db.config.test.js");

var dashboardConfig = dbConfig();
dashboardConfig.name = "core_provision";
var mongo = new Mongo(dashboardConfig);

var config = helper.requireModule('./config');
var extKey = 'aa39b5490c4a4ed0e56d7ec1232a428f771e8bb83cfcee16de14f735d0f5da587d5968ec4f785e38570902fd24e0b522b46cb171872d1ea038e88328e7d973ff47d9392f72b2d49566209eb88eb60aed8534a965cf30072c39565bd8d72f68ac';

var config = {
  "config": {
      "driver": "travis",
      "settings": {
          "domain": "api.travis-ci.org",
          "owner": "soajsTestAccount",
          "gitToken": process.env.SOAJS_TEST_GIT_TOKEN
      },
      "recipe": "",
  }
};

var repoToUse;

function executeMyRequest(params, apiPath, method, cb) {
    requester(apiPath, method, params, function (error, body) {
        assert.ifError(error);
        assert.ok(body);
        return cb(body);
    });

    function requester(apiName, method, params, cb) {
        var options = {
            uri: 'http://localhost:4000/dashboard/' + apiName,
            headers: {
                'Content-Type': 'application/json',
                key: extKey
            },
            json: true
        };

        if (params.headers) {
            for (var h in params.headers) {
                if (params.headers.hasOwnProperty(h)) {
                    options.headers[h] = params.headers[h];
                }
            }
        }

        if (params.form) {
            options.body = params.form;
        }

        if (params.qs) {
            options.qs = params.qs;
        }
	    
        request[method](options, function (error, response, body) {
            assert.ifError(error);
            assert.ok(body);
            return cb(null, body);
        });
    }
}

describe("DASHBOARD TESTS: Continuous integration", function (){
	
    it("Success - Save config (without recipe)", function(done){
        var params = {};
        params.form = config;

        executeMyRequest(params, 'ci', 'post', function (body) {
        	console.log(JSON.stringify(body, null, 2));
            assert.ok(body.data);
            assert.ok(body.result);
            done();
{'fraction_non_alphanumeric': 0.14114748328053503, 'fraction_numerical': 0.046286518831397394, 'mean_word_length': 2.433836858006042, 'pattern_counts': {'":': 22, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2483768', 'n_tokens_mistral': 2009, 'n_tokens_neox': 1772, 'n_words': 338}