<commit_before># frozen_string_literal: true

require "rails_helper"

describe CharacterBlueprintsImporter do
  let(:character_id) { double }

  let(:page) { double }

  subject { described_class.new(character_id, page) }

  it { should be_a(CharacterBaseImporter) }

  describe "#initialize" do
    context "when page not present" do
      subject { described_class.new(character_id) }

      its(:character_id) { should eq(character_id) }

      its(:page) { should eq(1) }
    end

    context "when page is present" do
      its(:character_id) { should eq(character_id) }

      its(:page) { should eq(page) }
    end
  end

  describe "#update!" do
    # TODO: write
  end

  # private methods

  describe "#import_other_pages" do
    context "when page is more than 1" do
      let(:page) { 2 }

      let(:total_pages) { 2 }

      before { expect(CharacterBlueprintsJob).not_to receive(:perform_later) }

      specify { expect { subject.send(:import_other_pages, total_pages) }.not_to raise_error }
    end

    context "when total pages is 1" do
      let(:page) { 1 }

      let(:total_pages) { 1 }

      before { expect(CharacterBlueprintsJob).not_to receive(:perform_later) }

      specify { expect { subject.send(:import_other_pages, total_pages) }.not_to raise_error }
    end

    context "when page is 1 and total pages more than 1" do
      let(:page) { 1 }<commit_msg>More specs<commit_after># frozen_string_literal: true

require "rails_helper"

describe CharacterBlueprintsImporter do
  let(:character_id) { double }

  let(:page) { double }

  subject { described_class.new(character_id, page) }

  it { should be_a(CharacterBaseImporter) }

  describe "#initialize" do
    context "when page not present" do
      subject { described_class.new(character_id) }

      its(:character_id) { should eq(character_id) }

      its(:page) { should eq(1) }
    end

    context "when page is present" do
      its(:character_id) { should eq(character_id) }

      its(:page) { should eq(page) }
    end
  end

  describe "#update!" do
    # context "when scope present" do
    #   before { expect(subject).to receive(:refresh_character_access_token) }
    #
    #   let(:access_token) { double }
    #
    #   let(:character) do
    #     instance_double(Character,
    #                     character_id: character_id,
    #                     access_token: access_token,
    #                     scopes: "esi-killmails.read_killmails.v1")
    #   end
    #
    #   before { expect(subject).to receive(:character).and_return(character).exactly(4).times }
    #
    #   let(:json) { double }
    #
    #   let(:killmail) { instance_double(EveOnline::ESI::Models::KillmailShort, as_json: json) }
    #
    #   let(:total_pages) { double }
    #
    #   let(:esi) do
    #     instance_double(EveOnline::ESI::CharacterKillmailsRecent,
    #                     killmails: [killmail],
    #                     scope: "esi-killmails.read_killmails.v1",
    #                     total_pages: total_pages)
    #   end
    #
    #   before { expect(EveOnline::ESI::CharacterKillmailsRecent).to receive(:new).with(character_id: character_id, token: access_token, page: page).and_return(esi) }
    #
    #   before do
    #     #
    #     # character.character_killmails.find_or_create_by!(killmail.as_json)
    #     #
    #     expect(character).to receive(:character_killmails) do
    #       double.tap do |a|
    #         expect(a).to receive(:find_or_create_by!).with(json)
    #       end
    #     end
    #   end
    #
    #   before { expect(subject).to receive(:import_other_pages).with(total_pages) }
    #
    #   specify { expect { subject.update! }.not_to raise_error }
    # end

    context "when scope not present" do
      before { expect(subject).to receive(:refresh_character_access_token) }

      let(:access_token) { double }

      let(:character) do
        instance_double(Character,
          character_id: character_id,
          access_token: access_token,
          scopes: "")
      end

      before { expect(subject).to receive(:character).and_return(character).exactly(3).times }

      let(:esi) do
        instance_double(EveOnline::ESI::CharacterBlueprints,
          scope: "esi-characters.read_blueprints.v1")
      end

      before { expect(EveOnline::ESI::CharacterBlueprints).to receive(:new).with(character_id: character_id, token: access_token, page: page).and_return(esi) }

      before { expect(character).not_to receive(:character_blueprints) }

      before { expect(subject).not_to receive(:import_other_pages) }

      specify { expect { subject.update! }.not_to raise_error }
    end
  end

  # private methods

  describe "#import_other_pages" do
    context "when page is more than 1" do
      let(:page) { 2 }

      let(:total_pages) { 2 }

      before { expect(CharacterBlueprintsJob).not_to receive(:perform_later) }

      specify { expect { subject.send(:import_other_pages, total_pages) }.not_to raise_error }
    end

    context "when total pages is 1" do
      let(:page) { 1 }

      let(:total_pages) { 1 }

      before { expect(CharacterBlueprintsJob).not_to receive(:perform_later) }

      specify { expect { subject.send(:import_other_pages, total_pages) }.not_to raise_error }
    end

    context "when page is 1 and total pages more than 1" do
      let(:page) { 1 }
{'fraction_non_alphanumeric': 0.11144297181258167, 'fraction_numerical': 0.004666791114429718, 'mean_word_length': 2.7973068745570515, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3829006', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1633, 'n_words': 356}