<commit_before>require 'rails_helper'

RSpec.describe BookingRequestCreator do
  let(:prisoner_step) {
    PrisonerStep.new(
      prison_id: 1,
      first_name: 'Oscar',
      last_name: 'Wilde',
      date_of_birth: Date.new(1980, 12, 31),
      number: 'a1234bc'
    )
  }

  let(:visitors_step) {
    VisitorsStep.new(
      first_name: 'Ada',
      last_name: 'Lovelace',
      date_of_birth: Date.new(1970, 11, 30),
      email_address: '<EMAIL>',
      phone_no: '01154960222'
    )
  }

  let(:slots_step) {
    SlotsStep.new(
      option_1: '2015-01-02T09:00/10:00',
      option_2: '2015-01-03T09:00/10:00',
      option_3: '2015-01-04T09:00/10:00'
    )
  }

  let(:mailing) {
    double(Mail::Message, deliver_later: nil)
  }

  before do
    allow(PrisonMailer).to receive(:request_received).and_return(mailing)
  end

  it 'creates a Visit record' do
    expect(Visit).
      to receive(:create!).
      with(
        prison_id: 1,
        prisoner_first_name: 'Oscar',
        prisoner_last_name: 'Wilde',
        prisoner_date_of_birth: Date.new(1980, 12, 31),
        prisoner_number: 'a1234bc',
        visitor_first_name: 'Ada',
        visitor_last_name: 'Lovelace',
        visitor_date_of_birth: Date.new(1970, 11, 30),
        visitor_email_address: '<EMAIL>',
        visitor_phone_no: '01154960222',
        slot_option_1: '2015-01-02T09:00/10:00',
        slot_option_2: '2015-01-03T09:00/10:00',
        slot_option_3: '2015-01-04T09:00/10:00'
      ).and_return double(Visit, id: 2)

    described_class.new.create! prisoner_step, visitors_step, slots_step
  end

  it 'emails the prison' do
    visit = double(Visit, id: 2)
    allow(Visit).to receive(:create!).and_return(visit)
    expect(PrisonMailer).to receive(:request_received).with(visit).
      and_return(mailing)
    expect(mailing).to receive(:deliver_later)

    described_class.new.create! prisoner_step, visitors_step, slots_step
  end
end<commit_msg>Add spec that logs visit id<commit_after>require 'rails_helper'

RSpec.describe BookingRequestCreator do
  let(:prisoner_step) {
    PrisonerStep.new(
      prison_id: 1,
      first_name: 'Oscar',
      last_name: 'Wilde',
      date_of_birth: Date.new(1980, 12, 31),
      number: 'a1234bc'
    )
  }

  let(:visitors_step) {
    VisitorsStep.new(
      first_name: 'Ada',
      last_name: 'Lovelace',
      date_of_birth: Date.new(1970, 11, 30),
      email_address: '<EMAIL>',
      phone_no: '01154960222'
    )
  }

  let(:slots_step) {
    SlotsStep.new(
      option_1: '2015-01-02T09:00/10:00',
      option_2: '2015-01-03T09:00/10:00',
      option_3: '2015-01-04T09:00/10:00'
    )
  }

  let(:mailing) {
    double(Mail::Message, deliver_later: nil)
  }

  before do
    allow(PrisonMailer).to receive(:request_received).and_return(mailing)
  end

  it 'creates a Visit record' do
    expect(Visit).
      to receive(:create!).
      with(
        prison_id: 1,
        prisoner_first_name: 'Oscar',
        prisoner_last_name: 'Wilde',
        prisoner_date_of_birth: Date.new(1980, 12, 31),
        prisoner_number: 'a1234bc',
        visitor_first_name: 'Ada',
        visitor_last_name: 'Lovelace',
        visitor_date_of_birth: Date.new(1970, 11, 30),
        visitor_email_address: '<EMAIL>',
        visitor_phone_no: '01154960222',
        slot_option_1: '2015-01-02T09:00/10:00',
        slot_option_2: '2015-01-03T09:00/10:00',
        slot_option_3: '2015-01-04T09:00/10:00'
      ).and_return double(Visit, id: 2)

    described_class.new.create! prisoner_step, visitors_step, slots_step
  end

  it 'emails the prison' do
    visit = double(Visit, id: 2)
    allow(Visit).to receive(:create!).and_return(visit)
    expect(PrisonMailer).to receive(:request_received).with(visit).
      and_return(mailing)
    expect(mailing).to receive(:deliver_later)

    described_class.new.create! prisoner_step, visitors_step, slots_step
  end

  it 'logs the visit id' do
    visit = double(Visit, id: 2)
    allow(Visit).to receive(:create!).and_return(visit)

    expect(LogStasher.request_context).to match(visit_id: 2)

    described_class.new.create! prisoner_step, visitors_step, slots_step
  end
end
{'fraction_non_alphanumeric': 0.1288387715930902, 'fraction_numerical': 0.08109404990403071, 'mean_word_length': 3.1359126984126986, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3622341', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1530, 'n_words': 266}