<commit_before>//TODO: Query params
//TODO: Request headers
//TODO: Request body

import test from 'tape';
import $ from 'jquery';
import {Server, Router} from '../../../src';

const server = new Server();
const router = new Router();
const response = [{name: 'Hector'}];
const checkResponse = (assert, response) => assert.equal(response[0].name, 'Hector', 'Return the right response');

router.get('/users', request => response)
router.post('/users', request => response);
server.use(router);

export const jquerySpec = () => {
  test('Integration # jQuery # get', (assert) => {
    assert.plan(1);

    $.get('/users').then(r => {
      checkResponse(assert, r);
    });
  });
  test('Integration # jQuery # getJSON', (assert) => {
    assert.plan(1);

    $.getJSON('/users').then(r => {
      checkResponse(assert, r);
    });
  });
  test('Integration # jQuery # post', (assert) => {
    assert.plan(1);

    $.post('/users').then(r => {
      checkResponse(assert, r);
    });
  });
  test('Integration # jQuery # ajax', (assert) => {
    assert.plan(3);

    $.ajax({
      url: '/users',
      success(r) {
        checkResponse(assert, r);
      }
    });
    $.ajax({
      url: '/users',
      method: 'POST',
      success(r) {
        checkResponse(assert, r);
      }
    });
    $.ajax({
      url: '/users',
      method: 'POST',
      success(r) {
        checkResponse(assert, r);
      },
      dataType: 'json'
    });
  });
};<commit_msg>Improve jQuery coverage<commit_after>import test from 'tape';
import $ from 'jquery';
import {Server, Router} from '../../../src';

const server = new Server();
const router = new Router();
const response = [{name: 'Hector'}];
const checkResponse = (assert, response) => assert.equal(response[0].name, 'Hector', 'Return the right response');

router.get('/users', request => response)
router.post('/users', request => response);
server.use(router);

export const jquerySpec = () => {
  test('Integration # jQuery # get', (assert) => {
    assert.plan(1);

    $.get('/users').then(r => {
      checkResponse(assert, r);
    });
  });
  test('Integration # jQuery # getJSON', (assert) => {
    assert.plan(1);

    $.getJSON('/users').then(r => {
      checkResponse(assert, r);
    });
  });
  test('Integration # jQuery # post', (assert) => {
    assert.plan(1);

    $.post('/users').then(r => {
      checkResponse(assert, r);
    });
  });
  test('Integration # jQuery # ajax', (assert) => {
    assert.plan(3);

    $.ajax({
      url: '/users',
      success(r) {
        checkResponse(assert, r);
      }
    });
    $.ajax({
      url: '/users',
      method: 'POST',
      success(r) {
        checkResponse(assert, r);
      }
    });
    $.ajax({
      url: '/users',
      method: 'POST',
      success(r) {
        checkResponse(assert, r);
      },
      dataType: 'json'
    });
  });
  test('Integration # jQuery # params', assert => {
    assert.plan(1);

    const server = new Server();
    const router = new Router();

    router.get('/params_test', request => {
      assert.equal(request.query.param1, 'foo', 'Query params is fine');
    });

    server.use(router);

    $.get('/params_test', {param1: 'foo'});
  });
  test('Integration # jQuery # post # body', assert => {
    assert.plan(2);

    const server = new Server();
    const router = new Router();

    router.post('/body_test', request => {
      assert.equal(request.body, 'foo=bar', 'Body is sent properly');
    });

    server.use(router);

    $.post('/body_test', {foo: 'bar'});
    $.ajax({
      type: "POST",
      url: '/body_test',
      data: {foo: 'bar'}
    });
  });
  test('Integration # jQuery # headers', assert => {
    assert.plan(1);

    const server = new Server();
    const router = new Router();

    router.post('/headers_test', request => {
      assert.equal(request.headers['X-Kakapo-token'], 1234, 'Custom header is received');
    });

    server.use(router);

    $.ajax({
      type: "POST",
      url: '/headers_test',
      headers: {
        'X-Kakapo-token': <PASSWORD>
      }
    });
  });
};
{'fraction_non_alphanumeric': 0.20372640353027702, 'fraction_numerical': 0.004658004412846286, 'mean_word_length': 2.617021276595745, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 32, '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': '2633454', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1295, 'n_words': 294}