<commit_before># frozen_string_literal: true

require 'spec_helper'

describe Api::OrderSerializer do
  let(:serializer) { Api::OrderSerializer.new order }
  let(:order) { create(:completed_order_with_totals) }

  let!(:completed_payment) { create(:payment, order: order, state: 'completed', amount: order.total - 1) }
  let!(:payment) { create(:payment, order: order, state: 'checkout', amount: 123.45) }

  it "serializes an order" do
    expect(serializer.to_json).to match order.number.to_s
  end

  it "convert the state attributes to translatable keys" do
    # byebug if serializer.to_json =~ /balance_due/
    expect(serializer.to_json).to match "complete"
    expect(serializer.to_json).to match "balance_due"
  end

  it "only serializes completed payments" do
    expect(serializer.to_json).to match completed_payment.amount.to_s
    expect(serializer.to_json).to_not match payment.amount.to_s
  end

  describe '#outstanding_balance' do
    context 'when the customer_balance feature is enabled' do
      before do
        allow(OpenFoodNetwork::FeatureToggle)
          .to receive(:enabled?).with(:customer_balance, order.user) { true }

        allow(order).to receive(:balance_value).and_return(-1.23)
      end

      it "returns the object's balance_value from the users perspective" do
        expect(serializer.serializable_hash[:outstanding_balance]).to eq(1.23)
      end
    end

    context 'when the customer_balance is not enabled' do
      before do
        allow(OpenFoodNetwork::FeatureToggle)
          .to receive(:enabled?).with(:customer_balance, order.user) { false }
      end

      it 'calls #outstanding_balance on the object' do
        expect(serializer.serializable_hash[:outstanding_balance]).to eq(1.0)
      end
    end
  end
end<commit_msg>Remove old commented out code<commit_after># frozen_string_literal: true

require 'spec_helper'

describe Api::OrderSerializer do
  let(:serializer) { Api::OrderSerializer.new order }
  let(:order) { create(:completed_order_with_totals) }

  let!(:completed_payment) { create(:payment, order: order, state: 'completed', amount: order.total - 1) }
  let!(:payment) { create(:payment, order: order, state: 'checkout', amount: 123.45) }

  it "serializes an order" do
    expect(serializer.to_json).to match order.number.to_s
  end

  it "convert the state attributes to translatable keys" do
    expect(serializer.to_json).to match "complete"
    expect(serializer.to_json).to match "balance_due"
  end

  it "only serializes completed payments" do
    expect(serializer.to_json).to match completed_payment.amount.to_s
    expect(serializer.to_json).to_not match payment.amount.to_s
  end

  describe '#outstanding_balance' do
    context 'when the customer_balance feature is enabled' do
      before do
        allow(OpenFoodNetwork::FeatureToggle)
          .to receive(:enabled?).with(:customer_balance, order.user) { true }

        allow(order).to receive(:balance_value).and_return(-1.23)
      end

      it "returns the object's balance_value from the users perspective" do
        expect(serializer.serializable_hash[:outstanding_balance]).to eq(1.23)
      end
    end

    context 'when the customer_balance is not enabled' do
      before do
        allow(OpenFoodNetwork::FeatureToggle)
          .to receive(:enabled?).with(:customer_balance, order.user) { false }

        allow(order).to receive(:outstanding_balance).and_return(123.0)
      end

      it 'calls #outstanding_balance on the object' do
        expect(serializer.serializable_hash[:outstanding_balance]).to eq(123.0)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10196730396231643, 'fraction_numerical': 0.00942089221390967, 'mean_word_length': 3.8133333333333335, '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': '6951411', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1060, 'n_words': 273}