Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarrero committed Jul 31, 2023
1 parent 254c793 commit 4cc5597
Show file tree
Hide file tree
Showing 17 changed files with 856 additions and 76 deletions.
168 changes: 155 additions & 13 deletions spec/api/customers_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# unit tests for create_customer
# Create customer
# The purpose of business is to create and keep a customer, you will learn what elements you need to create a customer. Remember the credit and debit card tokenization process: [https://developers.conekta.com/page/web-checkout-tokenizer](https://developers.conekta.com/page/web-checkout-tokenizer)
# The purpose of business is to create and keep a customer, you will learn what elements you need to create a customer. Remember the credit and debit card tokenization process: [https://developers.conekta.com/page/web-checkout-tokenizer](https://developers.conekta.com/page/web-checkout-tokenizer)
# @param customer requested field for customer
# @param [Hash] opts the optional parameters
# @option opts [String] :accept_language Use for knowing which language to use
Expand All @@ -42,12 +42,16 @@
describe 'create_customer test' do
it 'should work' do


customer = full_customer

response = @api_instance.create_customer(customer)

expect(response).to be_instance_of(Conekta::CustomerResponse)
expect(response.id).to be_truthy
expect(response.custom_reference).to eq(customer.custom_reference)
expect(response.fiscal_entities.data.length).to eq(1)
expect(response.fiscal_entities.has_more).to be_falsey
expect(response.livemode).to be_truthy
end
end

Expand All @@ -62,7 +66,23 @@
# @return [CreateCustomerFiscalEntitiesResponse]
describe 'create_customer_fiscal_entities test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = "cus_2tXyF9BwPG14UMkkg"
request = Conekta::CustomerFiscalEntitiesRequest.new({
address: Conekta::CustomerFiscalEntitiesRequestAddress.new({
street1: "av siem",
city: "mexico",
country: "MX",
postal_code: "11000",
external_number: "11544"
})
})

response = @api_instance.create_customer_fiscal_entities(id, request)

expect(response).to be_instance_of(Conekta::CreateCustomerFiscalEntitiesResponse)
expect(response.address.country).not_to eq(request.address.country)
expect(response.parent_id).to eq(id)
expect(response.id).to be_truthy
end
end

Expand All @@ -76,7 +96,12 @@
# @return [CustomerResponse]
describe 'delete_customer_by_id test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = "cus_2tXyF9BwPG14UMkkg"

response = @api_instance.delete_customer_by_id(id, { accept_language: 'es' })

expect(response).to be_instance_of(Conekta::CustomerResponse)
expect(response.id).to eq(id)
end
end

Expand All @@ -89,10 +114,24 @@
# @option opts [String] :x_child_company_id In the case of a holding company, the company id of the child company to which will process the request.
# @return [CustomerResponse]
describe 'get_customer_by_id test' do
it 'card' do
id = "cus_2tXx8KUxw6311kEbs"

response = @api_instance.get_customer_by_id(id, { accept_language: 'es' })

expect(response).to be_instance_of(Conekta::CustomerResponse)
expect(response.id).to eq(id)
expect(response.payment_sources.data.length).to eq(1)
expect(response.payment_sources.data.first).to be_instance_of(Conekta::PaymentMethodCardResponse)
expect(response.payment_sources.data.first.type).to eq('card')
expect(response.payment_sources.data.first.card_type).to eq('credit')
expect(response.subscription).not_to be_nil
expect(response.subscription.customer_id).to eq(id)
end
it 'cash' do
id = 'cus_2rGtVzg5V2KZrKXBh'

response = @api_instance.get_customer_by_id(id, {accept_language: 'es'})
response = @api_instance.get_customer_by_id(id, { accept_language: 'es' })

expect(response).to be_instance_of(Conekta::CustomerResponse)
expect(response.id).to eq(id)
Expand All @@ -102,6 +141,17 @@
expect(response.payment_sources.data.first.provider).to eq('Oxxo')
expect(response.payment_sources.data.first.object).to eq('payment_source')
end
it 'spei' do
id = "cus_2tYELwYTKSB5hDXsr"

response = @api_instance.get_customer_by_id(id, { accept_language: 'es' })

expect(response).to be_instance_of(Conekta::CustomerResponse)
expect(response.id).to eq(id)
expect(response.payment_sources.data.length).to eq(1)
expect(response.payment_sources.data.first).to be_instance_of(Conekta::PaymentMethodSpeiRecurrent)
expect(response.payment_sources.data.first.type).to eq('spei_recurrent')
end
end

