<commit_before># frozen_string_literal: true
require 'rails_helper'

describe 'Email Confirmation when signing up to express donations' do
  let!(:member) { create(:member, email: '<EMAIL>') }

  let!(:auth) do
    create(:member_authentication,
           member: member,
           password: 'password',
           confirmed_at: nil,
           token: '<PASSWORD>')
  end

  it 'Confirms user authentication if the token matches the member authentication record' do
    get '/email_confirmation?email=test%40example.com&amp;token=<PASSWORD>'
    Timecop.freeze do
      expect(response.body).to include('You have successfully signed up for express donations')
      expect(member.authentication.confirmed_at).to be_within(1.second).of Time.now
    end
  end

  it 'Logs an error and renders errors if the token and email address do not match' do
    expect(Rails.logger).to receive(:error).with(
      'Token verification failed for email <EMAIL> with token <PASSWORD>.'
    )
    get '/email_confirmation?email=test%40example.com&amp;token=<PASSWORD>'
    expect(response.body).to include(
      'There was an issue signing up for express donations.',
      'Your confirmation token appears to be invalid.'
    )
    expect(member.authentication.confirmed_at).to be nil
  end
end<commit_msg>Refactors request spec - inline with changed workflow<commit_after># frozen_string_literal: true
require 'rails_helper'

describe 'Email Confirmation when signing up to express donations' do
  let!(:auth) do
    create(:member_authentication, token: '<PASSWORD>')
  end

  it 'confirms user authentication if the token matches' do
    Timecop.freeze do
      get '/email_confirmation?token=1<PASSWORD>'

      expect(response.body).to include('You have successfully signed up for express donations')
      expect(auth.reload.confirmed_at).to eq(Time.now)
    end
  end

  it 'renders error if the token does not match' do
    get '/email_confirmation?token=abcd'

    expect(response.body).to match(/issue signing up for express donations/)
    expect(auth.reload.confirmed_at).to be nil
  end
end
{'fraction_non_alphanumeric': 0.0937350549976088, 'fraction_numerical': 0.0028694404591104736, 'mean_word_length': 3.8878504672897196, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3211963', 'n_tokens_mistral': 612, 'n_tokens_neox': 582, 'n_words': 191}