<commit_before>import {module, test} from 'qunit';
import { Model, ActiveModelSerializer } from 'ember-cli-mirage';
import Server from 'ember-cli-mirage/server';

module('Integration | Server | Resource shorthand', {
  beforeEach() {
    this.server = new Server({
      environment: 'test',
      models: {
        contact: Model,
        blogPost: Model
      },
      serializers: {
        application: ActiveModelSerializer
      }
    });
    this.server.timing = 0;
    this.server.logging = false;
  },
  afterEach() {
    this.server.shutdown();
  }
});

test('resource generates get shorthand for index action', function(assert) {
  assert.expect(3);
  let done = assert.async(2);

  this.server.db.loadData({
    contacts: [
      { id: 1, name: 'Link' },
      { id: 2, name: 'Zelda' }
    ],
    blogPosts: [
      { id: 1, title: 'Post 1' },
      { id: 2, title: 'Post 2' }
    ]
  });

  this.server.resource('contacts');
  this.server.resource('blog-posts', 'posts');

  $.ajax({
    method: 'GET',
    url: '/contacts'
  }).done(function(res, status, xhr) {
    assert.equal(xhr.status, 200);
    assert.deepEqual(res, { contacts: [{ id: '1', name: 'Link' }, { id: '2', name: 'Zelda' }] });
    done();
  });

  $.ajax({
    method: 'GET',
    url: '/posts'
  }).fail((xhr, textStatus, error) => {
    assert.ok(false, 'failed to find custom path');
    done();
  }).done(function(res, status, xhr) {
    assert.ok(true);
    done();
  });
});

test('resource generates get shorthand for show action', function(assert) {
  assert.expect(3);
  let done = assert.async(2);

  this.server.db.loadData({
    contacts: [
      { id: 1, name: 'Link' },
      { id: 2, name: 'Zelda' }
    ],
    blogPosts: [
      { id: 1, title: 'Post 1' },
      { id: 2, title: 'Post 2' }
    ]
  });

  this.server.resource('contacts');
  this.server.resource('blog-posts', 'posts');

  $.ajax({
    method: 'GET',
    url: '/contacts/2'
  }).done(function(res, status, xhr) {
    assert.equal(xhr.status, 200);
    assert.deepEqual(res, { contact: { id: '2', name: 'Zelda' } });
    done();
  });

  $.ajax({
    method: 'GET',
    url: '/posts/2'
  }).fail((xhr, textStatus, error) => {
    assert.ok(false, 'failed to find custom path');
    done();
  }).done(function(res, status, xhr) {
    assert.ok(true);
    done();
  });
});

test('resource generates post shorthand', function(assert) {
  let { server } = this;
  assert.expect(3);
  let done = assert.async(2);

  server.resource('contacts');
  server.resource('blog-posts', 'posts');

  $.ajax({
    method: 'POST',
    url: '/contacts',
    data: JSON.stringify({
      contact: {
        name: 'Zelda'
      }
    })
  }).done((res, status, xhr) => {
    assert.equal(xhr.status, 201);
    assert.equal(server.db.contacts.length, 1);
    done();
  });

  $.ajax({
    method: 'POST',
    url: '/posts',
    data: JSON.stringify({
      blog_post: {
        name: 'Post 1'
      }
    })
  }).fail((xhr, textStatus, error) => {
    assert.ok(false, 'failed to find custom path');
    done()
  }).done((res, status, xhr) => {
    assert.ok(true);
    done();
  });
});

test('resource generates put shorthand', function(assert) {
  let { server } = this;
  assert.expect(3);
  let done = assert.async(2);

  this.server.db.loadData({<commit_msg>add missing semi-colon<commit_after>import {module, test} from 'qunit';
import { Model, ActiveModelSerializer } from 'ember-cli-mirage';
import Server from 'ember-cli-mirage/server';

module('Integration | Server | Resource shorthand', {
  beforeEach() {
    this.server = new Server({
      environment: 'test',
      models: {
        contact: Model,
        blogPost: Model
      },
      serializers: {
        application: ActiveModelSerializer
      }
    });
    this.server.timing = 0;
    this.server.logging = false;
  },
  afterEach() {
    this.server.shutdown();
  }
});

test('resource generates get shorthand for index action', function(assert) {
  assert.expect(3);
  let done = assert.async(2);

  this.server.db.loadData({
    contacts: [
      { id: 1, name: 'Link' },
      { id: 2, name: 'Zelda' }
    ],
    blogPosts: [
      { id: 1, title: 'Post 1' },
      { id: 2, title: 'Post 2' }
    ]
  });

  this.server.resource('contacts');
  this.server.resource('blog-posts', 'posts');

  $.ajax({
    method: 'GET',
    url: '/contacts'
  }).done(function(res, status, xhr) {
    assert.equal(xhr.status, 200);
    assert.deepEqual(res, { contacts: [{ id: '1', name: 'Link' }, { id: '2', name: 'Zelda' }] });
    done();
  });

  $.ajax({
    method: 'GET',
    url: '/posts'
  }).fail((xhr, textStatus, error) => {
    assert.ok(false, 'failed to find custom path');
    done();
  }).done(function(res, status, xhr) {
    assert.ok(true);
    done();
  });
});

test('resource generates get shorthand for show action', function(assert) {
  assert.expect(3);
  let done = assert.async(2);

  this.server.db.loadData({
    contacts: [
      { id: 1, name: 'Link' },
      { id: 2, name: 'Zelda' }
    ],
    blogPosts: [
      { id: 1, title: 'Post 1' },
      { id: 2, title: 'Post 2' }
    ]
  });

  this.server.resource('contacts');
  this.server.resource('blog-posts', 'posts');

  $.ajax({
    method: 'GET',
    url: '/contacts/2'
  }).done(function(res, status, xhr) {
    assert.equal(xhr.status, 200);
    assert.deepEqual(res, { contact: { id: '2', name: 'Zelda' } });
    done();
  });

  $.ajax({
    method: 'GET',
    url: '/posts/2'
  }).fail((xhr, textStatus, error) => {
    assert.ok(false, 'failed to find custom path');
    done();
  }).done(function(res, status, xhr) {
    assert.ok(true);
    done();
  });
});

test('resource generates post shorthand', function(assert) {
  let { server } = this;
  assert.expect(3);
  let done = assert.async(2);

  server.resource('contacts');
  server.resource('blog-posts', 'posts');

  $.ajax({
    method: 'POST',
    url: '/contacts',
    data: JSON.stringify({
      contact: {
        name: 'Zelda'
      }
    })
  }).done((res, status, xhr) => {
    assert.equal(xhr.status, 201);
    assert.equal(server.db.contacts.length, 1);
    done();
  });

  $.ajax({
    method: 'POST',
    url: '/posts',
    data: JSON.stringify({
      blog_post: {
        name: 'Post 1'
      }
    })
  }).fail((xhr, textStatus, error) => {
    assert.ok(false, 'failed to find custom path');
    done();
  }).done((res, status, xhr) => {
    assert.ok(true);
    done();
  });
});

test('resource generates put shorthand', function(assert) {
  let { server } = this;
  assert.expect(3);
  let done = assert.async(2);

  this.server.db.loadData({
{'fraction_non_alphanumeric': 0.19510721836303233, 'fraction_numerical': 0.01117487163998792, 'mean_word_length': 2.7041387024608503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '250025', 'n_tokens_mistral': 2395, 'n_tokens_neox': 2312, 'n_words': 521}