<commit_before># frozen_string_literal: true

require 'system_helper'

describe '
    As an administrator
    I want to create/update complex order cycles with a specific time
', js: true do
  include AdminHelper
  include AuthenticationHelper
  include WebHelper

  let(:order_cycle_opening_time) { 1.day.from_now(Time.zone.now) }
  let(:order_cycle_closing_time) { 2.days.from_now(Time.zone.now) }

  # Given coordinating, supplying and distributing enterprises with some products with variants
  let!(:coordinator) { create(:distributor_enterprise, name: 'My coordinator') }
  let!(:supplier) { create(:supplier_enterprise, name: 'My supplier') }
  let!(:product) { create(:product, supplier: supplier) }
  let!(:v1) { create(:variant, product: product) }
  let!(:v2) { create(:variant, product: product) }
  let!(:distributor) {
    create(:distributor_enterprise, name: 'My distributor', with_payment_and_shipping: true)
  }
  let!(:payment_method_i) { distributor.payment_methods.first }
  let!(:payment_method_ii) { create(:payment_method, distributors: [distributor]) }
  let!(:shipping_method_i) { distributor.shipping_methods.first }
  let!(:shipping_method_ii) { create(:shipping_method, distributors: [distributor]) }
  let(:oc) { OrderCycle.last }

  # And some enterprise fees
  let!(:supplier_fee) { create(:enterprise_fee, enterprise: supplier, name: 'Supplier fee') }
  let!(:coordinator_fee) { create(:enterprise_fee, enterprise: coordinator, name: 'Coord fee') }
  let!(:distributor_fee) do
    create(:enterprise_fee, enterprise: distributor, name: 'Distributor fee')
  end

  before do
    # Relationships required for interface to work
    create(:enterprise_relationship, parent: supplier, child: coordinator,
                                     permissions_list: [:add_to_order_cycle])
    create(:enterprise_relationship, parent: distributor, child: coordinator,
                                     permissions_list: [:add_to_order_cycle])
    create(:enterprise_relationship, parent: supplier, child: distributor,
                                     permissions_list: [:add_to_order_cycle])

    shipping_method_i.update!(name: "Pickup - always available")
    shipping_method_ii.update!(name: "Delivery - sometimes available")
    payment_method_ii.update!(name: "Cash")
  end

  it "creating an order cycle with full interface", js: true do
    ## CREATE
    login_as_admin_and_visit admin_order_cycles_path
    click_link 'New Order Cycle'

    # Select a coordinator since there are two available
    select2_select 'My coordinator', from: 'coordinator_id'<commit_msg>Adds retry: 3 to flaky example<commit_after># frozen_string_literal: true

require 'system_helper'

describe '
    As an administrator
    I want to create/update complex order cycles with a specific time
' do
  include AdminHelper
  include AuthenticationHelper
  include WebHelper

  let(:order_cycle_opening_time) { 1.day.from_now(Time.zone.now) }
  let(:order_cycle_closing_time) { 2.days.from_now(Time.zone.now) }

  # Given coordinating, supplying and distributing enterprises with some products with variants
  let!(:coordinator) { create(:distributor_enterprise, name: 'My coordinator') }
  let!(:supplier) { create(:supplier_enterprise, name: 'My supplier') }
  let!(:product) { create(:product, supplier: supplier) }
  let!(:v1) { create(:variant, product: product) }
  let!(:v2) { create(:variant, product: product) }
  let!(:distributor) {
    create(:distributor_enterprise, name: 'My distributor', with_payment_and_shipping: true)
  }
  let!(:payment_method_i) { distributor.payment_methods.first }
  let!(:payment_method_ii) { create(:payment_method, distributors: [distributor]) }
  let!(:shipping_method_i) { distributor.shipping_methods.first }
  let!(:shipping_method_ii) { create(:shipping_method, distributors: [distributor]) }
  let(:oc) { OrderCycle.last }

  # And some enterprise fees
  let!(:supplier_fee) { create(:enterprise_fee, enterprise: supplier, name: 'Supplier fee') }
  let!(:coordinator_fee) { create(:enterprise_fee, enterprise: coordinator, name: 'Coord fee') }
  let!(:distributor_fee) do
    create(:enterprise_fee, enterprise: distributor, name: 'Distributor fee')
  end

  before do
    # Relationships required for interface to work
    create(:enterprise_relationship, parent: supplier, child: coordinator,
                                     permissions_list: [:add_to_order_cycle])
    create(:enterprise_relationship, parent: distributor, child: coordinator,
                                     permissions_list: [:add_to_order_cycle])
    create(:enterprise_relationship, parent: supplier, child: distributor,
                                     permissions_list: [:add_to_order_cycle])

    shipping_method_i.update!(name: "Pickup - always available")
    shipping_method_ii.update!(name: "Delivery - sometimes available")
    payment_method_ii.update!(name: "Cash")
  end

  it "creating an order cycle with full interface", retry: 3 do
    ## CREATE
    login_as_admin_and_visit admin_order_cycles_path
    click_link 'New Order Cycle'

    # Select a coordinator since there are two available
    select2_select 'My coordinator', from: 'coordinator_id'
{'fraction_non_alphanumeric': 0.10616241121136495, 'fraction_numerical': 0.002303705125743905, 'mean_word_length': 4.427083333333333, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4333849', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1495, 'n_words': 372}