Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from GdsApi::PublishingApiV2 #1052

Merged
merged 13 commits into from Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/lib/services.rb
Expand Up @@ -4,7 +4,7 @@

module Services
def self.publishing_api
@publishing_api ||= GdsApi::PublishingApiV2.new(
@publishing_api ||= GdsApi::PublishingApi.new(
Plek.new.find("publishing-api"),
disable_cache: true,
bearer_token: ENV["PUBLISHING_API_BEARER_TOKEN"] || "example",
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/taxons_controller_spec.rb
Expand Up @@ -115,9 +115,9 @@
taxon = build(:taxon, publication_state: "unpublished", content_id: SecureRandom.uuid)
stub_publishing_api_publish(taxon.content_id, {}, status: 422)
payload = Taxonomy::BuildTaxonPayload.call(taxon: taxon)
publishing_api_has_item(payload.merge(content_id: taxon.content_id))
publishing_api_has_expanded_links(content_id: taxon.content_id)
publishing_api_has_lookups(taxon.base_path => SecureRandom.uuid)
stub_publishing_api_has_item(payload.merge(content_id: taxon.content_id))
stub_publishing_api_has_expanded_links(content_id: taxon.content_id)
stub_publishing_api_has_lookups(taxon.base_path => SecureRandom.uuid)

post :publish, params: { taxon_id: taxon.content_id }

Expand Down Expand Up @@ -151,8 +151,8 @@
parent_taxon = taxon_with_details(
"root", other_fields: { base_path: "/level-one", content_id: "CONTENT-ID-PARENT" }
)
publishing_api_has_item(parent_taxon)
publishing_api_has_expanded_links(content_id: "CONTENT-ID-PARENT")
stub_publishing_api_has_item(parent_taxon)
stub_publishing_api_has_expanded_links(content_id: "CONTENT-ID-PARENT")

Timecop.freeze do
payload = Taxonomy::BuildTaxonPayload.call(taxon: taxon)
Expand All @@ -178,8 +178,8 @@
},
}

publishing_api_has_item(payload.merge(content_id: taxon.content_id))
publishing_api_has_expanded_links(expanded_links.merge(content_id: taxon.content_id))
stub_publishing_api_has_item(payload.merge(content_id: taxon.content_id))
stub_publishing_api_has_expanded_links(expanded_links.merge(content_id: taxon.content_id))
stub_publishing_api_put_content(taxon.content_id, payload)
stub_publishing_api_patch_links(taxon.content_id, links.to_json)

Expand Down
22 changes: 11 additions & 11 deletions spec/features/bulk_tagging_spec.rb
Expand Up @@ -49,7 +49,7 @@ def given_a_collection_with_items_and_some_other_content_groupings
q: "Tax",
)

publishing_api_has_item(document_collection)
stub_publishing_api_has_item(document_collection)

