<commit_before>/* global describe, require, it */
'use strict';

// safer to ensure this here (in addition to grunt:env:test)
process.env.NODE_ENV = 'test';

var Promise = require( 'lie' );
var chai = require( 'chai' );
var expect = chai.expect;
var chaiAsPromised = require( 'chai-as-promised' );
var model = require( '../../app/models/account-model' );
var config = require( '../../app/models/config-model' ).server;

chai.use( chaiAsPromised );

describe( 'Account Model', function() {

    describe( 'get: when attempting to obtain an account', function() {

        it( 'returns an error when the account does not exist', function() {
            return expect( model.get( 'nonexisting' ) ).to.eventually.be.rejected;
        } );

        [
            // config               // request serverUrl
            [ 'http://example.com', 'http://example.com' ],
            [ 'http://example.com', 'https://example.com' ],
            [ 'http://example.com', 'http://example.com/johndoe' ],
            [ 'http://example.com', 'https://example.com/johndoe' ],
            [ 'https://example.com', 'http://example.com' ],
            [ 'https://example.com', 'http://example.com/johndoe' ],
            [ 'https://example.com', 'https://example.com/johndoe' ],
            [ 'example.com', 'http://example.com' ],
            [ 'example.com', 'https://example.com' ],
            [ 'example.com', 'http://example.com/johndoe' ],
        ].forEach( function( test ) {
            var accountServerUrl = test[ 0 ];
            var requestServerUrl = test[ 1 ];
            it( 'returns the hardcoded account object with linked server ' + accountServerUrl + ' and request server ' + requestServerUrl, function() {
                var getAccountPromise;
                var accountKey = '123abc';
                var survey = {
                    openRosaServer: requestServerUrl
                };

                config[ 'linked form and data server' ][ 'server url' ] = accountServerUrl;
                config[ 'linked form and data server' ][ 'api key' ] = accountKey;

                getAccountPromise = model.get( survey );

                return Promise.all( [
                    expect( getAccountPromise ).to.eventually.have.property( 'key' ).and.to.equal( accountKey ),
                    expect( getAccountPromise ).to.eventually.have.property( 'openRosaServer' ).and.to.equal( accountServerUrl )
                ] );
            } );
        } );

        [
            [ 'http://example.com', 'http://example.org', 403 ],
            [ 'http://examplecom', 'http://example.org', 403 ],
            [ 'http://example.com/johndoe', 'http://example.com', 403 ],

        ].forEach( function( test ) {
            var accountServerUrl = test[ 0 ];
            var requestServerUrl = test[ 1 ];
            var errorCode = test[ 2 ];
            it( 'returns ' + errorCode + ' for ' + accountServerUrl + ' and request server ' + requestServerUrl, function() {
                var getAccountPromise;
                var survey = {
                    openRosaServer: requestServerUrl
                };

                config[ 'linked form and data server' ][ 'server url' ] = accountServerUrl;

                getAccountPromise = model.get( survey );

                return expect( getAccountPromise ).to.eventually.be.rejected;
            } );
        } );

    } );

} );
<commit_msg>fixed: account model tests<commit_after>/* global describe, require, it */
'use strict';

// safer to ensure this here (in addition to grunt:env:test)
process.env.NODE_ENV = 'test';

var Promise = require( 'lie' );
var chai = require( 'chai' );
var expect = chai.expect;
var chaiAsPromised = require( 'chai-as-promised' );
var config = require( '../../app/models/config-model' ).server;
config[ 'account lib' ] = undefined;
var model = require( '../../app/models/account-model' );

chai.use( chaiAsPromised );

describe( 'Account Model', function() {

    describe( 'get: when attempting to obtain an account', function() {

        it( 'returns an error when the account does not exist', function() {
            return expect( model.get( 'nonexisting' ) ).to.eventually.be.rejected;
        } );

        [
            // config               // request serverUrl
            [ 'http://example.com', 'http://example.com' ],
            [ 'http://example.com', 'https://example.com' ],
            [ 'http://example.com', 'http://example.com/johndoe' ],
            [ 'http://example.com', 'https://example.com/johndoe' ],
            [ 'https://example.com', 'http://example.com' ],
            [ 'https://example.com', 'http://example.com/johndoe' ],
            [ 'https://example.com', 'https://example.com/johndoe' ],
            [ 'example.com', 'http://example.com' ],
            [ 'example.com', 'https://example.com' ],
            [ 'example.com', 'http://example.com/johndoe' ],
        ].forEach( function( test ) {
            var accountServerUrl = test[ 0 ];
            var requestServerUrl = test[ 1 ];
            it( 'returns the hardcoded account object with linked server ' + accountServerUrl + ' and request server ' + requestServerUrl, function() {
                var getAccountPromise;
                var accountKey = '123abc';
                var survey = {
                    openRosaServer: requestServerUrl
                };

                config[ 'linked form and data server' ][ 'server url' ] = accountServerUrl;
                config[ 'linked form and data server' ][ 'api key' ] = accountKey;

                getAccountPromise = model.get( survey );

                return Promise.all( [
                    expect( getAccountPromise ).to.eventually.have.property( 'key' ).and.to.equal( accountKey ),
                    expect( getAccountPromise ).to.eventually.have.property( 'linkedServer' ).and.to.equal( accountServerUrl )
                ] );
            } );
        } );

        [
            [ 'http://example.com', 'http://example.org', 403 ],
            [ 'http://examplecom', 'http://example.org', 403 ],
            [ 'http://example.com/johndoe', 'http://example.com', 403 ],

        ].forEach( function( test ) {
            var accountServerUrl = test[ 0 ];
            var requestServerUrl = test[ 1 ];
            var errorCode = test[ 2 ];
            it( 'returns ' + errorCode + ' for ' + accountServerUrl + ' and request server ' + requestServerUrl, function() {
                var getAccountPromise;
                var survey = {
                    openRosaServer: requestServerUrl
                };

                config[ 'linked form and data server' ][ 'server url' ] = accountServerUrl;

                getAccountPromise = model.get( survey );

                return expect( getAccountPromise ).to.eventually.be.rejected;
            } );
        } );

    } );

} );

{'fraction_non_alphanumeric': 0.14988324576765907, 'fraction_numerical': 0.0049620548744892, 'mean_word_length': 1.8673640167364016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 14, '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': '1345008', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1847, 'n_words': 451}