<commit_before>require "test_helper"

require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures"

class ProjectClientTest < ActiveSupport::TestCase

  def setup
    @port = mock
    Kalibro::Client::Port.expects(:new).with('Project').returns(@port)
    @project = ProjectFixtures.qt_calculator
  end

  should 'get project by name' do
    request_body = {:project_name => @project.name}
    response_hash = {:project => @project.to_hash}
    @port.expects(:request).with(:get_project, request_body).returns(response_hash)
    assert_equal @project, Kalibro::Client::ProjectClient.project(@project.name)
  end
  
  should 'raise error when project doesnt exist' do
    request_body = {:project_name => @project.name}
    @port.expects(:request).with(:get_project, request_body)
      .raises(Exception.new("(S:Server) There is no project named " + @project.name))
    assert_nil Kalibro::Client::ProjectClient.project(@project.name)
  end

  should 'save project' do
    create_project_content_mock
    @project.state = nil
    @port.expects(:request).with(:save_project, {:project => @project.to_hash})
    Kalibro::Client::ProjectClient.save(@project_content)
  end

  should 'remove existent project from service' do
    @port.expects(:request).with(:get_project_names).returns({:project_name => @project.name})
    @port.expects(:request).with(:remove_project, {:project_name => @project.name})
    Kalibro::Client::ProjectClient.remove(@project.name)
  end

  should 'not try to remove inexistent project from service' do
    @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'})
    @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never
    Kalibro::Client::ProjectClient.remove(@project.name)
  end

  private

  def create_project_content_mock
    @project_content = mock
    @project_content.expects(:name).returns(@project.name)
    @project_content.expects(:license).returns(@project.license)
    @project_content.expects(:description).returns(@project.description)
    @project_content.expects(:repository_type).returns(@project.repository.type)<commit_msg>[Mezuro] fixed sintax error on project client test<commit_after>require "test_helper"

require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures"

class ProjectClientTest < ActiveSupport::TestCase

  def setup
    @port = mock
    Kalibro::Client::Port.expects(:new).with('Project').returns(@port)
    @project = ProjectFixtures.qt_calculator
  end

  should 'get project by name' do
    request_body = {:project_name => @project.name}
    response_hash = {:project => @project.to_hash}
    @port.expects(:request).with(:get_project, request_body).returns(response_hash)
    assert_equal @project, Kalibro::Client::ProjectClient.project(@project.name)
  end
  
  should 'raise error when project doesnt exist' do
    request_body = {:project_name => @project.name}
    @port.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name))
    assert_nil Kalibro::Client::ProjectClient.project(@project.name)
  end

  should 'save project' do
    create_project_content_mock
    @project.state = nil
    @port.expects(:request).with(:save_project, {:project => @project.to_hash})
    Kalibro::Client::ProjectClient.save(@project_content)
  end

  should 'remove existent project from service' do
    @port.expects(:request).with(:get_project_names).returns({:project_name => @project.name})
    @port.expects(:request).with(:remove_project, {:project_name => @project.name})
    Kalibro::Client::ProjectClient.remove(@project.name)
  end

  should 'not try to remove inexistent project from service' do
    @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'})
    @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never
    Kalibro::Client::ProjectClient.remove(@project.name)
  end

  private

  def create_project_content_mock
    @project_content = mock
    @project_content.expects(:name).returns(@project.name)
    @project_content.expects(:license).returns(@project.license)
    @project_content.expects(:description).returns(@project.description)
    @project_content.expects(:repository_type).returns(@project.repository.type)
{'fraction_non_alphanumeric': 0.1355463347164592, 'fraction_numerical': 0.0, 'mean_word_length': 5.524812030075188, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '7149558', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1294, 'n_words': 223}