<commit_before>'use strict'

##################
# common helpers #
##################

ok = 200
err = 500

expect_to_be_function = (fn) ->
  expect(fn).toEqual jasmine.any Function

expect_to_be_promise = (obj) ->
  expect(obj).toBeDefined()
  expect_to_be_function obj.then

validate_arguments_count = (args, arg_count, msg) ->
  throw new Error msg unless args.length is arg_count

pass = -> {pass: true}

################
# http helpers #
################

http_backend = ->
  _http_backend = undefined
  inject ($httpBackend) -> _http_backend = $httpBackend
  _http_backend

expect_get = (uri, response) ->
  if response?
    http_backend().expectGET(uri).respond ok, response
  else
    http_backend().expectGET(uri).respond ok

allow_get = (response) ->
  if response?
    http_backend().expectGET().respond ok, response
  else
    http_backend().expectGET().respond ok

fail_get = ->
  http_backend().expectGET().respond err

expect_post = (uri, body, response) ->
  if response?
    http_backend().expectPOST(uri, body).respond ok, response
  else
    http_backend().expectPOST(uri, body).respond ok

allow_post = (response) ->
  if response?
    http_backend().expectPOST().respond ok, response
  else
    http_backend().expectPOST().respond ok

fail_post = ->
  http_backend().expectPOST().respond err

flush = ->
  http_backend().flush()

grab_data = (promise) ->
  _actual_data = undefined
  promise.then (data) -> _actual_data = data
  _actual_data

assert_unwrapped_data = (actual_data, expected_data) ->
  result =
    pass: actual_data is expected_data
    message: ->
      "Expected response data `#{actual_data}` to equal to `#{expected_data}`. Seems that response was not properly unwrapped."

############
# matchers #
############

to_get = ->
  compare: (fn, uri) ->
    # validations
    validate_arguments_count arguments, 2, 'to_get takes a single uri argument.'
    expect_to_be_function fn

    # expect http call
    expect_get uri

    # make the call
    fn()

    # flush & assert<commit_msg>removed unused function<commit_after>'use strict'

##################
# common helpers #
##################

ok = 200
err = 500

expect_to_be_function = (fn) ->
  expect(fn).toEqual jasmine.any Function

expect_to_be_promise = (obj) ->
  expect(obj).toBeDefined()
  expect_to_be_function obj.then

validate_arguments_count = (args, arg_count, msg) ->
  throw new Error msg unless args.length is arg_count

pass = -> {pass: true}

################
# http helpers #
################

http_backend = ->
  _http_backend = undefined
  inject ($httpBackend) -> _http_backend = $httpBackend
  _http_backend

expect_get = (uri, response) ->
  if response?
    http_backend().expectGET(uri).respond ok, response
  else
    http_backend().expectGET(uri).respond ok

allow_get = (response) ->
  if response?
    http_backend().expectGET().respond ok, response
  else
    http_backend().expectGET().respond ok

fail_get = ->
  http_backend().expectGET().respond err

expect_post = (uri, body, response) ->
  if response?
    http_backend().expectPOST(uri, body).respond ok, response
  else
    http_backend().expectPOST(uri, body).respond ok

allow_post = (response) ->
  if response?
    http_backend().expectPOST().respond ok, response
  else
    http_backend().expectPOST().respond ok

fail_post = ->
  http_backend().expectPOST().respond err

flush = ->
  http_backend().flush()

assert_unwrapped_data = (actual_data, expected_data) ->
  result =
    pass: actual_data is expected_data
    message: ->
      "Expected response data `#{actual_data}` to equal to `#{expected_data}`. Seems that response was not properly unwrapped."

############
# matchers #
############

to_get = ->
  compare: (fn, uri) ->
    # validations
    validate_arguments_count arguments, 2, 'to_get takes a single uri argument.'
    expect_to_be_function fn

    # expect http call
    expect_get uri

    # make the call
    fn()

    # flush & assert
{'fraction_non_alphanumeric': 0.15665399239543726, 'fraction_numerical': 0.003548795944233207, 'mean_word_length': 3.9510664993726476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '6301870', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1231, 'n_words': 306}