Skip to content

Commit

Permalink
Merge pull request #2324 from alphagov/strip-will-continue-on
Browse files Browse the repository at this point in the history
Strip will continue on if link doesn't exist
  • Loading branch information
1pretz1 committed Jun 27, 2023
2 parents 9b91e38 + 93523fa commit 105bb32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/importers/licence_transaction/licence_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def call
update_type: "major",
licence_transaction_location: tagging["locations"],
licence_transaction_industry: tagging["industries"],
licence_transaction_will_continue_on: details["will_continue_on"].presence,
licence_transaction_will_continue_on: will_continue_on(details),
licence_transaction_continuation_link: details["continuation_link"].presence,
licence_transaction_licence_identifier: licence_identifier(details),
primary_publishing_organisation: tagging["primary_publishing_organisation"],
Expand All @@ -49,13 +49,13 @@ def call

new_licence.change_note = "Imported from Publisher"

unless new_licence.valid?
puts "[ERROR] licence: #{new_licence.base_path} has validation errors: #{new_licence.errors.inspect}"
if new_licence_already_imported?(new_licence.base_path)
puts "Skipping as licence: #{new_licence.base_path} is already imported"
next
end

if new_licence_already_imported?(new_licence.base_path)
puts "Skipping as licence: #{new_licence.base_path} is already imported"
unless new_licence.valid?
puts "[ERROR] licence: #{new_licence.base_path} has validation errors: #{new_licence.errors.inspect}"
next
end

Expand Down Expand Up @@ -206,6 +206,10 @@ def tagging_csv_validator
def licence_identifier(details)
details["licence_identifier"] if details["continuation_link"].blank?
end

def will_continue_on(details)
details["will_continue_on"] if details["continuation_link"].present?
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
publishing_api_licences_response.tap { |licences| licences.first["title"] = nil }
end

before do
stub_publishing_api_has_content(
[],
{ document_type: "licence_transaction", page: 1, per_page: 500, states: "published" },
)
end

it "doesn't migrate the licence" do
expect { described_class.new(tagging_path).call }
.to output(invalid_licence_error_message).to_stdout
Expand Down

0 comments on commit 105bb32

Please sign in to comment.