<commit_before>describe('SugarCRM Javascript API', function () {

    beforeEach(function () {
        this.api = SUGAR.Api.createInstance({
            serverUrl:"/rest/v10",
            keyValueStore: SugarTest.keyValueStore
        });
        this.fixtures = fixtures.api;
        this.fixtures.fields = fixtures.metadata.fields;
        SugarTest.seedFakeServer();
        this.callbacks = {
            success:function (data) {},
            error:function (data) {}
        };
    });

    afterEach(function () {
        if (this.callbacks.success.restore) this.callbacks.success.restore();
        if (this.api.call.restore) this.api.call.restore();
        if (jQuery.ajax.restore) jQuery.ajax.restore();
        if (SugarTest.keyValueStore.set.restore) SugarTest.keyValueStore.set.restore();
        if (SugarTest.keyValueStore.get.restore) SugarTest.keyValueStore.get.restore();
        if (SugarTest.keyValueStore.cut.restore) SugarTest.keyValueStore.cut.restore();
    });

    it('should create a default api instance', function () {
        var api = SUGAR.Api.createInstance();
        expect(api.serverUrl).toEqual('/rest/v10');
        expect(api.isAuthenticated()).toBeFalsy();
    });

    it('should create an authenticated instance if storage has auth token set', function () {

        SugarTest.storage.AuthAccessToken = "<PASSWORD>";
        var sspy = sinon.spy(SugarTest.keyValueStore, 'get'),
            api = SUGAR.Api.createInstance({
                serverUrl:"/rest/v10",
                platform: "portal",
                keyValueStore: SugarTest.keyValueStore
            });

        expect(api.isAuthenticated()).toBeTruthy();
        expect(sspy).toHaveBeenCalled();
    });

    it('should fail to create an instance if key/value store is invalid', function () {
        expect(function() {
            SUGAR.Api.createInstance({ keyValueStore: {} });<commit_msg>Fixing test issues. Any runner should have it's own config.js file. Other fixes.<commit_after>describe('SugarCRM Javascript API', function () {

    function restoreApiSingleton() {
        // Essentially, this will go back to an API instance per user's config file
        SUGAR.Api.createInstance({
            serverUrl: SUGAR.App.config.serverUrl,
            platform: SUGAR.App.config.platform,
            timeout: SUGAR.App.config.serverTimeout,
            keyValueStore: SUGAR.App[SUGAR.App.config.authStore || "cache"],
            clientID: SUGAR.App.config.clientID
        });
    }

    beforeEach(function () {
        this.api = SUGAR.Api.createInstance({
            serverUrl:"/rest/v10",
            keyValueStore: SugarTest.keyValueStore
        });
        this.fixtures = fixtures.api;
        this.fixtures.fields = fixtures.metadata.fields;
        SugarTest.seedFakeServer();
        this.callbacks = {
            success:function (data) {},
            error:function (data) {}
        };
    });

    afterEach(function () {
        if (this.callbacks.success.restore) this.callbacks.success.restore();
        if (this.api.call.restore) this.api.call.restore();
        if (jQuery.ajax.restore) jQuery.ajax.restore();
        if (SugarTest.keyValueStore.set.restore) SugarTest.keyValueStore.set.restore();
        if (SugarTest.keyValueStore.get.restore) SugarTest.keyValueStore.get.restore();
        if (SugarTest.keyValueStore.cut.restore) SugarTest.keyValueStore.cut.restore();

        // Since api is a singleton .. /rest/v10 becomes the new serverUrl for all other tests.
        restoreApiSingleton();
    });

    it('should create a default api instance', function () {
        var api = SUGAR.Api.createInstance();
        expect(api.serverUrl).toEqual('/rest/v10');
        expect(api.isAuthenticated()).toBeFalsy();
    });

    it('should create an authenticated instance if storage has auth token set', function () {

        SugarTest.storage.AuthAccessToken = "xyz";
        var sspy = sinon.spy(SugarTest.keyValueStore, 'get'),
            api = SUGAR.Api.createInstance({
                serverUrl:"/rest/v10",
                platform: "portal",
                keyValueStore: SugarTest.keyValueStore
            });

        expect(api.isAuthenticated()).toBeTruthy();
        expect(sspy).toHaveBeenCalled();
    });

    it('should fail to create an instance if key/value store is invalid', function () {
        expect(function() {
            SUGAR.Api.createInstance({ keyValueStore: {} });
{'fraction_non_alphanumeric': 0.1278364412491575, 'fraction_numerical': 0.0031453605931251404, 'mean_word_length': 2.4754098360655736, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5429890', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1248, 'n_words': 240}