Skip to content

Commit

Permalink
Merge pull request #562 from samcrang/update-to-use-new-register-api
Browse files Browse the repository at this point in the history
Update to handle new Register API response format
  • Loading branch information
pixeltrix committed Mar 31, 2017
2 parents 0f7b862 + 84a3f40 commit 024fb1d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
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

0 comments on commit 024fb1d

Please sign in to comment.