<commit_before>import {
  moduleFor,
  test
} from 'ember-qunit';

// The default (application) adapter is the DRF adapter.
// see app/adapters/application.js
moduleFor('adapter:application', 'DRFAdapter', {
  // The integration tests don't work with the host set so the host
  // setting is being overridden directly.
  subject: function(options, factory) {
    return factory.create({host: 'test-host'});
  }
});

test('host config override', function(assert) {
  var adapter = this.subject();
  assert.equal(adapter.get('host'), 'test-host');
});

test('namespace config override', function(assert) {
  var adapter = this.subject();
  assert.equal(adapter.get('namespace'), 'test-api');
});

test('pathForType', function(assert) {
  var adapter = this.subject();
  assert.equal(adapter.pathForType('Animal'), 'animals');
  assert.equal(adapter.pathForType('FurryAnimals'), 'furry-animals');
});

test('buildURL', function(assert) {
  var adapter = this.subject();
  assert.equal(adapter.buildURL('Animal', 5, null), 'test-host/test-api/animals/5/');
  assert.equal(adapter.buildURL('FurryAnimals', 5, null), 'test-host/test-api/furry-animals/5/');
});

test('buildURL - no trailing slashes', function(assert) {
  var adapter = this.subject();
  adapter.set('addTrailingSlashes', false);
  assert.equal(adapter.buildURL('Animal', 5, null), 'test-host/test-api/animals/5');
  assert.equal(adapter.buildURL('FurryAnimals', 5, null), 'test-host/test-api/furry-animals/5');
});

test('ajaxError - returns invalid error if 400 response', function(assert) {
  var error = new DS.InvalidError({errors: {name: ['This field cannot be blank.']}});

  var jqXHR = {
    status: 400,
    responseText: JSON.stringify({name: ['This field cannot be blank.']})
  };

  var adapter = this.subject();
  assert.equal(adapter.ajaxError(jqXHR), error.toString());
});

test('ajaxError - returns error if not 400 response', function(assert) {
  var jqXHR = {
    status: 403,
    responseText: JSON.stringify({detail: 'You do not have permission to perform this action.'})
  };

  var adapter = this.subject();
  assert.equal(adapter.ajaxError(jqXHR), jqXHR);
});

test('ajaxError - returns error if no responseText to parse', function(assert) {
  var jqXHR = {
    status: 500,
    statusText: 'Internal Server Error',
    responseText: ''
  };

  var adapter = this.subject();
  assert.equal(adapter.ajaxError(jqXHR), jqXHR);
});

test('ajaxError - returns ajax response if no status returned', function(assert) {
  var jqXHR = {
    responseText: 'Something went wrong'
  };

  var adapter = this.subject();
  assert.equal(adapter.ajaxError(jqXHR), jqXHR);
});

test('_stripIDFromURL - returns base URL for type', function(assert) {
  var record = {
    constructor: { typeKey: 'furry-animal' }
  };
  var adapter = this.subject();

  assert.equal(adapter._stripIDFromURL('store', record), 'test-host/test-api/furry-animals/');
});

test('_stripIDFromURL without trailing slash - returns base URL for type', function(assert) {
  var record = {
    constructor: { typeKey: 'furry-animal' }
  };
  var adapter = this.subject();
  adapter.set('addTrailingSlashes', false);

  assert.equal(adapter._stripIDFromURL('store', record), 'test-host/test-api/furry-animals');
});<commit_msg>Update unit tests for adapter's _stripIDFromURL<commit_after>import {
  moduleFor,
  test
} from 'ember-qunit';

// The default (application) adapter is the DRF adapter.
// see app/adapters/application.js
moduleFor('adapter:application', 'DRFAdapter', {
  // The integration tests don't work with the host set so the host
  // setting is being overridden directly.
  subject: function(options, factory) {
    return factory.create({host: 'test-host'});
  }
});

test('host config override', function(assert) {
  var adapter = this.subject();
  assert.equal(adapter.get('host'), 'test-host');
});

test('namespace config override', function(assert) {
  var adapter = this.subject();
  assert.equal(adapter.get('namespace'), 'test-api');
});

test('pathForType', function(assert) {
  var adapter = this.subject();
  assert.equal(adapter.pathForType('Animal'), 'animals');
  assert.equal(adapter.pathForType('FurryAnimals'), 'furry-animals');
});

test('buildURL', function(assert) {
  var adapter = this.subject();
  assert.equal(adapter.buildURL('Animal', 5, null), 'test-host/test-api/animals/5/');
  assert.equal(adapter.buildURL('FurryAnimals', 5, null), 'test-host/test-api/furry-animals/5/');
});

test('buildURL - no trailing slashes', function(assert) {
  var adapter = this.subject();
  adapter.set('addTrailingSlashes', false);
  assert.equal(adapter.buildURL('Animal', 5, null), 'test-host/test-api/animals/5');
  assert.equal(adapter.buildURL('FurryAnimals', 5, null), 'test-host/test-api/furry-animals/5');
});

test('ajaxError - returns invalid error if 400 response', function(assert) {
  var error = new DS.InvalidError({errors: {name: ['This field cannot be blank.']}});

  var jqXHR = {
    status: 400,
    responseText: JSON.stringify({name: ['This field cannot be blank.']})
  };

  var adapter = this.subject();
  assert.equal(adapter.ajaxError(jqXHR), error.toString());
});

test('ajaxError - returns error if not 400 response', function(assert) {
  var jqXHR = {
    status: 403,
    responseText: JSON.stringify({detail: 'You do not have permission to perform this action.'})
  };

  var adapter = this.subject();
  assert.equal(adapter.ajaxError(jqXHR), jqXHR);
});

test('ajaxError - returns error if no responseText to parse', function(assert) {
  var jqXHR = {
    status: 500,
    statusText: 'Internal Server Error',
    responseText: ''
  };

  var adapter = this.subject();
  assert.equal(adapter.ajaxError(jqXHR), jqXHR);
});

test('ajaxError - returns ajax response if no status returned', function(assert) {
  var jqXHR = {
    responseText: 'Something went wrong'
  };

  var adapter = this.subject();
  assert.equal(adapter.ajaxError(jqXHR), jqXHR);
});

test('_stripIDFromURL - returns base URL for type', function(assert) {
  var snapshot = {
    typeKey: 'furry-animal'
  };
  var adapter = this.subject();

  assert.equal(adapter._stripIDFromURL('store', snapshot), 'test-host/test-api/furry-animals/');
});

test('_stripIDFromURL without trailing slash - returns base URL for type', function(assert) {
  var snapshot = {
    typeKey: 'furry-animal'
  };
  var adapter = this.subject();
  adapter.set('addTrailingSlashes', false);

  assert.equal(adapter._stripIDFromURL('store', snapshot), 'test-host/test-api/furry-animals');
});
{'fraction_non_alphanumeric': 0.1629436964504284, 'fraction_numerical': 0.007037943696450428, 'mean_word_length': 4.606346483704974, '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': '3929107', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2054, 'n_words': 495}