<commit_before>require "rails_helper"

describe FormAnswerDecorator do
  DOCUMENT_FIELDS = {
    nominee_organisation: "organization_address_name",
    nominee_position: "nominee_position",
    nominee_building: "nominee_personal_address_building",
    nominee_street: "nominee_personal_address_street",
    nominee_city: "nominee_personal_address_city",
    nominee_county: "nominee_personal_address_county",
    nominee_postcode: "nominee_personal_address_postcode",
    nominee_telephone: "nominee_phone",
    nominee_email: "nominee_email",
    nominee_region: "nominee_personal_address_region",
    nominator_building: "personal_address_building",
    nominator_street: "personal_address_street",
    nominator_city: "personal_address_city",
    nominator_county: "personal_address_county",
    nominator_postcode: "personal_address_postcode",
    nominator_telephone: "personal_phone",
    nominator_email: "personal_email",
    registration_number: "registration_number",
    website_url: "website_url",
    head_of_bussines_title: "head_of_bussines_title",
    head_of_business_honours: "head_of_business_honours",
    head_job_title: "head_job_title",
    head_email: "head_email",
    applying_for: "applying_for",
    parent_company: "parent_company",
    parent_company_country: "parent_company_country",
    parent_ultimate_control: "parent_ultimate_control",
    ultimate_control_company: "ultimate_control_company",
    ultimate_control_company_country: "ultimate_control_company_country",
    innovation_desc_short: "innovation_desc_short",
    development_desc_short: "development_desc_short",
    development_management_approach_briefly: "development_management_approach_briefly",
    mobility_desc_short: "mobility_desc_short",
    organisation_type: "organisation_type"
  }

  let(:user) { build_stubbed(:user, first_name: "John", last_name: "Doe") }

  describe "#average_growth_for" do
    subject { described_class.new form_answer }
    let!(:form_answer) { build(:form_answer, document: { sic_code: sic_code.code }) }
    let(:year) { 1 }

    context "sic code present" do
      let(:sic_code) { SICCode.first }
      it "returns average growth for specific year" do
        expect(subject.average_growth_for(year)).to eq(sic_code.by_year(year))
      end
    end

    context "sic code not present" do
      let(:sic_code) { double(code: nil) }
      it "returns nil" do
        expect(subject.average_growth_for(year)).to be_nil
      end
    end
  end

  describe "#last_state_updated_by" do
    it "Returns the person and time of who made the last transition" do

      Timecop.freeze(DateTime.new(Date.current.year, 2, 6, 8, 30)) do
        form_answer = create(:form_answer).decorate
        form_answer.state_machine.submit(form_answer.user)
        expect(form_answer.last_state_updated_by).to eq("Updated by <NAME> -  6 Feb #{Date.current.year} at 8:30am")
      end
    end
  end

  describe "#feedback_updated_by" do
    it "Returns the person and time of who made the feedback" do
      Timecop.freeze(DateTime.new(Date.current.year, 2, 6, 8, 30)) do
        form_answer = create(:feedback, authorable: user).form_answer.decorate
        expect(form_answer.feedback_updated_by).to eq("Updated by: <NAME> -  6 Feb #{Date.current.year} at 8:30am")
      end
    end
  end

  describe "#press_summary" do
    it "Returns the person and time of who made the last transition" do
      Timecop.freeze(DateTime.new(Date.current.year, 2, 6, 8, 30)) do
        form_answer = create(:press_summary, authorable: user).form_answer.decorate
        expect(form_answer.press_summary_updated_by).to eq("Updated by <NAME> -  6 Feb #{Date.current.year} at 8:30am")
      end
    end
  end

  describe "#dashboard_status" do
    it "returns fill progress when application is not submitted" do
     form_answer = create(:form_answer, :trade, state: "application_in_progress", document: { sic_code:  SICCode.first.code })
      expect(described_class.new(form_answer).dashboard_status).to eq("Application in progress...9%")
    end

    it "warns that assessors are not assigned if assessment is in progress and assessors are not assigned yet for admin section" do
      form_answer = create(:form_answer, :trade, :submitted, state: "assessment_in_progress")<commit_msg>adapt tests to new required fields for IT<commit_after>require "rails_helper"

