<commit_before>import sinon from 'sinon';
import 'sinon-as-promised';
import Client from '../../lib/ethical-jobs.js';

const willResolveWith = {
  foo: 'bar',
  bar: 'foo', 
  bam: 'wham',
};

// ---
// GET verb
// -----------------

describe('GET requests', () => {

  const api = new Client();

  beforeEach(() => {
    sinon.stub(api, 'dispatchRequest').returns(willResolveWith);
  });

  afterEach(() => {
    api.dispatchRequest.restore();
  });

  test('should call dispatch only once', () => {
    api.get('/my/cool/route');
    expect(api.dispatchRequest.calledOnce).toBe(true);
  });  

  test('should use the correct HTTP verb', () => {
    api.get('/my/cool/route');
    expect(api.dispatchRequest.args[0][1].method).toBe('get');
  });

  test('should call dispatch with correct route', () => {
    api.get('/my/cool/route');
    expect(api.dispatchRequest.args[0][0]).toBe('//api.ethicaljobs.com.au/my/cool/route');
  });  

  test('should send correct params', () => {
    api.get('/my/cool/route', { foo: 'bar', funy: 'music'});
    expect(api.dispatchRequest.args[0][0]).toBe('//api.ethicaljobs.com.au/my/cool/route?foo=bar&funy=music');
    expect(api.dispatchRequest.args[0][1].body).toBe('{}');
  });  

  test('should return the correct response', () => {
    return expect(api.get('/my/cool/route')).toEqual(willResolveWith);
  }); 

});

// ---
// POST verb<commit_msg>verb test passing<commit_after>import sinon from 'sinon';
import 'sinon-as-promised';
import Client from '../../lib/ethical-jobs.js';

const willResolveWith = {
  foo: 'bar',
  bar: 'foo', 
  bam: 'wham',
};

// ---
// GET verb
// -----------------

describe('GET requests', () => {

  const api = new Client();

  beforeEach(() => {
    sinon.stub(api, 'dispatchRequest').returns(willResolveWith);
  });

  afterEach(() => {
    api.dispatchRequest.restore();
  });

  test('should call dispatch only once', () => {
    api.get('/my/cool/route');
    expect(api.dispatchRequest.calledOnce).toBe(true);
  });  

  test('should use the correct HTTP verb', () => {
    api.get('/my/cool/route');
    expect(api.dispatchRequest.args[0][1].method).toBe('get');
  });

  test('should call dispatch with correct route', () => {
    api.get('/my/cool/route');
    expect(api.dispatchRequest.args[0][0]).toBe('//api.ethicaljobs.com.au/my/cool/route');
  });  

  test('should send correct params', () => {
    api.get('/my/cool/route', { foo: 'bar', funy: 'music'});
    expect(api.dispatchRequest.args[0][0]).toBe('//api.ethicaljobs.com.au/my/cool/route?foo=bar&funy=music');
    expect(api.dispatchRequest.args[0][1].body).toBe(null);
  });  

  test('should return the correct response', () => {
    return expect(api.get('/my/cool/route')).toEqual(willResolveWith);
  }); 

});

// ---
// POST verb
{'fraction_non_alphanumeric': 0.2349137931034483, 'fraction_numerical': 0.005747126436781609, 'mean_word_length': 3.2912172573189524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4791822', 'n_tokens_mistral': 977, 'n_tokens_neox': 936, 'n_words': 149}