Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batch-api can return response #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/facebook_ads/batch_api/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def <<(api_req)

def execute
return [] if operations.empty?
operations.each_slice(50) do |slice|
operations.each_slice(50).map do |slice|
api_response = APIRequest.new(:post, '', session: session, params: batch_args(slice)).execute_now
self.last_api_response = api_response
slice.zip(api_response.result).map do |req, res|
Expand Down
33 changes: 33 additions & 0 deletions spec/facebook_ads/batch_api/batch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

RSpec.describe FacebookAds::Batch do
describe "#execute" do
let(:expected_api_response) do
status = 200
headers = { content_type: "application/json" }
body = [
{
"code" => status,
"headers": headers.map { |k, v| { name: k, value: v } },
"body" => { "id" => "act_123456", "name" => "test account name" }
}
].to_json
FacebookAds::APIResponse.new(status, headers, body)
end
before do
expect_any_instance_of(FacebookAds::APIRequest).to receive(:execute_now).and_return(expected_api_response)
end

it do
batch = FacebookAds::Batch.with_batch do
FacebookAds::AdAccount.get("act_123456").name
end
batch_api_responses = batch.execute
api_responses = batch_api_responses.first
api_response = api_responses.first

expect(api_response).to be_a FacebookAds::AdAccount
expect(api_response).to match have_attributes(id: "act_123456", name: "test account name")
end
end
end