Skip to content

Commit

Permalink
Added ability to specify fileds on business_profile API
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacio-chiazzo committed Feb 4, 2024
1 parent 7b83272 commit f1428fa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/whatsapp_sdk/api/business_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ class BusinessProfile < Request
#
# @param phone_number_id [Integer] Phone Number Id.
# @return [Api::Response] Response object.
sig { params(phone_number_id: Integer).returns(Api::Response) }
def details(phone_number_id)
sig { params(phone_number_id: Integer, fields: T.nilable(T::Array[String])).returns(Api::Response) }
def details(phone_number_id, fields: nil)
fields = if fields
fields.join(',')
else
DEFAULT_FIELDS
end

response = send_request(
http_method: "get",
endpoint: "#{phone_number_id}/whatsapp_business_profile?fields=#{DEFAULT_FIELDS}"
endpoint: "#{phone_number_id}/whatsapp_business_profile?fields=#{fields}"
)

Api::Response.new(
Expand Down
26 changes: 26 additions & 0 deletions test/whatsapp/api/business_profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@ def test_details_handles_error_response
assert_mock_error_response(mocked_error_response, response, Responses::MessageErrorResponse)
end

def test_details_accepts_fields
fields = %w[about address]
phone_number_id = 123_456
@business_profile_api.stubs(:send_request)
.with(
http_method: "get",
endpoint: "#{phone_number_id}/whatsapp_business_profile?fields=about,address"
).returns(valid_details_response)

response = @business_profile_api.details(phone_number_id, fields: fields)
assert_business_details_mock_response(valid_detail_response, response)
end

def test_details_sends_all_fields_by_default
fields = "about,address,description,email,profile_picture_url,websites,vertical"
phone_number_id = 123_456
@business_profile_api.stubs(:send_request)
.with(
http_method: "get",
endpoint: "#{phone_number_id}/whatsapp_business_profile?fields=#{fields}"
).returns(valid_details_response)

response = @business_profile_api.details(phone_number_id)
assert_business_details_mock_response(valid_detail_response, response)
end

def test_details_with_success_response
mock_business_profile_response(valid_details_response)
response = @business_profile_api.details(123_123)
Expand Down

0 comments on commit f1428fa

Please sign in to comment.