describe FormAnswerDecorator do
  DOCUMENT_FIELDS = {
    nominee_organisation: "organization_address_name",
    nominee_position: "nominee_position",
    nominee_building: "nominee_personal_address_building",
    nominee_street: "nominee_personal_address_street",
    nominee_city: "nominee_personal_address_city",
    nominee_county: "nominee_personal_address_county",
    nominee_postcode: "nominee_personal_address_postcode",
    nominee_telephone: "nominee_phone",
    nominee_email: "nominee_email",
    nominee_region: "nominee_personal_address_region",
    nominator_building: "personal_address_building",
    nominator_street: "personal_address_street",
    nominator_city: "personal_address_city",
    nominator_county: "personal_address_county",
    nominator_postcode: "personal_address_postcode",
    nominator_telephone: "personal_phone",
    nominator_email: "personal_email",
    registration_number: "registration_number",
    website_url: "website_url",
    head_of_bussines_title: "head_of_bussines_title",
    head_of_business_honours: "head_of_business_honours",
    head_job_title: "head_job_title",
    head_email: "head_email",
    applying_for: "applying_for",
    parent_company: "parent_company",
    parent_company_country: "parent_company_country",
    parent_ultimate_control: "parent_ultimate_control",
    ultimate_control_company: "ultimate_control_company",
    ultimate_control_company_country: "ultimate_control_company_country",
    innovation_desc_short: "innovation_desc_short",
    development_desc_short: "development_desc_short",
    development_management_approach_briefly: "development_management_approach_briefly",
    mobility_desc_short: "mobility_desc_short",
    organisation_type: "organisation_type"
  }

  let(:user) { build_stubbed(:user, first_name: "John", last_name: "Doe") }

  describe "#average_growth_for" do
    subject { described_class.new form_answer }
    let!(:form_answer) { build(:form_answer, document: { sic_code: sic_code.code }) }
    let(:year) { 1 }

    context "sic code present" do
      let(:sic_code) { SICCode.first }
      it "returns average growth for specific year" do
        expect(subject.average_growth_for(year)).to eq(sic_code.by_year(year))
      end
    end

    context "sic code not present" do
      let(:sic_code) { double(code: nil) }
      it "returns nil" do
        expect(subject.average_growth_for(year)).to be_nil
      end
    end
  end

  describe "#last_state_updated_by" do
    it "Returns the person and time of who made the last transition" do

      Timecop.freeze(DateTime.new(Date.current.year, 2, 6, 8, 30)) do
        form_answer = create(:form_answer).decorate
        form_answer.state_machine.submit(form_answer.user)
        expect(form_answer.last_state_updated_by).to eq("Updated by <NAME> -  6 Feb #{Date.current.year} at 8:30am")
      end
    end
  end

  describe "#feedback_updated_by" do
    it "Returns the person and time of who made the feedback" do
      Timecop.freeze(DateTime.new(Date.current.year, 2, 6, 8, 30)) do
        form_answer = create(:feedback, authorable: user).form_answer.decorate
        expect(form_answer.feedback_updated_by).to eq("Updated by: <NAME> -  6 Feb #{Date.current.year} at 8:30am")
      end
    end
  end

  describe "#press_summary" do
    it "Returns the person and time of who made the last transition" do
      Timecop.freeze(DateTime.new(Date.current.year, 2, 6, 8, 30)) do
        form_answer = create(:press_summary, authorable: user).form_answer.decorate
        expect(form_answer.press_summary_updated_by).to eq("Updated by <NAME> -  6 Feb #{Date.current.year} at 8:30am")
      end
    end
  end

  describe "#dashboard_status" do
    it "returns fill progress when application is not submitted" do
     form_answer = create(:form_answer, :trade, state: "application_in_progress", document: { sic_code:  SICCode.first.code })
      expect(described_class.new(form_answer).dashboard_status).to eq("Application in progress...10%")
    end

    it "warns that assessors are not assigned if assessment is in progress and assessors are not assigned yet for admin section" do
      form_answer = create(:form_answer, :trade, :submitted, state: "assessment_in_progress")
{'fraction_non_alphanumeric': 0.09392072532837382, 'fraction_numerical': 0.006858072765314425, 'mean_word_length': 4.536679536679537, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2468', 'n_tokens_mistral': 2830, 'n_tokens_neox': 2695, 'n_words': 598}