# unit tests for get_customers
Expand All @@ -116,8 +166,32 @@
# @option opts [String] :previous previous page
# @return [CustomersResponse]
describe 'get_customers test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
it 'with limit' do
response = @api_instance.get_customers({ accept_language: 'es', limit: 21 })

expect(response).to be_instance_of(Conekta::CustomersResponse)
expect(response.next_page_url).to be_truthy
expect(response.previous_page_url).to be_falsey
expect(response.has_more).to be_truthy
expect(response.object).to eq('list')
end
it 'next' do
response = @api_instance.get_customers({ accept_language: 'es', limit: 22, _next: 'cus_2sthLBEZRLp2s6GWc' })

expect(response).to be_instance_of(Conekta::CustomersResponse)
expect(response.next_page_url).to be_truthy
expect(response.previous_page_url).to be_truthy
expect(response.has_more).to be_truthy
expect(response.object).to eq('list')
end
it 'previous' do
response = @api_instance.get_customers({ accept_language: 'es', limit: 23, previous: 'cus_2ss5YAeTKuEr5M4fD' })

expect(response).to be_instance_of(Conekta::CustomersResponse)
expect(response.next_page_url).to be_truthy
expect(response.previous_page_url).to be_falsey
expect(response.has_more).to be_falsey
expect(response.object).to eq('list')
end
end

Expand All @@ -132,7 +206,15 @@
# @return [CustomerResponse]
describe 'update_customer test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = "cus_2tYENskzTjjgkGQLt"
update_request = Conekta::UpdateCustomer.new({
email: '[email protected]'
})
response = @api_instance.update_customer(id, update_request)

expect(response).to be_instance_of(Conekta::CustomerResponse)
expect(response.email).to eq(update_request.email)
expect(response.id).to eq(id)
end
end

Expand All @@ -148,16 +230,76 @@
# @return [UpdateCustomerFiscalEntitiesResponse]
describe 'update_customer_fiscal_entities test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = "cus_2tYENskzTjjgkGQLt"
fiscal_entities_id = "fis_ent_2tYENskzTjjgkGQLr"
request = Conekta::CustomerUpdateFiscalEntitiesRequest.new({
tax_id: 'tax_28764234'
})
response = @api_instance.update_customer_fiscal_entities(id, fiscal_entities_id, request)

expect(response).to be_instance_of(Conekta::UpdateCustomerFiscalEntitiesResponse)
expect(response.tax_id).to eq(request.tax_id)
expect(response.parent_id).to eq(id)
expect(response.id).to eq(fiscal_entities_id)
end
end

