<commit_before>Batman.Request.setupMockedResponse = ->
  Batman.Request.mockedResponses = {}

Batman.Request.addMockedResponse = (method, url, callback) ->
  Batman.Request.mockedResponses["#{method}::#{url}"] ||= []
  Batman.Request.mockedResponses["#{method}::#{url}"].push(callback)

Batman.Request.fetchMockedResponse = (method, url) ->
  callbackList = Batman.Request.mockedResponses?["#{method}::#{url}"]
  return if !callbackList || callbackList.length is 0

  callback = callbackList.pop()
  return callback()

Batman.Request::send = (data) ->
  data ||= @get('data')
  @fire 'loading'

  mockedResponse = Batman.Request.fetchMockedResponse(@get('method'), @get('url'))

  return if not mockedResponse
  {status, response, beforeResponse} = mockedResponse

  @mixin
    status: status
    response: JSON.stringify(response)

  beforeResponse?(this)

  if status < 400
    @fire 'success', response
  else
    @fire 'error', {response: response, status: status, request: this}

  @fire 'loaded'<commit_msg>Mock setImmediate to setTimeout in tests to facilitate sinon fake timer testing<commit_after>Batman.Request.setupMockedResponse = ->
  Batman.Request.mockedResponses = {}

Batman.Request.addMockedResponse = (method, url, callback) ->
  Batman.Request.mockedResponses["#{method}::#{url}"] ||= []
  Batman.Request.mockedResponses["#{method}::#{url}"].push(callback)

Batman.Request.fetchMockedResponse = (method, url) ->
  callbackList = Batman.Request.mockedResponses?["#{method}::#{url}"]
  return if !callbackList || callbackList.length is 0

  callback = callbackList.pop()
  return callback()

Batman.Request::send = (data) ->
  data ||= @get('data')
  @fire 'loading'

  mockedResponse = Batman.Request.fetchMockedResponse(@get('method'), @get('url'))

  return if not mockedResponse
  {status, response, beforeResponse} = mockedResponse

  @mixin
    status: status
    response: JSON.stringify(response)

  beforeResponse?(this)

  if status < 400
    @fire 'success', response
  else
    @fire 'error', {response: response, status: status, request: this}

  @fire 'loaded'

Batman.setImmediate = (fn) -> setTimeout(fn, 0)
Batman.clearImmediate = (handle) -> clearTimeout(handle)

{'fraction_non_alphanumeric': 0.15325147794452024, 'fraction_numerical': 0.004092769440654843, 'mean_word_length': 5.094182825484765, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7432226', 'n_tokens_mistral': 727, 'n_tokens_neox': 705, 'n_words': 143}