<commit_before># frozen_string_literal: true

require 'spec_helper'

describe Spree::OrderMailer do
  include OpenFoodNetwork::EmailHelper

  context "basic behaviour" do
    let(:order) { build(:order_with_totals_and_distribution) }

    context ":from not set explicitly" do
      it "falls back to spree config" do
        message = Spree::OrderMailer.confirm_email_for_customer(order)
        expect(message.from).to eq [Spree::Config[:mails_from]]
      end
    end

    it "doesn't aggressively escape double quotes in confirmation body" do
      confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order)
      expect(confirmation_email.body).to_not include("&quot;")
    end

    it "confirm_email_for_customer accepts an order id as an alternative to an Order object" do
      expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
      expect {
        Spree::OrderMailer.confirm_email_for_customer(order.id).deliver_now
      }.to_not raise_error
    end

    it "cancel_email accepts an order id as an alternative to an Order object" do
      expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
      expect {
        Spree::OrderMailer.cancel_email(order.id).deliver_now
      }.to_not raise_error
    end
  end
<commit_msg>Rearrange and extend some OrderMailer unit-tests<commit_after># frozen_string_literal: true

require 'spec_helper'

describe Spree::OrderMailer do
  include OpenFoodNetwork::EmailHelper

  describe '#confirm_email_for_customer' do
    subject(:email) { described_class.confirm_email_for_customer(order) }

    let(:order) { build(:order_with_totals_and_distribution) }

    it 'renders the shared/_payment.html.haml partial' do
      expect(email.body).to include(I18n.t(:email_payment_summary))
    end

    context 'when the order has outstanding balance' do
      before { allow(order).to receive(:outstanding_balance) { 123 } }

      it 'renders the amount as money' do
        expect(email.body).to include('$123')
      end
    end

    context 'when the order has no outstanding balance' do
      before { allow(order).to receive(:outstanding_balance) { 0 } }

      it 'displays the payment status' do
        expect(email.body).to include(I18n.t(:email_payment_not_paid))
      end
    end

    context "when :from is not set explicitly" do
      it "falls back to spree config" do
        expect(email.from).to eq [Spree::Config[:mails_from]]
      end
    end

    it "doesn't aggressively escape double quotes body" do
      expect(email.body).to_not include("&quot;")
    end

    it "accepts an order id as an alternative to an Order object" do
      expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
      expect {
        described_class.confirm_email_for_customer(order.id).deliver_now
      }.to_not raise_error
    end
  end

  describe '#confirm_email_for_shop' do
    subject(:email) { described_class.confirm_email_for_shop(order) }

    let(:order) { build(:order_with_totals_and_distribution) }

    it 'renders the shared/_payment.html.haml partial' do
      expect(email.body).to include(I18n.t(:email_payment_summary))
    end

    context 'when the order has outstanding balance' do
      before { allow(order).to receive(:outstanding_balance) { 123 } }

      it 'renders the amount as money' do
        expect(email.body).to include('$123')
      end
    end

    context 'when the order has no outstanding balance' do
      before { allow(order).to receive(:outstanding_balance) { 0 } }

      it 'displays the payment status' do
        expect(email.body).to include(I18n.t(:email_payment_not_paid))
      end
    end
  end

  context "basic behaviour" do
    let(:order) { build(:order_with_totals_and_distribution) }

    it "cancel_email accepts an order id as an alternative to an Order object" do
      expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
      expect {
        Spree::OrderMailer.cancel_email(order.id).deliver_now
      }.to_not raise_error
    end
  end

{'fraction_non_alphanumeric': 0.09423695275785308, 'fraction_numerical': 0.005441503833786792, 'mean_word_length': 3.5438202247191013, 'pattern_counts': {'":': 1, '<': 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': '2994477', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1199, 'n_words': 314}