Skip to content

Commit

Permalink
Merge pull request #1300 from alphagov/content-modelling/700-add-roll…
Browse files Browse the repository at this point in the history
…up-data-to-host-content-endpoint

(700) Add rollup data to host content endpoint
  • Loading branch information
pezholio authored Nov 28, 2024
2 parents 21a90bf + a7c216f commit 6ca9e91
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

* Add rollup data to host content endpoint [PR](https://github.com/alphagov/gds-api-adapters/pull/1300)

## 97.4.0

* Update dependencies
Expand Down
36 changes: 30 additions & 6 deletions lib/gds_api/test_helpers/publishing_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,28 @@ def stub_publishing_api_has_content(items, params = {})
# "base_path" => "/organisation/bar",
# },
# }] # an array of content items that embed the target content_id
# rollup: {
# "views" => 1
# "locations" => 1
# "instances" => 1
# "organisations" => 1
# } # metadata with the total counts across all pages
# )
# @param content_id [UUID, Mocha::ParameterMatchers::Anything]
# @param content_id [UUID]
# @param total Integer
# @param total_pages Integer
# @param results [Hash]
def stub_publishing_api_has_embedded_content(content_id:, total: 0, total_pages: 0, results: [], page_number: nil, order: nil)
url = "#{PUBLISHING_API_V2_ENDPOINT}/content/#{content_id}/embedded"
# @param results [Array]
# @param rollup [Hash]
def stub_publishing_api_has_embedded_content(
content_id:,
total: 0,
total_pages: 0,
results: [],
page_number: nil,
order: nil,
rollup: {}
)
url = "#{PUBLISHING_API_V2_ENDPOINT}/content/#{content_id}/host-content"

query = {
"page" => page_number,
Expand All @@ -390,12 +405,20 @@ def stub_publishing_api_has_embedded_content(content_id:, total: 0, total_pages:
"content_id" => content_id,
"total" => total,
"total_pages" => total_pages,
"rollup" => rollup,
"results" => results,
}.to_json)
end

def stub_publishing_api_has_embedded_content_for_any_content_id(total: 0, total_pages: 0, results: [], page_number: nil, order: nil)
url = %r{\A#{PUBLISHING_API_V2_ENDPOINT}/content/[0-9a-fA-F-]{36}/embedded}
def stub_publishing_api_has_embedded_content_for_any_content_id(
total: 0,
total_pages: 0,
results: [],
page_number: nil,
order: nil,
rollup: {}
)
url = %r{\A#{PUBLISHING_API_V2_ENDPOINT}/content/[0-9a-fA-F-]{36}/host-content}

query = {
"page" => page_number,
Expand All @@ -408,6 +431,7 @@ def stub_publishing_api_has_embedded_content_for_any_content_id(total: 0, total_
"content_id" => SecureRandom.uuid,
"total" => total,
"total_pages" => total_pages,
"rollup" => rollup,
"results" => results,
}.to_json)
end
Expand Down
9 changes: 9 additions & 0 deletions test/pacts/publishing_api/get_embedded_content_pact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@
},
}
end
let(:rollup) do
{
"views" => 0,
"locations" => 1,
"instances" => 1,
"organisations" => 1,
}
end
let(:expected_body) do
{
"content_id" => reusable_content_id,
"total" => 1,
"results" => [result],
"rollup" => rollup,
}
end

Expand Down

0 comments on commit 6ca9e91

Please sign in to comment.