<commit_before>import Ember from 'ember';
import DS from 'ember-data';
import FactoryGuy from './factory-guy';
import MockUpdateRequest from './mocks/mock-update-request';
import MockCreateRequest from './mocks/mock-create-request';
import MockQueryRequest from './mocks/mock-query-request';
import MockQueryRecordRequest from './mocks/mock-query-record-request';
import MockFindRequest from './mocks/mock-find-request';
import MockReloadRequest from './mocks/mock-reload-request';
import MockFindAllRequest from './mocks/mock-find-all-request';
import MockDeleteRequest from './mocks/mock-delete-request';

let MockServer = Ember.Object.extend({

  setup: function({mockjaxLogLevel = 1, responseTime = 0, logLevel = 0 }={}) {
    Ember.$.mockjaxSettings.logging = mockjaxLogLevel; // set to 4 for maximum logging output
    Ember.$.mockjaxSettings.responseTime = responseTime;
    FactoryGuy.settings({logLevel});
  },

  teardown: function () {
    Ember.$.mockjax.clear();
  },

  // Look up a controller from the current container
  controllerFor: function (name) {
    return this.get('container').lookup('controller:' + name);
  },

  // Set a property on a controller in the current container
  setControllerProp: function (controller_name, property, value) {
    let controller = this.controllerFor(controller_name);
    controller.set(property, value);
  },

  /**
   Using mockjax to stub an http request.

   @param {String} url request url
   @param {Object} json response
   @param {Object} options ajax request options
   */
  stubEndpointForHttpRequest: function (url, json, options={}) {
    let request = {
      url: url,
      dataType: 'json',
      responseText: json,
      type: options.type || 'GET',
      status: options.status || 200
    };
    if (options.urlParams) {
      request.urlParams = options.urlParams;
    }
    if (options.data) {
      request.data = options.data;
    }

    return $.mockjax(request);
  },
  /**
   Handling ajax GET for handling finding a model
   You can mock failed find by calling `fails()`

   ```js
   // Typically you will use like:

   // To return default factory 'user'
   let mockFind = TestHelper.mockFind('user');
   let userId = mockFind.get('id');

   // or to return custom factory built json object
   let json = FactoryGuy.build('user', 'with_whacky_name', {isDude: true});
   let mockFind = TestHelper.mockFind('user').returns({json});
   let userId = json.get('id');

   // To mock failure case use method fails
   TestHelper.mockFind('user').fails();

   // Then to 'find' the user
   store.find('user', userId);

   // or in acceptance test
   visit('/user'+userId);
   ```

   @param {String} name  name of the fixture ( or modelName ) to find
   @param {String} trait  optional traits (one or more)<commit_msg>doc update<commit_after>import Ember from 'ember';
import DS from 'ember-data';
import FactoryGuy from './factory-guy';
import MockUpdateRequest from './mocks/mock-update-request';
import MockCreateRequest from './mocks/mock-create-request';
import MockQueryRequest from './mocks/mock-query-request';
import MockQueryRecordRequest from './mocks/mock-query-record-request';
import MockFindRequest from './mocks/mock-find-request';
import MockReloadRequest from './mocks/mock-reload-request';
import MockFindAllRequest from './mocks/mock-find-all-request';
import MockDeleteRequest from './mocks/mock-delete-request';

let MockServer = Ember.Object.extend({

  setup: function({mockjaxLogLevel = 1, responseTime = 0, logLevel = 0 }={}) {
    Ember.$.mockjaxSettings.logging = mockjaxLogLevel; // set to 4 for maximum logging output
    Ember.$.mockjaxSettings.responseTime = responseTime;
    FactoryGuy.settings({logLevel});
  },

  teardown: function () {
    Ember.$.mockjax.clear();
  },

  // Look up a controller from the current container
  controllerFor: function (name) {
    return this.get('container').lookup('controller:' + name);
  },

  // Set a property on a controller in the current container
  setControllerProp: function (controller_name, property, value) {
    let controller = this.controllerFor(controller_name);
    controller.set(property, value);
  },

  /**
   Using mockjax to stub an http request.

   @param {String} url request url
   @param {Object} json response
   @param {Object} options ajax request options
   */
  stubEndpointForHttpRequest: function (url, json, options={}) {
    let request = {
      url: url,
      dataType: 'json',
      responseText: json,
      type: options.type || 'GET',
      status: options.status || 200
    };
    if (options.urlParams) {
      request.urlParams = options.urlParams;
    }
    if (options.data) {
      request.data = options.data;
    }

    return $.mockjax(request);
  },
  /**
   Handling ajax GET for handling finding a model
   You can mock failed find by calling `fails()`

   ```js
   // Typically you will use like:

   // To return default factory 'user'
   let mock = mockFind('user');
   let userId = mock.get('id');

   // or to return custom factory built json object
   let json = build('user', 'with_whacky_name', {isDude: true});
   let mock = mockFind('user').returns({json});
   let userId = json.get('id');

   // To mock failure case use method fails
   mockFind('user').fails();

   // Then to 'find' the user
   store.find('user', userId);

   // or in acceptance test
   visit('/user'+userId);
   ```

   @param {String} name  name of the fixture ( or modelName ) to find
   @param {String} trait  optional traits (one or more)
{'fraction_non_alphanumeric': 0.12913727618014106, 'fraction_numerical': 0.00253210345451257, 'mean_word_length': 3.4886363636363638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4988911', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1589, 'n_words': 492}