require "rails_helper"

RSpec.describe "Invalid content requests", type: :request do
  let(:error_details) { { errors: { update_type: "invalid" } } }

  before do
    stub_request(:put, /publish-intent/)
      .to_return(
        status: 422,
        body: error_details.to_json,
        headers: {"Content-type" => "application/json"}
      )
  end

  context "/publish-intent" do
    let(:request_body) { content_item_params.to_json }
    let(:request_path) { "/publish-intent/#{base_path}" }
    let(:request_method) { :put }

    does_not_log_event
    creates_no_derived_representations
  end
end

require "rails_helper"

RSpec.describe "Invalid content requests", type: :request do
  let(:error_details) { {errors: {update_type: "invalid"}} }

  before do
    stub_request(:put, %r{.*content-store.*/content/.*})
      .to_return(
        status: 422,
        body: error_details.to_json,
        headers: {"Content-type" => "application/json"}
      )
  end

  context "/content" do
    let(:request_body) { content_item_params.to_json }
    let(:request_path) { "/content#{base_path}" }
    let(:request_method) { :put }

    does_not_log_event
    creates_no_derived_representations
  end

  context "/draft-content" do
    let(:request_body) { content_item_params.to_json }
    let(:request_path) { "/draft-content#{base_path}" }
    let(:request_method) { :put }

    does_not_log_event
    creates_no_derived_representations
  end

  context "/v2/content" do
    let(:request_body) { v2_content_item.to_json }
    let(:request_path) { "/v2/content/#{content_id}" }
    let(:request_method) { :put }

    does_not_log_event
    creates_no_derived_representations
  end

  context "/v2/links" do
    let(:request_body) { links_attributes.to_json }
    let(:request_path) { "/v2/links/#{content_id}" }
    let(:request_method) { :put }

    before do
      live = FactoryGirl.create(:live_content_item, v2_content_item.slice(*LiveContentItem::TOP_LEVEL_FIELDS))
      draft = live.draft_content_item

      draft.update!(access_limited: v2_content_item.fetch(:access_limited))

      FactoryGirl.create(:version, target: draft, number: 1)
      FactoryGirl.create(:version, target: live, number: 1)
    end

    does_not_log_event
    creates_no_derived_representations
  end
end

--- 
+++ 
@@ -1,10 +1,10 @@
 require "rails_helper"
 
 RSpec.describe "Invalid content requests", type: :request do
-  let(:error_details) { {errors: {update_type: "invalid"}} }
+  let(:error_details) { { errors: { update_type: "invalid" } } }
 
   before do
-    stub_request(:put, %r{.*content-store.*/content/.*})
+    stub_request(:put, /publish-intent/)
       .to_return(
         status: 422,
         body: error_details.to_json,
@@ -12,49 +12,12 @@
       )
   end
 
-  context "/content" do
+  context "/publish-intent" do
     let(:request_body) { content_item_params.to_json }
-    let(:request_path) { "/content#{base_path}" }
+    let(:request_path) { "/publish-intent/#{base_path}" }
     let(:request_method) { :put }
 
     does_not_log_event
     creates_no_derived_representations
   end
-
-  context "/draft-content" do
-    let(:request_body) { content_item_params.to_json }
-    let(:request_path) { "/draft-content#{base_path}" }
-    let(:request_method) { :put }
-
-    does_not_log_event
-    creates_no_derived_representations
-  end
-
-  context "/v2/content" do
-    let(:request_body) { v2_content_item.to_json }
-    let(:request_path) { "/v2/content/#{content_id}" }
-    let(:request_method) { :put }
-
-    does_not_log_event
-    creates_no_derived_representations
-  end
-
-  context "/v2/links" do
-    let(:request_body) { links_attributes.to_json }
-    let(:request_path) { "/v2/links/#{content_id}" }
-    let(:request_method) { :put }
-
-    before do
-      live = FactoryGirl.create(:live_content_item, v2_content_item.slice(*LiveContentItem::TOP_LEVEL_FIELDS))
-      draft = live.draft_content_item
-
-      draft.update!(access_limited: v2_content_item.fetch(:access_limited))
-
-      FactoryGirl.create(:version, target: draft, number: 1)
-      FactoryGirl.create(:version, target: live, number: 1)
-    end
-
-    does_not_log_event
-    creates_no_derived_representations
-  end
 end
Remove tests for synchronous ContentStore calls…

These tests are no longer relevant because we call
the content store asynchronously for the /v2
endpoints.

The /v1 endpoints are still synchronous
so we changed these tests to use the /publish-intents
endpoint because that’s the only endpoint that’s
still validated by the content store.