/
partners.rb
26 lines (20 loc) · 1.15 KB
/
partners.rb
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
def partners_path(attributes = {})
url_for_model(attributes.merge(resource: 'partner'))
end
Given(/^a Partner "([^"]*)" exists (?:in Referential "([^"]+)" )?with connectors \[([^"\]]*)\] and the following settings:$/) do |slug, referential, connectors, settings|
attributes = {"slug" => slug, "connectorTypes" => connectors.split(',').map(&:strip), "settings" => settings.rows_hash}
begin
RestClient.post partners_path(referential: referential), attributes.to_json, {content_type: :json, accept: :json, :Authorization => "Token token=#{$token}"}
rescue RestClient::ExceptionWithResponse => err
puts err.response.body
raise err
end
end
Then(/^one Partner(?: in Referential "([^"]+)")? has the following attributes:$/) do |referential, attributes|
response = RestClient.get partners_path(referential: referential), {content_type: :json, :Authorization => "Token token=#{$token}"}
response_array = api_attributes(response.body)
parsed_attributes = model_attributes(attributes)
found_value = response_array.find{|a| a["Id"] == parsed_attributes["Id"]}
expect(found_value).not_to be_nil
expect(found_value).to include(parsed_attributes)
end