<commit_before>require File.expand_path('../../../../test_helper', __FILE__)

class RedmineUndevGit::Services::GitlabTest < ActiveSupport::TestCase

  def test_git_urls_from_request
    RedmineUndevGit::Services::Gitlab.any_instance.stubs(:web_hook).returns(
        gitlab_payload('<EMAIL>:path_to/diaspora.git')
    )
    service = RedmineUndevGit::Services::Gitlab.new(nil)
    urls = service.all_urls
    assert_include '<EMAIL>:path_to/diaspora.git', urls
    assert_include 'https://example.com/path_to/diaspora.git', urls
    assert_include 'git://example.com/path_to/diaspora.git', urls
  end

  def test_assert_service_error_on_wrong_url
    assert_raise RedmineUndevGit::Services::WrongRepoUrl do
      RedmineUndevGit::Services::Gitlab.any_instance.stubs(:web_hook).returns(
          gitlab_payload('git<EMAIL>/path_to/diaspora.git')
      )
      RedmineUndevGit::Services::Gitlab.new(nil).all_urls
    end
  end

  def gitlab_payload(repo_url = '<EMAIL>:diaspora.git')
    HashWithIndifferentAccess.new(
        before: '95790bf891e76fee5e1747ab589903a6a1f80f22',<commit_msg>micro fix to tests<commit_after>require File.expand_path('../../../../test_helper', __FILE__)

class RedmineUndevGit::Services::GitlabTest < ActiveSupport::TestCase

  def test_git_urls_from_request
    RedmineUndevGit::Services::Gitlab.any_instance.stubs(:web_hook).returns(
        gitlab_payload('<EMAIL>:path_to/diaspora.git')
    )
    service = RedmineUndevGit::Services::Gitlab.new(nil)
    urls = service.send :all_urls
    assert_include '<EMAIL>:path_to/diaspora.git', urls
    assert_include 'https://example.com/path_to/diaspora.git', urls
    assert_include 'git://example.com/path_to/diaspora.git', urls
  end

  def test_assert_service_error_on_wrong_url
    assert_raise RedmineUndevGit::Services::WrongRepoUrl do
      RedmineUndevGit::Services::Gitlab.any_instance.stubs(:web_hook).returns(
          gitlab_payload('git@example.com/path_to/diaspora.git')
      )
      RedmineUndevGit::Services::Gitlab.new(nil).send :all_urls
    end
  end

  def gitlab_payload(repo_url = '<EMAIL>:diaspora.git')
    HashWithIndifferentAccess.new(
        before: '95790bf891e76fee5e1747ab589903a6a1f80f22',
{'fraction_non_alphanumeric': 0.12363636363636364, 'fraction_numerical': 0.024545454545454544, 'mean_word_length': 4.776902887139108, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3516193', 'n_tokens_mistral': 832, 'n_tokens_neox': 770, 'n_words': 84}