<commit_before>require "rails_helper"
require 'features/user_and_organisations'

feature "Add dataset page", type: :feature, vcr: { :match_requests_on => [:host, :method] } do
  include_context 'user and organisations'

  let(:data_file) {File.join(Rails.root, 'spec', 'fixtures', 'valid-schema.csv') }

  before(:each) do
    @user = create(:user)
    OmniAuth.config.mock_auth[:github]
    sign_in @user
    allow_any_instance_of(User).to receive(:organizations) { organizations }
    allow_any_instance_of(User).to receive(:github_user) { github_user }
    allow_any_instance_of(DatasetFileSchemaService).to receive(:read_file_with_utf_8).and_return(read_fixture_schema_file('good-schema.json'))
  end



  

  context "logged in visitors has no schemas" do
    scenario "and can add a dataset file schema on it's own" do
      visit root_path

      click_link 'List my dataset file schemas'
      expect(page).to have_content 'You currently have no dataset file schemas, why not add one?'
      click_link 'Add a new dataset file schema'
      common_name = 'Fri1437'

      before_datasets = DatasetFileSchema.count

      within 'form' do
        fill_in 'dataset_file_schema_name', with: "#{common_name}-schema-name"
        fill_in 'dataset_file_schema_description', with: "#{common_name}-schema-description"
        attach_file('dataset_file_schema_url_in_s3', data_file)

        click_on 'Submit'
      end<commit_msg>Start working on feature test<commit_after>require "rails_helper"
require 'features/user_and_organisations'

feature "Add dataset page", type: :feature, vcr: { :match_requests_on => [:host, :method] } do
  include_context 'user and organisations'

  let(:data_file) { get_fixture_schema_file('valid-schema.csv') }

  before(:each) do
    @user = create(:user)
    OmniAuth.config.mock_auth[:github]
    sign_in @user
    allow_any_instance_of(User).to receive(:organizations) { organizations }
    allow_any_instance_of(User).to receive(:github_user) { github_user }
    allow_any_instance_of(DatasetFileSchemaService).to receive(:read_file_with_utf_8).and_return(read_fixture_schema_file('good-schema.json'))
  end

  context "logged in visitors has no schemas" do
    scenario "and can infer a dataset file schema from a data file" do
      visit root_path

      click_link 'List my dataset file schemas'
      expect(page).to have_content 'You currently have no dataset file schemas, why not add one?'
      click_link 'Infer a new dataset file schema'
      common_name = 'Fri1437'

      before_datasets = DatasetFileSchema.count

      within 'form' do
        fill_in 'dataset_file_schema_name', with: "#{common_name}-schema-name"
        fill_in 'dataset_file_schema_description', with: "#{common_name}-schema-description"
        attach_file('dataset_file_schema_url_in_s3', data_file)

        click_on 'Submit'
      end
{'fraction_non_alphanumeric': 0.09713487071977638, 'fraction_numerical': 0.0041928721174004195, 'mean_word_length': 4.361423220973783, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3825672', 'n_tokens_mistral': 908, 'n_tokens_neox': 881, 'n_words': 217}