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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/parliament/utils/test_helpers/vcr_helper.rb', line 15
def self.load_rspec_config(config)
return unless LOADED_VCR
parliament_uri = 'http://localhost:3030'
bandiera_uri = 'http://localhost:5000'
opensearch_uri = 'https://apidataparliament.azure-api.net/search/description'
hybrid_bills_uri = 'https://localhost:5050'
VCR.configure do |config|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
config.hook_into :webmock
config.configure_rspec_metadata!
config.default_cassette_options = {
record: :once
}
config.register_request_matcher :filtered_uri do |request_1, request_2|
parliament_match = request_1.uri.sub(ENV['PARLIAMENT_BASE_URL'], parliament_uri) == request_2.uri.sub(ENV['PARLIAMENT_BASE_URL'], parliament_uri) if ENV['PARLIAMENT_BASE_URL']
bandiera_match = request_1.uri.sub(ENV['BANDIERA_URL'], bandiera_uri) == request_2.uri.sub(ENV['BANDIERA_URL'], bandiera_uri) if ENV['BANDIERA_URL']
opensearch_match = request_1.uri.sub(ENV['OPENSEARCH_DESCRIPTION_URL'], opensearch_uri) == request_2.uri.sub(ENV['OPENSEARCH_DESCRIPTION_URL'], opensearch_uri) if ENV['OPENSEARCH_DESCRIPTION_URL']
hybrid_bills_match = request_1.uri.sub(ENV['HYBRID_BILL_API_BASE_URL'], hybrid_bills_uri) == request_2.uri.sub(ENV['HYBRID_BILL_API_BASE_URL'], hybrid_bills_uri) if ENV['HYBRID_BILL_API_BASE_URL']
parliament_match || bandiera_match || opensearch_match || hybrid_bills_match
end
config.default_cassette_options = { match_requests_on: %i[method filtered_uri] }
config.filter_sensitive_data('<AUTH_TOKEN>') { ENV['PARLIAMENT_AUTH_TOKEN'] } if ENV['PARLIAMENT_AUTH_TOKEN']
config.filter_sensitive_data(parliament_uri) { ENV['PARLIAMENT_BASE_URL'] } if ENV['PARLIAMENT_BASE_URL']
config.filter_sensitive_data(bandiera_uri) { ENV['BANDIERA_URL'] } if ENV['BANDIERA_URL']
config.filter_sensitive_data(opensearch_uri) { ENV['OPENSEARCH_DESCRIPTION_URL'] } if ENV['OPENSEARCH_DESCRIPTION_URL']
config.filter_sensitive_data(hybrid_bills_uri) { ENV['HYBRID_BILL_API_BASE_URL'] } if ENV['HYBRID_BILL_API_BASE_URL']
config.before_record do |interaction|
should_ignore = ['_:node', '^^<http://www.w3.org/2001/XMLSchema#date>', '^^<http://www.w3.org/2001/XMLSchema#dateTime>', '^^<http://www.w3.org/2001/XMLSchema#integer>']
if interaction.response.['Content-Type']&.include?('application/n-triples')
lines = interaction.response.body.split("\n")
predicate_occurrances = Hash.new(1)
lines.each do |line|
next if should_ignore.any? { |condition| line.include?(condition) }
next unless line.include?('"')
subject, predicate_and_object = line.split('> <')
predicate, object = predicate_and_object.split('> "')
predicate_type = predicate.split('/').last
occurrance = predicate_occurrances[predicate_type]
predicate_occurrances[predicate_type] = predicate_occurrances[predicate_type] + 1
new_object = "#{predicate_type} - #{occurrance}\""
index = object.index('"')
object[0..index] = new_object if index
new_line = "#{subject}> <#{predicate}> \"#{object}"
config.filter_sensitive_data(new_line) { line }
end
end
end
end
config
end
|