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

Update to handle new Register API response format #562

Merged
merged 2 commits into from
Mar 31, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/jobs/fetch_country_register_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def perform(*args)
private

def countries
items = fetch_register.body
if items.is_a?(Array)
items.map { |r| r['entry'] }
values = fetch_register.body.values
if !values.empty? && values.first.has_key?('item')
values.map { |x| x['item'].first }
else
items.values
values
end
end

Expand Down
86 changes: 46 additions & 40 deletions spec/jobs/fetch_petition_register_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@ def json_error(status = 404, body = "{}")
{status: status, headers: {"Content-Type" => "application/json"}, body: body}
end

context "old (array-based) record schema" do
context "latest record schema" do
context "when a country does not exist" do
before do
stub_register.to_return json_response <<-JSON
[
{
"serial-number": 6,
"hash": "2778fa2a0a97b98728053b4caf7fee918aa0357c",
"entry": {
"citizen-names": "Briton;British citizen",
"country": "GB",
"name": "United Kingdom",
"official-name": "The United Kingdom of Great Britain and Northern Ireland",
"start-date": "1707-05-01",
"end-date": "2017-12-31"
}
{
"GB" : {
"index-entry-number": "6",
"entry-number": "6",
"entry-timestamp": "2016-04-05T13:23:05Z",
"key": "GB",
"item": [{
"citizen-names": "Briton;British citizen",
"country": "GB",
"name": "United Kingdom",
"official-name": "The United Kingdom of Great Britain and Northern Ireland",
"start-date": "1707-05-01",
"end-date": "2017-12-31"
}]
}
]
}
JSON
end

Expand Down Expand Up @@ -74,20 +76,22 @@ def json_error(status = 404, body = "{}")
FactoryGirl.create(:location, code: "GB")

stub_register.to_return json_response <<-JSON
[
{
"serial-number": 6,
"hash": "2778fa2a0a97b98728053b4caf7fee918aa0357c",
"entry": {
"citizen-names": "Briton;British citizen",
"country": "GB",
"name": "United Kingdom",
"official-name": "The United Kingdom of Great Britain and Northern Ireland",
"start-date": "1707-05-01",
"end-date": "2017-12-31"
}
{
"GB" : {
"index-entry-number": "6",
"entry-number": "6",
"entry-timestamp": "2016-04-05T13:23:05Z",
"key": "GB",
"item": [{
"citizen-names": "Briton;British citizen",
"country": "GB",
"name": "United Kingdom",
"official-name": "The United Kingdom of Great Britain and Northern Ireland",
"start-date": "1707-05-01",
"end-date": "2017-12-31"
}]
}
]
}
JSON
end

Expand Down Expand Up @@ -129,22 +133,23 @@ def json_error(status = 404, body = "{}")
FactoryGirl.create(:location, code: "GB", name: "United Kingdom")

stub_register.to_return json_response <<-JSON
[
{
"serial-number": 6,
"hash": "2778fa2a0a97b98728053b4caf7fee918aa0357c",
"entry": {
"citizen-names": "Briton;British citizen",
"country": "GB",
"name": "United Kingdom",
"official-name": "The United Kingdom of Great Britain and Northern Ireland"
}
{
"GB" : {
"index-entry-number": "6",
"entry-number": "6",
"entry-timestamp": "2016-04-05T13:23:05Z",
"key": "GB",
"item": [{
"citizen-names": "Briton;British citizen",
"country": "GB",
"name": "United Kingdom",
"official-name": "The United Kingdom of Great Britain and Northern Ireland"
}]
}
]
}
JSON
end


it "doesn't update an existing record" do
expect {
perform_enqueued_jobs {
Expand All @@ -153,9 +158,10 @@ def json_error(status = 404, body = "{}")
}.not_to change { location.reload.updated_at }
end
end

end

context "new (map-based) record schema" do
context "old record schema" do
context "when a country does not exist" do
before do
stub_register.to_return json_response <<-JSON
Expand Down