publishing_api_has_content_items(
[{
Expand All @@ -71,7 +71,7 @@ def given_a_collection_with_items_and_some_other_content_groupings
q: "browse",
)

publishing_api_has_expanded_links(
stub_publishing_api_has_expanded_links(
content_id: "collection-id",
expanded_links: {
documents: [
Expand All @@ -83,11 +83,11 @@ def given_a_collection_with_items_and_some_other_content_groupings
end

def and_a_set_of_taxons
publishing_api_has_item(basic_content_item("Taxon 1"))
publishing_api_has_item(basic_content_item("Taxon 2"))
stub_publishing_api_has_item(basic_content_item("Taxon 1"))
stub_publishing_api_has_item(basic_content_item("Taxon 2"))

# Used in the dropdown
publishing_api_has_linkables(
stub_publishing_api_has_linkables(
[
build_linkable(internal_name: "Taxon 1", content_id: "taxon-1"),
build_linkable(internal_name: "Taxon 2", content_id: "taxon-2"),
Expand Down Expand Up @@ -159,9 +159,9 @@ def then_i_can_preview_my_changes
end

def when_i_create_tags
publishing_api_has_links(content_id: "tax-doc-1", links: { taxons: [] })
publishing_api_has_links(content_id: "tax-doc-2", links: { taxons: [] })
publishing_api_has_lookups(
stub_publishing_api_has_links(content_id: "tax-doc-1", links: { taxons: [] })
stub_publishing_api_has_links(content_id: "tax-doc-2", links: { taxons: [] })
stub_publishing_api_has_lookups(
"/level-one/tax-doc-1" => "tax-doc-1",
"/level-one/tax-doc-2" => "tax-doc-2",
)
Expand Down Expand Up @@ -247,14 +247,14 @@ def given_a_tag_migration_exists
tag_migration.tag_mappings << tag_mapping
tag_migration.save!

publishing_api_has_item(
stub_publishing_api_has_item(
content_id: tag_migration.source_content_id,
title: "Source content",
document_type: "taxon",
base_path: "/source-content",
)

publishing_api_has_lookups(tag_mapping.content_base_path => "content-id")
stub_publishing_api_has_lookups(tag_mapping.content_base_path => "content-id")
publishing_api_has_taxons(
[
basic_content_item(
Expand All @@ -266,7 +266,7 @@ def given_a_tag_migration_exists
),
],
)
publishing_api_has_links(
stub_publishing_api_has_links(
content_id: "content-id",
links: { taxons: [] },
version: 0,
Expand Down
12 changes: 6 additions & 6 deletions spec/features/bulk_updating_spec.rb
Expand Up @@ -44,28 +44,28 @@ def given_a_published_taxon_with_draft_children

stub_requests_for_show_page(@parent_taxon)

publishing_api_has_links(
stub_publishing_api_has_links(
content_id: @parent_content_id,
links: {
child_taxons: [@child_content_id],
},
)

publishing_api_has_links(
stub_publishing_api_has_links(
content_id: @child_content_id,
links: {
parent: [@parent_content_id],
},
)

publishing_api_has_expanded_links(
stub_publishing_api_has_expanded_links(
content_id: @parent_content_id,
expanded_links: {
child_taxons: [@child_taxon],
},
)

publishing_api_has_expanded_links(
stub_publishing_api_has_expanded_links(
content_id: @child_content_id,
expanded_links: {
parent_taxons: [@parent_taxon],
Expand Down Expand Up @@ -95,8 +95,8 @@ def when_i_click_confirm_update

# We need to make a get request for each item to determine whether the taxon
# is published or not
publishing_api_has_item(@parent_taxon)
publishing_api_has_item(@child_taxon)
stub_publishing_api_has_item(@parent_taxon)
stub_publishing_api_has_item(@child_taxon)
stub_any_publishing_api_put_content

click_button "Confirm bulk update"
Expand Down
26 changes: 13 additions & 13 deletions spec/features/delete_taxon_spec.rb
Expand Up @@ -130,7 +130,7 @@ def given_a_deleted_taxon

# Override the `links` call in stub_requests_for_show_page
# TODO: extend stub_requests_for_show_page to make this easier
publishing_api_has_links(
stub_publishing_api_has_links(
content_id: @taxon_content_id,
links: {
parent_taxons: %w[CONTENT-ID-PARENT],
Expand Down Expand Up @@ -181,7 +181,7 @@ def when_i_choose_a_taxon_to_redirect_to(selection)

def when_i_confirm_deletion
Sidekiq::Testing.inline! do
@get_content_request = publishing_api_has_item(stubbed_taxons[0])
@get_content_request = stub_publishing_api_has_item(stubbed_taxons[0])
@unpublish_request = stub_publishing_api_unpublish(@taxon_content_id, body: { type: :redirect, alternative_path: "/alpha-taxonomy/vehicle-plating" }.to_json)
click_on "Delete and redirect"
end
Expand All @@ -191,8 +191,8 @@ def when_i_confirm_restoration
parent_taxon = taxon_with_details(
"root", other_fields: { base_path: "/level-one", content_id: "CONTENT-ID-PARENT" }
)
publishing_api_has_item(parent_taxon)
publishing_api_has_links(content_id: "CONTENT-ID-PARENT")
stub_publishing_api_has_item(parent_taxon)
stub_publishing_api_has_links(content_id: "CONTENT-ID-PARENT")

@put_content_request = stub_publishing_api_put_content(@taxon_content_id, {})
@patch_links_request = stub_publishing_api_patch_links(@taxon_content_id, {})
Expand Down Expand Up @@ -254,19 +254,19 @@ def add_a_parent_taxon
#
# Stub realistic values for links and expanded links to correctly render
# the tree on the taxon show page
publishing_api_has_links(
stub_publishing_api_has_links(
content_id: @taxon_content_id,
links: {
parent_taxons: [@parent_taxon_content_id],
},
)
publishing_api_has_expanded_links(
stub_publishing_api_has_expanded_links(
content_id: @taxon_content_id,
expanded_links: {
parent_taxons: [@parent_taxon],
},
)
publishing_api_has_expanded_links(
stub_publishing_api_has_expanded_links(
content_id: @parent_taxon_content_id,
expanded_links: {
child_taxons: [@taxon],
Expand All @@ -283,19 +283,19 @@ def add_a_child_taxon
#
# Stub realistic values for links and expanded links to correctly render
# the tree on the taxon show page
publishing_api_has_links(
stub_publishing_api_has_links(
content_id: @taxon_content_id,
links: {
child_taxons: [@child_taxon_content_id],
},
)
publishing_api_has_expanded_links(
stub_publishing_api_has_expanded_links(
content_id: @taxon_content_id,
expanded_links: {
child_taxons: [@child_taxon],
},
)
publishing_api_has_expanded_links(
stub_publishing_api_has_expanded_links(
content_id: @child_taxon_content_id,
expanded_links: {
parent_taxons: [@taxon],
Expand All @@ -305,16 +305,16 @@ def add_a_child_taxon

def add_tagged_content(fields:)
content_item = basic_content_item("tagged content")
publishing_api_has_linked_items(
stub_publishing_api_has_linked_items(
[content_item],
content_id: @taxon_content_id,
link_type: "taxons",
fields: fields,
)

publishing_api_has_lookups(content_item[:base_path] => content_item[:content_id])
stub_publishing_api_has_lookups(content_item[:base_path] => content_item[:content_id])

publishing_api_has_links(
stub_publishing_api_has_links(
content_id: content_item[:content_id],
links: {
taxons: [@taxon_content_id],
Expand Down
6 changes: 3 additions & 3 deletions spec/features/download_tagged_content_spec.rb
Expand Up @@ -35,14 +35,14 @@ def when_i_click_the_download_button
},
)

publishing_api_has_linked_items(
stub_publishing_api_has_linked_items(
[content_item],
content_id: @content_id,
link_type: "taxons",
fields: Taxonomy::TaxonomyExport::COLUMNS,
)

publishing_api_has_links_for_content_ids(
stub_publishing_api_has_links_for_content_ids(
"tagged-content" =>
{
"links" => {
Expand All @@ -51,7 +51,7 @@ def when_i_click_the_download_button
},
)

publishing_api_has_content(
stub_publishing_api_has_content(
[{ "content_id" => "org-content-id", "title" => "org title" }],
document_type: "organisation",
fields: %w[content_id title],
Expand Down
16 changes: 8 additions & 8 deletions spec/features/move_content_between_taxons_spec.rb
Expand Up @@ -76,12 +76,12 @@ def given_there_are_taxons
@document1 = basic_content_item("Tagged content 1")
@document2 = basic_content_item("Tagged content 2")

publishing_api_has_links(
stub_publishing_api_has_links(
content_id: @source_taxon[:content_id],
links: {},
version: 1,
)
publishing_api_has_expanded_links(
stub_publishing_api_has_expanded_links(
content_id: @source_taxon[:content_id],
expanded_links: {},
)
Expand All @@ -94,10 +94,10 @@ def given_there_are_taxons
)

publishing_api_has_taxons([@source_taxon, @dest_taxon])
publishing_api_has_item(@source_taxon)
publishing_api_has_item(@dest_taxon)
stub_publishing_api_has_item(@source_taxon)
stub_publishing_api_has_item(@dest_taxon)

publishing_api_has_linkables(
stub_publishing_api_has_linkables(
[@source_taxon_for_select, @dest_taxon_for_select],
document_type: "taxon",
)
Expand Down Expand Up @@ -147,7 +147,7 @@ def then_i_can_see_that_the_old_taxon_link_will_be_removed

def and_all_content_can_be_moved_when_i_start_the_content_move
# Lookups to fetch the content ID based on existing base paths
publishing_api_has_lookups(
stub_publishing_api_has_lookups(
@document1[:base_path] => @document1[:content_id],
@document2[:base_path] => @document2[:content_id],
)
Expand All @@ -166,7 +166,7 @@ def and_all_content_can_be_moved_when_i_start_the_content_move
end

def and_only_published_content_can_be_moved_when_i_start_the_content_move
publishing_api_has_lookups(
stub_publishing_api_has_lookups(
@document2[:base_path] => @document2[:content_id],
)

Expand Down Expand Up @@ -194,7 +194,7 @@ def and_i_start_tagging

def assert_content_items_have_been_moved_for_document(document, source, dest)
# First we fetch existing links
publishing_api_has_links(
stub_publishing_api_has_links(
content_id: document[:content_id],
links: { taxons: [source[:content_id]] },
version: 1,
Expand Down
2 changes: 1 addition & 1 deletion spec/features/project_spec.rb
Expand Up @@ -183,7 +183,7 @@ def and_there_is_a_draft_taxonomy_branch
end

def and_the_publishing_api_can_find_the_content_items_in_the_remote_spreadsheet
publishing_api_has_lookups(
stub_publishing_api_has_lookups(
"/vat-rates" => "f838c22a-b2aa-49be-bd95-153f593293a3",
"/passport-fees" => "8b59b474-9775-4366-97ee-97a66740411c",
)
Expand Down
4 changes: 2 additions & 2 deletions spec/features/related_item_tagging_spec.rb
Expand Up @@ -37,7 +37,7 @@ def and_i_navigate_to_tagging_page_for_item
end

def given_a_content_item_exists
publishing_api_has_lookups(
stub_publishing_api_has_lookups(
"/my-content-item" => "MY-CONTENT-ID",
)

Expand All @@ -62,7 +62,7 @@ def given_a_content_item_exists
def given_we_can_populate_the_dropdowns_with_content_from_publishing_api
# In this test we don't care about empty dropdowns
%w[topic taxon organisation mainstream_browse_page need].each do |document_type|
publishing_api_has_linkables([], document_type: document_type)
stub_publishing_api_has_linkables([], document_type: document_type)
end
end

Expand Down