<commit_before>require 'helper'

class TestFundraising < Minitest::Test
  def setup
    JustGiving::Configuration.application_id = '2345'
  end

  context 'using basic auth' do
    setup do
      JustGiving::Configuration.username = 'test'
      JustGiving::Configuration.password = '<PASSWORD>'
    end

    should 'get pages' do
      stub_get('/v1/fundraising/pages').with(
        :basic_auth => ['test', 'secret']
      ).to_return(
        :body    => fixture('fundraising_pages_success.json'),
        :headers => {:content_type =>  'application/json; charset=utf-8'}
      )

      pages = JustGiving::Fundraising.new.pages
    end

    should 'get donations' do
      stub_get('/v1/fundraising/pages/test/donations?pageNum=1&page_size=50').with(
        :basic_auth => ['test', 'secret']
      ).to_return(
        :body    => fixture('fundraising_donations_success.json'),
        :headers => {:content_type =>  'application/json; charset=utf-8'}
      )

      pages = JustGiving::Fundraising.new('test').donations
    end

    should 'set pagination options for donations' do
      stub_get('/v1/fundraising/pages/test/donations?pageNum=2&page_size=10').with(
        :basic_auth => ['test', 'secret']
      ).to_return(
        :body    => fixture('fundraising_donations_success.json'),
        :headers => {:content_type =>  'application/json; charset=utf-8'}
      )

      pages = JustGiving::Fundraising.new('test').donations(2, 10)
    end

    should 'create page' do
      stub_put('/v1/fundraising/pages').with(
        :basic_auth => ['test', 'secret']
      ).to_return(
        :body    => fixture('fundraising_pages_success.json'),
        :headers => {:content_type =>  'application/json; charset=utf-8'},
        :status  => 201
      )

      page = JustGiving::Fundraising.new.create({})
    end

    should 'update story' do
      stub_post('/v1/fundraising/pages/test').with(
        :basic_auth => ['test', 'secret'],
        :body       => '{"storySupplement":"new story"}'
      ).to_return(
        :body => fixture('fundraising_update_story_success.json'),
        :headers => {:content_type => 'application/json; charset=utf-8'},
        :status => 200
      )

      page = JustGiving::Fundraising.new('test').update_story('new story')
    end
  end

  context 'with no basic auth' do
    should 'check if short name is registered' do
      stub_head('/v1/fundraising/pages/test').to_return(
        :status  => 200,
        :headers => { :content_type => 'application/json; charset=utf-8'},
        :body    => "{}"
      )

      assert JustGiving::Fundraising.new('test').short_name_registered?
    end

    should 'check if short name is registered when not found' do
      stub_head('/v1/fundraising/pages/test').to_return(
        :status  => 404,
        :headers => {:content_type => 'application/json; charset=utf-8'}
      )

      refute JustGiving::Fundraising.new('test').short_name_registered?
    end

    should 'get fundraising page' do
      stub_get('/v1/fundraising/pages/test').to_return(
        :body    => fixture('fundraising_get_page_success.json'),
        :status  => 200,
        :headers => {:content_type =>  'application/json; charset=utf-8'}
      )

      page = JustGiving::Fundraising.new('test').page
      assert_equal "00A246", page["branding"]["buttonColour"]
      assert_equal "261017", page["charity"]["registrationNumber"]
    end
  end
end
<commit_msg>Fix tests broken by b498781 & 3742898<commit_after>require 'helper'

class TestFundraising < Minitest::Test
  def setup
    JustGiving::Configuration.application_id = '2345'
  end

  context 'using basic auth' do
    setup do
      JustGiving::Configuration.username = 'test'
      JustGiving::Configuration.password = '<PASSWORD>'
    end

    should 'get pages' do
      stub_get('/v1/fundraising/pages').with(
        :basic_auth => ['test', 'secret']
      ).to_return(
        :body    => fixture('fundraising_pages_success.json'),
        :headers => {:content_type =>  'application/json; charset=utf-8'}
      )

      pages = JustGiving::Fundraising.new.pages
    end

    should 'get donations' do
      stub_get('/v1/fundraising/pages/test/donations?pageNum=1&pagesize=50').with(
        :basic_auth => ['test', 'secret']
      ).to_return(
        :body    => fixture('fundraising_donations_success.json'),
        :headers => {:content_type =>  'application/json; charset=utf-8'}
      )

      pages = JustGiving::Fundraising.new('test').donations(1, 50, true)
    end

    should 'set pagination options for donations' do
      stub_get('/v1/fundraising/pages/test/donations?pageNum=2&pagesize=10').with(
        :basic_auth => ['test', 'secret']
      ).to_return(
        :body    => fixture('fundraising_donations_success.json'),
        :headers => {:content_type =>  'application/json; charset=utf-8'}
      )

      pages = JustGiving::Fundraising.new('test').donations(2, 10, true)
    end

    should 'create page' do
      stub_put('/v1/fundraising/pages').with(
        :basic_auth => ['test', 'secret']
      ).to_return(
        :body    => fixture('fundraising_pages_success.json'),
        :headers => {:content_type =>  'application/json; charset=utf-8'},
        :status  => 201
      )

      page = JustGiving::Fundraising.new.create({})
    end

    should 'update story' do
      stub_post('/v1/fundraising/pages/test').with(
        :basic_auth => ['test', 'secret'],
        :body       => '{"storySupplement":"new story"}'
      ).to_return(
        :body => fixture('fundraising_update_story_success.json'),
        :headers => {:content_type => 'application/json; charset=utf-8'},
        :status => 200
      )

      page = JustGiving::Fundraising.new('test').update_story('new story')
    end
  end

  context 'with no basic auth' do
    should 'check if short name is registered' do
      stub_head('/v1/fundraising/pages/test').to_return(
        :status  => 200,
        :headers => { :content_type => 'application/json; charset=utf-8'},
        :body    => "{}"
      )

      assert JustGiving::Fundraising.new('test').short_name_registered?
    end

    should 'check if short name is registered when not found' do
      stub_head('/v1/fundraising/pages/test').to_return(
        :status  => 404,
        :headers => {:content_type => 'application/json; charset=utf-8'}
      )

      refute JustGiving::Fundraising.new('test').short_name_registered?
    end

    should 'get fundraising page' do
      stub_get('/v1/fundraising/pages/test').to_return(
        :body    => fixture('fundraising_get_page_success.json'),
        :status  => 200,
        :headers => {:content_type =>  'application/json; charset=utf-8'}
      )

      page = JustGiving::Fundraising.new('test').page
      assert_equal "00A246", page["branding"]["buttonColour"]
      assert_equal "261017", page["charity"]["registrationNumber"]
    end
  end
end

{'fraction_non_alphanumeric': 0.14932715960063667, 'fraction_numerical': 0.018231804369845176, 'mean_word_length': 2.9006772009029347, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 73, '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': '1648813', 'n_tokens_mistral': 2255, 'n_tokens_neox': 2118, 'n_words': 400}