<commit_before>import { easyRequest } from './easy-requests'
import assert from 'assert'

describe('easyRequest', () => {
  it('is a function', () => {
    assert(typeof easyRequest === 'function')
  })
  it('returns json from fetch', async () => {
    const fetch = () => Promise.resolve({
      json: () => { return {test: "worked"} }
    })
    assert.deepEqual(
      await easyRequest(fetch)(),
      {test: "worked"},
      'did not return json from fetch'
    )
  })
  it('throws error if fetch throws error', async () => {
    const fetch = () => Promise.reject(new Error('some error'))
    let error
    try {
      await easyRequest(fetch)()
    } catch (e) { error = e }

    if(!error) throw new Error('should have thrown an error')
  })

})<commit_msg>(test) better test for easy-request<commit_after>import { post } from './easy-requests'
import assert from 'assert'
import sinon from 'sinon'

describe('post', () => {
  it('returns json from fetch', async () => {
    const fetch = () => Promise.resolve({
      json: () => { return {test: "worked"} }
    })
    assert.deepEqual(
      await post(fetch)(),
      {test: "worked"},
      'did not return json from fetch'
    )
  })
  it('calls fetch the correct way without token', async () => {
    const fetch = sinon.spy((a, b) => {
        return Promise.resolve({
          json: () => { return {} }
        })
      }
    )
    await post(fetch)({
      user: 'bill',
      password: 'password'
    }, 'https://someurl.com')

    assert(fetch.calledWith('https://someurl.com', {
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: 'user=bill&password=password'
    }))

  })
  it('throws error if fetch throws error', async () => {
    const fetch = () => Promise.reject(new Error('some error'))
    let error
    try {
      await post(fetch)()
    } catch (e) { error = e }

    if(!error) throw new Error('should have thrown an error')
  })

})
{'fraction_non_alphanumeric': 0.17210682492581603, 'fraction_numerical': 0.0, 'mean_word_length': 2.618962432915921, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '1855844', 'n_tokens_mistral': 627, 'n_tokens_neox': 616, 'n_words': 169}