Skip to content

Commit

Permalink
Merge pull request #1295 from alphagov/content-modelling/678-add-new-…
Browse files Browse the repository at this point in the history
…args-to-embedded-content-helper

Add page and order args to embedded content helper
  • Loading branch information
pezholio authored Nov 14, 2024
2 parents 03b3239 + ae41716 commit 0062147
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## Unreleased
## 97.3.0

* Add page and order args to get_content_by_embedded_document test helper [PR](https://github.com/alphagov/gds-api-adapters/pull/1295)
* Add autocomplete endpoint for Search API v2 [PR](https://github.com/alphagov/gds-api-adapters/pull/1292)

## 97.2.0
Expand Down
32 changes: 26 additions & 6 deletions lib/gds_api/test_helpers/publishing_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,16 @@ def stub_publishing_api_has_content(items, params = {})
# @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: [])
url = if content_id.is_a?(Mocha::ParameterMatchers::Anything)
%r{\A#{PUBLISHING_API_V2_ENDPOINT}/content/[0-9a-fA-F-]{36}/embedded}
else
"#{PUBLISHING_API_V2_ENDPOINT}/content/#{content_id}/embedded"
end
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"

query = {
"page" => page_number,
"order" => order,
}.compact

stub_request(:get, url)
.with(query:)
.to_return(body: {
"content_id" => content_id,
"total" => total,
Expand All @@ -392,6 +394,24 @@ def stub_publishing_api_has_embedded_content(content_id:, total: 0, total_pages:
}.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}

query = {
"page" => page_number,
"order" => order,
}.compact

stub_request(:get, url)
.with { |request| WebMock::Util::QueryMapper.query_to_values(request.uri.query) == query }
.to_return(body: {
"content_id" => SecureRandom.uuid,
"total" => total,
"total_pages" => total_pages,
"results" => results,
}.to_json)
end

# This method has been refactored into publishing_api_has_content (above)
# publishing_api_has_content allows for flexible passing in of arguments, please use instead
def stub_publishing_api_has_fields_for_document(document_type, items, fields)
Expand Down
2 changes: 1 addition & 1 deletion lib/gds_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GdsApi
VERSION = "97.2.0".freeze
VERSION = "97.3.0".freeze
end

0 comments on commit 0062147

Please sign in to comment.