This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
79 lines (63 loc) · 2.73 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
begin
require "rubocop/rake_task"
require "rspec/core/rake_task"
require "vcr"
RuboCop::RakeTask.new
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
# These gems will fail to load outside of dev/test environments
end
require_relative "app"
namespace :content_item do
desc "Sync a content item with the Publishing API"
task :sync, :content_id, :locale do |_, args|
args.with_defaults(locale: "en")
content_config = ContentConfig.find(args[:content_id], args[:locale])
abort "A content item is not configured for #{args[:content_id]}:#{args[:locale]}" unless content_config
if ENV["RESERVE_PATH"]
if content_config.base_path
GdsApi.publishing_api.put_path(
content_config.base_path,
{ publishing_app: PublishingApi::PUBLISHING_APP_NAME },
)
puts "Reserved #{content_config.base_path} for #{args[:content_id]}:#{args[:locale]}"
else
abort "A base_path isn't configured for #{args[:content_id]}:#{args[:locale]}"
end
end
live_result = PublishingApi::Updater.update_live(content_config)
puts live_result.to_s
draft_result = PublishingApi::Updater.update_draft(content_config)
puts draft_result.to_s
end
desc "Unpublish content from Publishing API"
task :unpublish, :content_id, :locale do |_, args|
args.with_defaults(locale: "en")
type = ENV.fetch("TYPE", "gone")
GdsApi.publishing_api.unpublish(args[:content_id],
locale: args[:locale],
discard_drafts: true,
type:,
explanation: ENV["EXPLANATION"],
alternative_path: ENV["URL"])
puts "Unpublished #{args[:content_id]}:#{args[:locale]} from GOV.UK with a type of #{type}"
end
end
namespace :vcr do
desc "Generate a new cassette to mock Contentful API responses for tests"
task :record_contentful_api_response do
File.delete("spec/fixtures/vcr_cassettes/contentful_api_response.yml") if File.exist?("spec/fixtures/vcr_cassettes/contentful_api_response.yml")
content_config = ContentConfig.all.last
contentful_client = ContentfulClient.live_client(content_config.contentful_space_id)
VCR.configure do |config|
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
config.hook_into(:webmock)
config.filter_sensitive_data("<ACCESS_TOKEN>") { contentful_client.configuration[:access_token] }
end
VCR.use_cassette("contentful_api_response", decode_compressed_response: true) do
contentful_client.entry(content_config.contentful_entry_id, include: 10)
end
puts "Recorded new Contentful API response cassette"
end
end
task default: %I[rubocop spec]