Skip to content

Commit 2a0d328

Browse files
committed
interim commit
1 parent 44b532f commit 2a0d328

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

Rakefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,19 @@ RuboCop::RakeTask.new
1111

1212
task default: %i[test]
1313

14-
task lint: %i[rubocop]
14+
task lint: %i[rubocop]
15+
16+
# Legacy tests task
17+
Minitest::TestTask.create(:legacy_test) do |t|
18+
t.libs << "test"
19+
t.test_globs = ["test/square_legacy/**/*_test.rb"]
20+
end
21+
22+
# Integration tests
23+
task :integration_test do
24+
integration_test_files = Dir.glob("test/square/integration/**/*.rb").sort
25+
cmd = "ruby -Ilib:test:. -w -e 'require \"minitest/autorun\"; "
26+
cmd += integration_test_files.map { |f| "require \"#{f}\"" }.join("; ")
27+
cmd += "'"
28+
sh cmd
29+
end

lib/square/customers/client.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ def list(request_options: {}, **params)
3737
#
3838
# @return [Square::Types::CreateCustomerResponse]
3939
def create(request_options: {}, **params)
40-
_request = params
41-
_response = @client.send(_request)
40+
_response = @client.send(Internal::JSON::Request.new(
41+
base_url: request_options[:base_url] || Square::Environment::SANDBOX,
42+
path: "/v2/customers",
43+
method: "POST",
44+
body: Types::CreateCustomerRequest.new(params[:request]).to_h,
45+
request_options: request_options
46+
))
4247
if _response.code >= "200" && _response.code < "300"
4348
return Square::Types::CreateCustomerResponse.load(_response.body)
4449
else
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
describe Square::Customers::Client do
6+
describe "#create and delete customer" do
7+
it "creates a customer" do
8+
9+
_request = Square::Customers::Types::CreateCustomerRequest.new(
10+
given_name: "Amelia",
11+
family_name: "Earhart",
12+
email_address: "Amelia.Earhart@example.com",
13+
address: {
14+
address_line_1: "500 Electric Ave",
15+
address_line_2: "Suite 600",
16+
locality: "New York",
17+
administrative_district_level_1: "NY",
18+
postal_code: "10003",
19+
country: "US"
20+
},
21+
phone_number: "+1-212-555-4240",
22+
reference_id: "YOUR_REFERENCE_ID",
23+
note: "a customer"
24+
)
25+
26+
puts "create customer request #{_request.to_h}" if verbose?
27+
28+
response = client.customers.create(request: _request.to_h)
29+
refute_nil response
30+
assert_equal response.class, Square::Types::CreateCustomerResponse
31+
refute_nil response.customer.id
32+
refute_nil response.customer.version
33+
puts "create customer response #{response.to_h}" if verbose?
34+
35+
_request = Square::Customers::Types::DeleteCustomerRequest.new(
36+
customer_id: response.customer.id,
37+
version: response.customer.version
38+
)
39+
40+
puts "delete customer request #{_request.to_h}" if verbose?
41+
42+
response = client.customers.delete(request: _request.to_h)
43+
refute_nil response
44+
assert_equal response.class, Square::Types::DeleteCustomerResponse
45+
puts "delete customer response #{response.to_h}" if verbose?
46+
end
47+
end
48+
end

test/square/integration/integration_test_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'minitest/hell'
44
require 'minitest/pride'
55
require 'minitest/proveit'
6-
require_relative 'test_helper'
6+
require 'test_helper'
77

88
class IntegrationTestBase < Minitest::Test
99
parallelize_me!

0 commit comments

Comments
 (0)