def full_customer
customer = Conekta::Customer.new(
fiscal_entities = Array.new(1)
fiscal_entities[0] =
Conekta::CustomerFiscalEntitiesRequest.new({
address: Conekta::CustomerFiscalEntitiesRequestAddress.new({
street1: "av siempre viva",
street2: "condensa",
postal_code: "11011",
city: "cdmx mexico",
state: "cdmx mexico",
country: "mexico",
residential: true,
external_number: "avas3"
}),
company_name: "testing ca",
tax_id: "tax_23432",
email: "[email protected]",
phone: "+573143152012",
})

payment_sources = Array.new(1)
payment_sources[0] =
Conekta::PaymentMethodCardRequest.new({
type: 'card',
token_id: 'tok_2tXyExrU6U7yiaTto'
})
shipping_contacts = Array.new(1)
shipping_contacts[0] = Conekta::CustomerShippingContacts.new({
address: Conekta::CustomerShippingContactsAddress.new({
street1: "avenida siempre viva",
country: "mexico",
postal_code: "11011"
}),
phone: "+54874122144"
})

subscription = Conekta::SubscriptionRequest.new({
plan_id: "plan_2tXx672QLQ68CkmMn",
card_id: "card_2tXyExrU6U7yiaTto",
trial_end: 1679321468
})
Conekta::Customer.new(
{
name: 'test dot'
name: 'test dot',
phone: '+573143159063',
email: '[email protected]',
corporate: true,
plan_id: 'plan_2tXx672QLQ68CkmMn',
default_shipping_contact_id: "",
default_payment_source_id: "",
custom_reference: "dotnet_12345678",
fiscal_entities: fiscal_entities,
payment_sources: payment_sources,
shipping_contacts: shipping_contacts,
subscription: subscription
}
)

customer
end
end
49 changes: 44 additions & 5 deletions spec/api/discounts_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@
# @return [DiscountLinesResponse]
describe 'orders_create_discount_line test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = 'ord_2tVyWPnCPWbrV37mW'
request = Conekta::OrderDiscountLinesRequest.new({
amount: 500,
code: "track",
type: "loyalty"
})
response = @api_instance.orders_create_discount_line(id, request)

expect(response).to be_instance_of(Conekta::DiscountLinesResponse)
expect(response.parent_id).to eq(id)
expect(response.amount).to eq(request.amount)
end
end

Expand All @@ -58,7 +68,15 @@
# @return [DiscountLinesResponse]
describe 'orders_delete_discount_lines test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = 'ord_2tVyWPnCPWbrV37mW'
discount_line_id = 'dis_lin_2tVyahK8Nts7rKRMZ'

response = @api_instance.orders_delete_discount_lines(id, discount_line_id)

expect(response).to be_instance_of(Conekta::DiscountLinesResponse)
expect(response.parent_id).to eq(id)
expect(response.id).to eq(discount_line_id)

end
end

Expand All @@ -73,7 +91,13 @@
# @return [DiscountLinesResponse]
describe 'orders_get_discount_line test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = 'ord_2tkwrBmcvGnA9zdU9'
discount_line_id = 'dis_lin_2tkwrBmcvGnA9zdU6'
response = @api_instance.orders_get_discount_line(id, discount_line_id)

expect(response).to be_instance_of(Conekta::DiscountLinesResponse)
expect(response.parent_id).to eq(id)
expect(response.id).to eq(discount_line_id)
end
end

Expand All @@ -91,7 +115,12 @@
# @return [GetOrderDiscountLinesResponse]
describe 'orders_get_discount_lines test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = 'ord_2tVyWPnCPWbrV37mW'
response = @api_instance.orders_get_discount_lines(id)

expect(response).to be_instance_of(Conekta::GetOrderDiscountLinesResponse)
expect(response.data.length).to eq(2)
expect(response.has_more).to be_falsey
end
end

Expand All @@ -107,7 +136,17 @@
# @return [DiscountLinesResponse]
describe 'orders_update_discount_lines test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id = 'ord_2tVyWPnCPWbrV37mW'
discount_lines_id = 'dis_lin_2tVyahK8Nts7rKRMZ'
request = Conekta::UpdateOrderDiscountLinesRequest.new({
amount: 100
})

response = @api_instance.orders_update_discount_lines(id, discount_lines_id, request)

expect(response).to be_instance_of(Conekta::DiscountLinesResponse)
expect(response.parent_id).to eq(id)
expect(response.id).to eq(discount_lines_id)
end
end

Expand Down
23 changes: 20 additions & 3 deletions spec/api/events_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
# @return [EventResponse]
describe 'get_event test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
id= '63fe3d2ddf70970001cfb41a'
response = @api_instance.get_event(id, {accept_language: 'en'})

expect(response).to be_instance_of(Conekta::EventResponse)
expect(response.id).to eq(id)
expect(response.webhook_logs.length).to eq(1)
end
end

Expand All @@ -58,7 +63,12 @@
# @return [GetEventsResponse]
describe 'get_events test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
response = @api_instance.get_events({accept_language: 'es'})

expect(response).to be_instance_of(Conekta::GetEventsResponse)
expect(response.has_more).to be_truthy
expect(response.previous_page_url).to be_nil
expect(response.next_page_url).not_to be_nil
end
end

Expand All @@ -72,7 +82,14 @@
# @return [EventsResendResponse]
describe 'resend_event test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
event_id= '6463d6e35a4c3e001819e760'
webhook_log_id= 'webhl_2svd2sh6GbqzyWBNZ'

response = @api_instance.resend_event(event_id, webhook_log_id)

expect(response).to be_instance_of(Conekta::EventsResendResponse)
expect(response.id).to eq(webhook_log_id)
expect(response.last_http_response_status).to eq(405)
end
end

Expand Down
5 changes: 0 additions & 5 deletions spec/api/logs_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
describe 'LogsApi' do
before do
# run before each test
Conekta.configure do |config|
config.host = BaseTest.host
config.access_token = 'key_xxxxxx'
config.scheme = 'http'
end
@api_instance = Conekta::LogsApi.new
end

Expand Down
Loading

0 comments on commit 4cc5597

Please sign in to comment.