<commit_before>ENV["RAILS_ENV"] = "test"
require "webmock"
require "pact/provider/rspec"
require "rails_helper"

WebMock.disable!

Pact.configure do |config|
  config.reports_dir = "spec/reports/pacts"
  config.include WebMock::API
  config.include WebMock::Matchers
end

Pact.service_provider "Content Store" do
  honours_pact_with "Publishing API" do
    if ENV['USE_LOCAL_PACT']
      pact_uri ENV.fetch('PUBLISHING_API_PACT_PATH', '../publishing-api/spec/pacts/publishing_api-content_store.json')
    else
      base_url = ENV.fetch("PACT_BROKER_BASE_URL", "https://pact-broker.cloudapps.digital")
      url = "#{base_url}/pacts/provider/#{CGI.escape(name)}/consumer/#{CGI.escape(consumer_name)}"
      version_part = ENV['PUBLISHING_API_PACT_VERSION'] ? "versions/#{CGI.escape(ENV['PUBLISHING_API_PACT_VERSION'])}" : 'latest'

      pact_uri "#{url}/#{version_part}"
    end
  end
end

Pact.provider_states_for "Publishing API" do
  set_up do
    WebMock.enable!
    WebMock.reset!
    DatabaseCleaner.clean_with :truncation
  end

  tear_down do
    WebMock.disable!
  end

  provider_state "a content item exists with base_path /vat-rates and transmitted_at 1000000000000000000" do
    set_up do
      stub_request(:any, Regexp.new(Plek.find("router-api")))

      FactoryGirl.create(<commit_msg>Switch from CGI.escape to ERB url_encode<commit_after>ENV["RAILS_ENV"] = "test"
require "webmock"
require "pact/provider/rspec"
require "rails_helper"

WebMock.disable!

Pact.configure do |config|
  config.reports_dir = "spec/reports/pacts"
  config.include WebMock::API
  config.include WebMock::Matchers
end

def url_encode(str)
  ERB::Util.url_encode(str)
end

Pact.service_provider "Content Store" do
  honours_pact_with "Publishing API" do
    if ENV['USE_LOCAL_PACT']
      pact_uri ENV.fetch('PUBLISHING_API_PACT_PATH', '../publishing-api/spec/pacts/publishing_api-content_store.json')
    else
      base_url = ENV.fetch("PACT_BROKER_BASE_URL", "https://pact-broker.cloudapps.digital")
      url = "#{base_url}/pacts/provider/#{url_encode(name)}/consumer/#{url_encode(consumer_name)}"
      version_part = ENV['PUBLISHING_API_PACT_VERSION'] ? "versions/#{url_encode(ENV['PUBLISHING_API_PACT_VERSION'])}" : 'latest'

      pact_uri "#{url}/#{version_part}"
    end
  end
end

Pact.provider_states_for "Publishing API" do
  set_up do
    WebMock.enable!
    WebMock.reset!
    DatabaseCleaner.clean_with :truncation
  end

  tear_down do
    WebMock.disable!
  end

  provider_state "a content item exists with base_path /vat-rates and transmitted_at 1000000000000000000" do
    set_up do
      stub_request(:any, Regexp.new(Plek.find("router-api")))

      FactoryGirl.create(
{'fraction_non_alphanumeric': 0.12099776619508563, 'fraction_numerical': 0.014147431124348473, 'mean_word_length': 4.597916666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '114215', 'n_tokens_mistral': 1041, 'n_tokens_neox': 965, 'n_words': 166}