Skip to content

Commit

Permalink
Merge pull request #77 from gocardless/persons_with_significant_contr…
Browse files Browse the repository at this point in the history
…ol_statements

persons_with_significant_control_statements
  • Loading branch information
mostafaibrahim17 authored Dec 13, 2022
2 parents 9ee4fb3 + cda942e commit ea24770
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/companies_house/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def persons_with_significant_control(id, register_view: false)
)
end

def persons_with_significant_control_statements(id, register_view: false)
get_all_pages(
:persons_with_significant_control_statements,
"company/#{id}/persons-with-significant-control-statements",
id,
register_view: register_view,
)
end

def filing_history_list(id)
get_all_pages(:filing_history_list, "company/#{id}/filing-history", id)
end
Expand Down
86 changes: 86 additions & 0 deletions spec/companies_house/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,92 @@
end
end

describe "#persons_with_significant_control_statements" do
subject(:response) do
client.persons_with_significant_control_statements(company_id,
register_view: register_view)
end

include_context "test client"

let(:rest_path) do
"company/#{company_id}/persons-with-significant-control-statements" \
"?register_view=#{register_view}"
end
let(:request_method) { "persons_with_significant_control_statements" }
let(:register_view) { true }

context "when all results are on a single page" do
let(:single_page) do
{
items_per_page: 2,
total_results: 2,
start_index: 0,
items: %w[item1 item2],
}.to_json
end

before do
stub_request(:get, "#{example_endpoint}/#{rest_path}").
with(
basic_auth: [api_key, ""],
query: { "start_index" => 0, register_view: register_view },
).to_return(body: single_page, status: status)
end

it "returns items from the one, single page" do
expect(response).to eq(%w[item1 item2])
end

context "with register_view: false" do
let(:register_view) { false }

it "returns items from the one, single page" do
expect(response).to eq(%w[item1 item2])
end
end
end

context "when results are spread across several pages" do
let(:page1) do
{
items_per_page: 1,
total_results: 2,
start_index: 0,
items: ["item1"],
}.to_json
end

let(:page2) do
{
items_per_page: 1,
total_results: 2,
start_index: 1,
items: ["item2"],
}.to_json
end

before do
stub_request(:get, "#{example_endpoint}/#{rest_path}").
with(
basic_auth: [api_key, ""],
query: { "start_index" => 0, register_view: true },
).
to_return(body: page1, status: status)
stub_request(:get, "#{example_endpoint}/#{rest_path}").
with(
basic_auth: [api_key, ""],
query: { "start_index" => 1, register_view: true },
).
to_return(body: page2, status: status)
end

it "returns items from all pages" do
expect(response).to eq(%w[item1 item2])
end
end
end

describe "#company_search" do
include_context "test client"

Expand Down

0 comments on commit ea24770

Please sign in to comment.