<commit_before>require 'test_helper'

class JsonApiClientMockTest < MiniTest::Unit::TestCase

  def teardown
    JsonApiClient::Resource.clear_test_results
    super
  end

  def test_conditionless_mocking
    BarResource.set_test_results([{foo: 'bar', qwer: 'asdf'}])
    results = BarResource.all

    assert_equal(JsonApiClient::ResultSet, results.class)
    assert_equal(1, results.length)

    first = results.first
    assert_equal(BarResource, first.class)
    assert_equal('bar', first.foo)
    assert_equal('asdf', first.qwer)

    conditioned_results = BarResource.where(something: 'else').all
    assert_equal(JsonApiClient::ResultSet, results.class)
    assert_equal(1, conditioned_results.length)

    first = conditioned_results.first
    assert_equal(BarResource, first.class)
    assert_equal('bar', first.foo)
    assert_equal('asdf', first.qwer)
  end

  def test_missing_mock
    assert_raises(JsonApiClientMock::MissingMock) do
      BarResource.all
    end
  end

  def test_conditional_mocking
    BarResource.set_test_results([{foo: 'bar', qwer: 'asdf'}], {foo: 'bar'})
    assert_raises(JsonApiClientMock::MissingMock) do
      BarResource.all
    end

    results = BarResource.where(foo: 'bar').all
    assert_equal(1, results.length)

    first = results.first
    assert_equal(BarResource, first.class)
    assert_equal('bar', first.foo)
    assert_equal('asdf', first.qwer)
  end

  def test_conditional_mocking_param_order<commit_msg>adds request path mocking tests<commit_after>require 'test_helper'

class JsonApiClientMockTest < MiniTest::Unit::TestCase

  def teardown
    JsonApiClient::Resource.clear_test_results
    super
  end

  def test_conditionless_mocking
    BarResource.set_test_results([{foo: 'bar', qwer: 'asdf'}])
    results = BarResource.all

    assert_equal(JsonApiClient::ResultSet, results.class)
    assert_equal(1, results.length)

    first = results.first
    assert_equal(BarResource, first.class)
    assert_equal('bar', first.foo)
    assert_equal('asdf', first.qwer)

    conditioned_results = BarResource.where(something: 'else').all
    assert_equal(JsonApiClient::ResultSet, results.class)
    assert_equal(1, conditioned_results.length)

    first = conditioned_results.first
    assert_equal(BarResource, first.class)
    assert_equal('bar', first.foo)
    assert_equal('asdf', first.qwer)
  end

  def test_missing_mock
    assert_raises(JsonApiClientMock::MissingMock) do
      BarResource.all
    end
  end

  def test_conditional_mocking
    BarResource.set_test_results([{foo: 'bar', qwer: 'asdf'}], {foo: 'bar'})
    assert_raises(JsonApiClientMock::MissingMock) do
      BarResource.all
    end

    results = BarResource.where(foo: 'bar').all
    assert_equal(1, results.length)

    first = results.first
    assert_equal(BarResource, first.class)
    assert_equal('bar', first.foo)
    assert_equal('asdf', first.qwer)
  end

  def test_by_conditional_request_path_mocking
    BarResource.set_test_results([{foo: 'bar', qwer: 'asdf'}], {path: 'bar_resources/10'})
    assert_raises(JsonApiClientMock::MissingMock) do
      BarResource.all
    end

    results = BarResource.find(10)
    assert_equal(1, results.length)

    first = results.first
    assert_equal(BarResource, first.class)
    assert_equal('bar', first.foo)
    assert_equal('asdf', first.qwer)
  end

  def test_conditional_mocking_param_order
{'fraction_non_alphanumeric': 0.10566706021251476, 'fraction_numerical': 0.003246753246753247, 'mean_word_length': 4.413738019169329, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '649394', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1077, 'n_words': 190}