diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..30ee8c0 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,31 @@ +name: Github workflow gem develop + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6 + with: + ruby-version: 2.7 + - run: bundle install + - name: Rubocop + run: rubocop + test: + needs: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6 + with: + ruby-version: 2.7 + - name: Bundle install + run: bundle install + - name: Gem build + run: gem build + - name: Gem install + run: gem install konduto-ruby --local konduto-ruby-*.gem + - name: Run Tests + run: rake test \ No newline at end of file diff --git a/.gitignore b/.gitignore index db43a3a..18a2fad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .idea/ +*/**/coverage/ +/coverage/ *.gem + diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..ce8310e --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,25 @@ +plugins: rubocop-minitest + +AllCops: + SuggestExtensions: false + +Naming/VariableName: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/PerceivedComplexity: + Enabled: false +Style/Documentation: + Enabled: false +Style/GuardClause: + Enabled: false +Naming/FileName: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Naming/PredicatePrefix: + Enabled: false \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..49c800e --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# Specify your gem's dependencies in konduto-ruby.gemspec +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..0575b8b --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,97 @@ +PATH + remote: . + specs: + konduto-ruby (2.2.0) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (7.1.5.1) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + mutex_m + securerandom (>= 0.3) + tzinfo (~> 2.0) + ast (2.4.3) + base64 (0.3.0) + benchmark (0.4.1) + bigdecimal (3.2.2) + concurrent-ruby (1.3.5) + connection_pool (2.5.3) + docile (1.4.1) + drb (2.2.3) + factory_bot (6.4.5) + activesupport (>= 5.0.0) + i18n (1.14.7) + concurrent-ruby (~> 1.0) + json (2.13.1) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + logger (1.7.0) + minitest (5.25.5) + mutex_m (0.3.0) + parallel (1.27.0) + parser (3.3.9.0) + ast (~> 2.4.1) + racc + prism (1.4.0) + racc (1.8.1) + rainbow (3.1.1) + rake (13.3.0) + regexp_parser (2.10.0) + rubocop (1.79.0) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.46.0, < 2.0) + ruby-progressbar (~> 1.7) + tsort (>= 0.2.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.46.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-minitest (0.38.1) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) + ruby-progressbar (1.13.0) + securerandom (0.3.2) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.2) + simplecov_json_formatter (0.1.4) + tsort (0.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (3.1.4) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + +PLATFORMS + ruby + x64-mingw32 + +DEPENDENCIES + factory_bot (~> 6.4) + konduto-ruby! + minitest (~> 5.25) + rake (~> 13.3.0) + rubocop (~> 1.79) + rubocop-minitest (~> 0.38.1) + simplecov (~> 0.22.0) + +BUNDLED WITH + 2.1.4 diff --git a/README.md b/README.md index 575d58d..1dede2e 100644 --- a/README.md +++ b/README.md @@ -69,107 +69,352 @@ order.customer = customer ### Order parameters -Parameter | Description ---- | --- -id | _(required)_ Unique identifier for each order. -visitor | _(required)_ Visitor identifier obtained from our JavaScript snippet. -total_amount | _(required)_ Total order amount. -shipping_amount | _(optional)_ Shipping and handling amount. -tax_amount | _(optional)_ Taxes amount. -currency | _(optional)_ Currency code with 3 letters (ISO-4712). -installments | _(optional)_ Number of installments in the payment plan. -ip | _(optional)_ Customer's IPv4 address. -customer | _(required)_ Object containing the customer details. -payment | _(optional)_ Array containing the payment methods. -billing | _(optional)_ Object containing the billing information. -shipping | _(optional)_ Object containing the shipping information. -shopping_cart | _(optional)_ Array containing the items purchased. -analyze | _(optional)_ A boolean indicating if the order should be analyzed. Defaults to **true**. -first_message | _(optional)_ Time when the first message was exchanged between customer and seller. -messages_exchanged | _(optional)_ Number of messages exchanged between customer and seller. -purchased_at | _(optional)_ Time when the customer purchased from the seller. - -#### Customer information - -Parameter | Description ---- | --- -id | _(required)_ **Unique** identifier for each customer. Can be anything you like (counter, id, e-mail address) as long as it's consistent in future orders. -name | _(required)_ Customer's full name. -email | _(required)_ Customer's e-mail address -tax_id | _(optional)_ Customer's tax id. -phone1 | _(optional)_ Customer's primary phone number -phone 2 | _(optional)_ Customer's secondary phone number -new | _(optional)_ Boolean indicating if the customer is using a newly created account for this purchase. -vip | _(optional)_ Boolean indicating if the customer is a VIP or frequent buyer. -created_at | _(optional)_ Date when customer was created. - - -#### Payment information - -Parameter | Description ---- | --- -status | _(required)_ The status of the transaction returned by the payment processor. Accepts `approved`, `declined` or `pending` if the payment wasn't been processed yet. -bin | _(optional)_ First six digits of the customer's credit card. Used to identify the type of card being sent. -last4 | _(optional)_ Four last digits of the customer's credit card number. -expiration_date | _(optional)_ Card's expiration date under MMYYYY format. - - -#### Billing address - -Parameter | Description ---- | --- -name | _(optional)_ Cardholder's full name. -address1 | _(optional)_ Cardholder's billing address on file with the bank. -address2 | _(optional)_ Additional cardholder address information. -city | _(optional)_ Cardholder's city. -state | _(optional)_ Cardholder's state. -zip | _(optional)_ Cardholder's ZIP code. -country | _(optional)_ Cardholder's country code (ISO 3166-2) - - -#### Shipping address - -Parameter | Description ---- | --- -name | _(optional)_ Recipient's full name. -address1 | _(optional)_ Recipient's shipping address. -address2 | _(optional)_ Additional recipient address information. -city | _(optional)_ Recipient's city. -state | _(optional)_ Recipient's state. -zip | _(optional)_ Recipient's ZIP code. -country | _(optional)_ Recipient's country code (ISO 3166-2) - - -#### Shopping cart - -Parameter | Description ---- | --- -sku | _(optional)_ Product or service's SKU or inventory id. -product_code | _(optional)_ Product or service's UPC, barcode or secondary id. -category | _(optional)_ Category code for the item purchased. [See here](http://docs.konduto.com/#n-tables) for the list. -name | _(optional)_ Name of the product or service. -description | _(optional)_ Detailed description of the item. -unit_cost | _(optional)_ Cost of a single unit of this item. -quantity | _(optional)_ Number of units purchased. -discount | _(optional)_ Discounted amount for this item. -created_at | _(optional)_ Date when this item was created. +| Parameter | Description | +| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| id | (required) Unique identifier for each order.Max. 100 chars, alpha-numeric. | +| visitor | (optional) Visitor identifier obtained from our JavaScript.Max. 40 chars, alpha-numeric. | +| total_amount | (required) Total order amount.Max. 10 chars, number. | +| shipping_amount | (optional) Shipping amount.Max. 10 chars, number. | +| tax_amount | (optional) Tax amount.Max. 10 chars, number. | +| currency | (optional) 3-letter currency code (ISO-4712).Max. 3 chars, string. | +| installments | (optional) Number of payment installments.Max. 3 chars, number. | +| ip | (optional) Client IPv4 address. Ex: IPV4 - 189.68.156.100 Max. 15 chars, string. IPV6 address customer (without abbreviations). Ex: IPV6 - 2001:0DB8:AD1F:25E2:CADE:CAFE:F0CA:84C1 String. | +| first_message | (optional) In the Marketplace, it brings the date and time of the first message exchanged between buyer and seller. YYYY-MM-DDTHH:mm:ssZ format (ISO 8601).Max. 20 chars, string. | +| messages_exchanged | (optional) In the Marketplace, it must bring the number of messages exchanged between buyer and seller until the moment of the transaction.Number. | +| purchase_at | (optional) In the Marketplace, it brings the date and time of the order closing on the website. YYYY-MM-DDTHH:mm:ssZ format (ISO 8601)Exactly 20 chars, string. | +| recurring | (optional) Indicates whether the order is recurring. | +| risk_level | (recommended) Indicates the order risk level. Supported values are: low, medium and high. String. | +| analyze | (optional) If false the system will take the transaction into account in the next reviews but does not return a recommendation and you are not charged.Boolean. If not sent the default is true. | +| sales_channel | (optional) Sales channel identifier. Max. 100 chars, string. | +| customer | (required) Object containing customer details. | +| payment | (optional) List containing payment methods. | +| billing | (optional) Object containing the billing address. | +| shipping | (optional) Object containing the delivery address. | +| shopping_cart | (optional) List containing the purchased items. | +| hotel | (optional) Object containing hotel and guest data. | +| travel | (optional) Object containing travel and passenger data. | +| seller | (optional) Object intended for the data of the product seller. | +| events | (optional) List of events promoted by the store. | +| scheduled | (optional) FOR PIX/SAFEBANKING. Indicates if a transaction is recurring. Default is false. | +| origin_account | (optional) FOR PIX/SAFEBANKING. Object containing origin account data. | +| destination_accounts | (optional) FOR PIX/SAFEBANKING. List of destination accounts. | +| tenant | (optional) FOR PIX/SAFEBANKING. Object containing data about the platform where the transaction is occurring. | +| point_of_sale | (optional) Object containing data about the physical point of sale. | +| agent | (optional) Object containing the details of the seller at the physical point of sale. | + +### Customer information + +| Parameter | Description | +| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| id | (required) Unique customer identifier. It can be any value (sequential, document, email) as long as it is consistent with future orders.Max. 100 chars, string. | +| name | (required) Customer's full name.Max. 100 chars, string. | +| email | (required) Customer’s e-mail address.Max. 100 chars, string. | +| dob | (optional) Customer's date of birth in YYYY-MM-DD format (ISO 8601).Max. 10 chars, string. | +| tax_id | (optional) Customer’s tax document number (CPF, CNPJ, etc).Max. 100 chars, string. | +| document_type | (recommended) Type of customer’s tax document (CPF, CNPJ, RG, PASSPORT, OTHER, CPF_CNPJ).Max. 100 chars, string. | +| phone1 | (optional) Primary customer’s phone number.Max. 100 chars, string. | +| phone2 | (optional) Secondary customer’s phone number.Max. 100 chars, string. | +| created_at | (optional) Date of customer’s account creation or registration on the website, in YYYY-MM-DD format (ISO 8601).Max 10 chars, string. | +| new | (optional) Flag indicating whether the customer is using a newly created account on this purchase.Boolean. | +| vip | (optional) Flag indicating whether this is a VIP customer or a frequent buyer.Boolean. | +| type | (optional) Customer type identifier.String. | +| risk_level | (optional) Risk level identifier. We currently use low, medium, high.String. | +| risk_score | (optional) Customer risk score identifier.Number. | +| mother_name | (optional) Full name of the client's mother.Max. 100 chars, string | + +### Payment information + +| Parameter | Description | +| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| type | (required) Payment method used by the customer. We currently support `credit`, `boleto`, `debit`, `transfer `and `voucher`.Max. 8 chars, string. | +| status | (required) The payment status returned by the card operator. It can be `approved` (approved), `declined` (declined) or `pending`(pending), if payment has not yet been made.Max. 8 chars, string.This field should only be sent for the payment type `payment.type=credit` | +| bin | (optional) The first six credit card numbers are used to identify the type of card used.Max. 6 chars, string.This field should only be sent for the payment type `payment.type=credit` | +| last4 | (optional) The last four digits of the credit card.Max. 4 chars, string.This field should only be sent for the payment type `payment.type=credit` | +| amount | (required) Total order amount.Max. 10 chars, number. | +| expiration_date | (optional) Card’s expiration date in MMYYYY format.Max. 6 chars, string.This field should only be sent for the payment type `payment.type=credit` | +| description | (optional) Some information regarding the discount..Max. 100 chars, string. | +| tax_id | (recommended) Cardholder's tax document (CPF). Max. 100 chars, string. | +| cvv_result | (recommended) CVV verification result code. Max. 4 chars, string. This field should only be sent for the payment type `payment.type=credit` or `payment.type=debit`. | +| avs_result | (recommended) AVS verification result code. Max. 4 chars, string. This field should only be sent for the payment type `payment.type=credit` or `payment.type=debit`. | +| sha1 | (recommended) Payment integrity code (an HMAC-SHA-256 of the notification fields). This field should only be sent for the payment type `payment.type=credit` or `payment.type=debit`. | +| name | (optional) Buyer's name. Max. 100 chars, string. | +| holder | (optional) Cardholder's name. Max. 100 chars, string. | + +### Billing address + +| Parameter | Description | +| --------- | --------------------------------------------------------------------------- | +| name | (optional) Cardholder’s name.Max. 100 chars, string. | +| address1 | (optional) Customer’s invoice address with the bank.Max. 255 chars, string. | +| address2 | (optional) Complement of the invoice address.Max. 255 chars, string. | +| city | (optional) Cardholder’s city.Max. 100 chars, string. | +| state | (optional) Cardholder’s stateMax. 100 chars, string. | +| zip | (optional) Cardholder’s Zip Code.Max. 100 chars, string. | +| country | (optional) Cardholder’s country code. (ISO 3166-2).Max. 2 chars, string. | + + +### Shipping address + +| Parameter | Description | +| -------------- | ----------------------------------------------------------------------------------------------------------- | +| name | (optional) Cardholder’s name.Max. 100 chars, string. | +| address1 | (optional) Customer’s invoice address with the bank.Max. 255 chars, string. | +| address2 | (optional) Complement of the invoice address.Max. 255 chars, string. | +| city | (optional) Customer’s city.Max. 100 chars, string. | +| state | (optional) Customer’s status.Max. 100 chars, string. | +| zip | (optional) Customer’s zip code.Max. 100 chars, string. | +| country | (optional) Customer’s country code. (ISO 3166-2) .Max. 2 chars, string. | +| estimated_date | (optional) Estimated shipping date. Formatted as AAAA-MM-DDTHH:mm:ssZ (ISO 8601). Exactly 20 chars, string. | +| value | (optional) Shipping amount. Number. | -### Seller +### Delivery -Parameter | Description ---- | --- -id | _(required)_ Seller's id -name | _(optional)_ Sellers's name -created_at | _(optional)_ Date when the seller was created +| Parameter | Description | +| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | +| delivery_company | (recommended) Adds the name of the company that will deliver the product to the customer. Example: `GFL` String, up to 100 chars. | +| delivery_method | (recommended) Details the type of withdrawal type, if applicable. Example: `retire_loja` String, up to 100 chars. | +| estimated_shipping_date | (recommended) Informs the estimated delivery date of the product. Example: `2021-05-06` String, format YYYY-MM-DDThh:mmZ (ISO 8601) | +| estimated_delivery_date | (recommended) Informs the estimated date of withdrawal of the product. Example: `2021-05-06` String, format YYYY-MM-DDThh:mmZ (ISO 8601) | + +### External device + +| Parameter | Description | +| ------------ | ----------------------------------------------------------------------- | +| fingerprint | (required) Browser identification. Max. 255 e min. 3, string | +| provider | (recommended) Provider type. Max. 225 e min. 2 chars, string. | +| category | (recommended) Category type. Max. 225 e min. 2 chars, string. | +| model | (recommended) Type of model used. Max. 225 chars, string. | +| platform | (recommended) Device type by customer. Max. 225 e min. 2 chars, string. | +| manufacturer | (recommended) Which Manufacturer. Max. 225 e min. 2 chars, string. | +| os | (recommended) What Operating System. Max. 225 e min. 2 chars, string. | +| browser | (recommended) Which browser. Max. 225 e min. 2 chars, string. | +| language | (recommended) Language used. Max 255, string. | + +### Shopping cart + +| Parameter | Description | +| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| sku | (recommended) SKU or inventory number of the product or service. Max. 100 chars, string. | +| product_code | (recommended) Barcode or UPC product or service. Max. 100 chars, string. | +| category | (recommended) Category code of the product purchased. See our [list of categories](https://docs.konduto.com/reference/categorias-de-produtos-e-c%C3%B3digos) for more information. Max. 4 chars, number. | +| name | (recommended) Product or service name. Max. 100 chars, string. | +| description | (recommended) Detailed description of the product or service. Max. 100 chars, string. | +| unit_cost | (recommended) Unit cost of this product or service. Max. 10 chars, number. | +| quantity | (recommended) Number of units purchased. Max. 10 chars, number. | +| discount | (recommended) Product discount value. Max. 10 chars, number. | +| created_at | (recommended) Date of publication of the product on the website, in YYYY-MM-DD format. (ISO 8601). Max. 10 chars, string. | +| delivery_type | (optional) Delivery type. Max. 255 chars, string. | +| delivery_sla_in_minutes | (optional) Estimated delivery time in minutes. Min. 0 and max. 9999999999. Number. | +| seller_id | (optional) Seller identifier. Max. 255 chars, string. | + + +### Travel + +| Parameters | Description | +| --------------- | -------------------------------------------------------- | +| type | (required) Type of trip. Currently `flight` or `bus`. | +| expiration_date | (recommended) Expiration date. Datetime. | +| departure | (required) Object with departure information. | +| return | (recommended) Object with the return travel information. | +| passengers | (required) Array of objects with passengers’ data. | + +#### Departure/return + +| Parameter | Description | +| --------------------- | ---------------------------------------------------------------------------------------------------------- | +| origin_city | (required if type=bus) City of origin. Max 100 chars, string. | +| destination_city | (required if type=bus) Destination city. Max 100 chars, string. | +| origin_airport | (required if type=flight) IATA airport code to the airport of origin. Exactly 3 chars, string. | +| destination_airport | (required if type=flight) IATA airport code to the airport of destiny. Exactly 3 chars, string. | +| date | (required) Date and time of boarding in UTC in YYYY-MM-DDThh:mmZ format (ISO 8601). Max. 17 chars, string. | +| number_of_connections | (recommended) Number of connections .Integer. | +| class | (recommended) Class name, such as `economy`, `business` and `first`. Max. 8 chars, string. | +| fare_basis | (recommended) Class code. Max 20 chars, string. | +| company | (recommended) Name of the airline company. Max. 255 chars, string. | + +#### Passenger + +| Parameter | Description | +| ----------------- | ----------------------------------------------------------------------------------------------- | +| name | (required) Passenger's full name. Max 100 chars, string. | +| document | (required) Document number. Max 100 chars, string. | +| document_type | (required) Document type. Can be `passport` or `id`. Max 8 chars, string. | +| dob | (recommended) Passenger's date of birth in YYYY-MM-DD format (ISO 8601). Max. 10 chars, string. | +| nationality | (recommended) Passenger's country of birth (ISO 3166-2). Max. 2 chars, string. | +| loyalty | (optional) Passenger's loyalty program. | +| frequent_traveler | (recommended) Flag of frequent traveler. Boolean, default is `false`. | +| special_needs | (recommended) Flag of frequent traveler. Boolean, default is `false`. | + +#### Loyalty + +| Parameter | Description | +| --------- | ---------------------------------------------------------------------- | +| program | Loyalty program type. Max. 255 chars, String Ex.: `smiles` | +| category | Loyalty program category. Max. 255 chars, String Ex.: `gold`, `silver` | + + +### Hotel + +| Parameter | Description | +| --------- | --------------------------------------------------------------------------------- | +| name | (required) Name of the hotel. Max. 100 chars, string. | +| address1 | (recommended) Hotel’s address. Max. 255 chars, string. | +| address2 | (recommended) Complement of the hotel’s address. Max. 255 chars, string. | +| city | (recommended) Hotel’s city. Max. 100 chars, string. | +| state | (recommended) Acronym for the hotel’ state. Max. 100 chars, string. | +| zip | (recommended) Hotel’s zip code. Max. 100 chars, string. | +| country | (recommended) Hotel’s country. Max. 2 chars, string. | +| category | (recommended) Hotel’s category. Max. 100 chars, string. | +| rooms | (required) Object with information about the hotel’s rooms. Max. 20 items, array. | + +#### Room + +| Parameter | Description | +| ---------------- | -------------------------------------------------------------------------------------------------------------- | +| number | (recommended) Room’s number. Max. 100 chars, string. | +| code | (recommended) Room’s code. Max. 100 chars, string. | +| type | (recommended) Room type. Max. 100 chars, string. | +| check_in_date | (required) Date and time of check-in in UTC in the YYYY-MM-DDThh:mmZ format (ISO 8601). Max. 17 chars, string. | +| check_out_date | (recommended) Date and time of check-out in UTC in the YYYY-MM-DDThh:mmZ (ISO 8601). Max. 17 chars, string. | +| number_of_guests | (recommended) Number of people. Max. 9999, number. | +| board_basis | (recommended) Feeding regime. Max. 100 chars, string. | +| guests | (required) Room guests. Max. 20 items, array. | + +#### Guest + +| Parameter | Description | +| ------------- | -------------------------------------------------------------------------------------------------------------------- | +| name | (required) Guest’s name. Max. 100 chars, string. | +| document | (recommended) Guest's document number. Max. 8 chars, string. | +| document_type | (recommended) Document used by the customer. We currently support `cpf`, `rg`, `passport`, `id` and `other`. string. | +| dob | (recommended) Customer's date of birth in YYYY-MM-DD format (ISO 8601). Max 10 chars, string. | +| nationality | (recommended) Guest’s nationality. Max. 2 chars, string. | + + +### Event + +| Parameter | Description | +| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| name | (required) Name of the event.Max. 255 chars, string. | +| date | (required) Date and time of the event in UTC in the YYYY-MM-DDThh:mmZ format (ISO 8601) Max. 17 chars, datetime, string. | +| type | (required) Type of the event. We currently support `show`, `theater`, `movies`, `party`, `festival`, `course`, `sports` and `corporate`string. | +| subtype | (optional) Detail of the event type.Max. 255 chars, string. | +| venue | (optional) Object with the location information of the event. | +| tickets | (optional) Array of objects with ticket data. | + +#### Venue + +| Parameter | Description | +| --------- | -------------------------------------------------------------------------- | +| name | (recommended) Place’s name. Max. 255 chars, string. | +| address | (recommended) Place’s address. Max. 255 chars, string. | +| city | (recommended) Place’s city. Max. 255 chars, string. | +| state | (recommended) Place’s state. Max. 100, string. | +| country | (recommended) Place’s country pursuant to ISO 3166-2. Max. 2 chars, string | +| capacity | (recommended) Place’s capacity. integer. | + +#### Ticket + +| Parameter | Note | +| --------- | --------------------------------------------------------------------------------------------------------------------------- | +| id | (recommended) Unique ticket identifier. Max. 255 chars, string. | +| category | (required) Ticket category. Actually supported values are `student`, `senior`, `government`, `social` and `regular`. string | +| section | (recommended) Ticket section. Max. 255 chars, string. | +| premium | (required) Indicates if the ticket is premium, receive only `true` or `false`. boolean. | +| attendee | (required) Array of objects with attendee data. | + +#### Attendee + +| Parameter | Note | +| ------------- | ----------------------------------------------------------------------------------------------------------------- | +| name | (recommended) Attendee's name. Max. 255 chars, string. | +| document | (required) Attendee's document. Max. 100 chars, string. | +| document_type | (recommended) Attendee's document type. We currently support `cpf`, `cnpj`, `rg`, `passport` and `other`. string. | +| dob | (recommended) Attendee's date of birth in UTC in the YYYY-MM-DD format (ISO 8601). Max. 17 chars, string. | + +### Vehicle + +| Parâmetro | Descrição | +| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | +| vid | (recommended) Vehicle's unique identifier. Max. Min. 17 chars, string. | +| renavam | (recommended) Renavan identification of the vehicle. Max. 11 chars, string. | +| registration | (recommended) Vehicle licence. Max. 15 chars, string. | +| make | (required) Vehicle brand. Max. 63 chars, string. | +| model | (required) Vehicle model. Max. 100 chars, string. | +| owner | (required) Array for vehicle owners information. | +| type | (recommended) Vehicle type. Valid options are: `car`, `bus`, `truck`, `motorcycle`, `aircraft`, `boat`, `bicycle`. Max. 15 chars, string. | +| usage | (recommended) Vehicle usage. Accepts values like: `private`, `commercial`, `experimental`, `government`, `military`, `instruction`. String | + +##### Owner + +| Parâmetro | Descrição | +| --------- | ----------------------------------------------------------- | +| name | (recommended) Vehicle owner's name. Max 255 chars, string. | +| tax_id | (required) Vehicle owner's document. Max 100 chars, string. | -### Delivery +### Seller -Parameter | Description ---- | --- -delivery_company | _(required)_ Name of the company that will deliver the product -delivery_method | _(optional)_ Delivery Method -estimated_shipping_date | _(optional)_ Estimated product shipping date -estimated_delivery_date | _(optional)_ Estimated product delivery date +| Parameter | Description | +| ---------- | ----------------------------------------------------------------------------------------------------------------------- | +| id | (required) Unique identifier of the seller within the Marketplace. Max. 100 chars, string. | +| name | (recommended) Store or seller’s name. Max. 100 chars, string. | +| created_at | (recommended) Date of creation of the store in the Marketplace, in YYYY-MM-DD format (ISO 8601). Max. 10 chars, string. | + +### Point of sale + +| Parameter | Description | +| --------- | ------------------------------------------------------------------------------------------------------------------------ | +| id | (required) Unique identifier of the physical store. Max. 100 chars, string. | +| name | (required) Full name of the physical store. Max. 100 chars, string. | +| lat | (recommended) Latitude of the physical store. We currently use maximum: -90, maximum: 90. Max. 10 characters, number. | +| long | (recommended) Longitude of the physical store. We currently use maximum: -180, maximum: 180. Max. 10 characters, number. | +| address | (recommended) Physical store's address. Max. 255 chars, string. | +| city | (recommended) Physical store's city. Max. 100 chars, string. | +| state | (recommended) Physical store's state. Max. 100 chars, string. | +| zip | (recommended) Physical store's zip code. Max. 100 chars, string. | +| country | (recommended) Country code of store's holder (ISO 3166-2). Max. 2 chars, string. | + +### Agent + +| Parameter | Description | +| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | +| id | (required) Seller's unique identifier. Max. 100 chars, string. | +| login | (recommended) Seller's login. Max. 100 chars, string. | +| name | (required) Seller's full name. Max. 100 chars, string. | +| tax_id | (recommended) Seller's tax document number (CPF, etc). Max. 100 chars, string. | +| dob | (recommended) Seller's date of birth in YYYY-MM-DD format (ISO 8601). Max. 10 chars, string. | +| category | (recommended) Category code of the product sold. Max. 100 chars, string. | +| created_at | (recommended) Date of creation of the account or registration of the seller on the website, in YYYY-MM-DD format (ISO 8601). Max 10 chars, string. | + + +### Origin account + +| Parameter | Description | +| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | +| id | (recommended) Account's unique identifier. Max. 255 chars, string. | +| key_type | (recommended) Type of key used to identify the account. We currently support `pix_cpf`, `pix_cnpj`, `pix_phone`, `pix_email`, `pix_evp`, `p2p` and `none`. | +| key_value | (recommended) Key used to identify the account. Max. 255 chars, string. | +| holder_name | (recommended) Name of the account holder. Max. 255 chars, string. | +| holder_tax_id | (recommended) CPF/CNPJ of the account holder. Max. 255 chars, string. | +| bank_code | (recommended) Code of the bank to which the account is linked. Max. 255 chars, string. | +| bank_name | (recommended) Name of the bank to which the account is linked. Max. 255 chars, string. | +| bank_branch | (recommended) Bank branch to which the account is linked. Max. 255 chars, string. | +| bank_account | (recommended) Account number. Max. 255 chars, string. | +| balance | (recommended) Current account balance. Number. | + +### Destination account + +| Parameter | Description | +| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | +| id | (recommended) Account's unique identifier. Max. 255 chars, string. | +| key_type | (recommended) Type of key used to identify the account. We currently support `pix_cpf`, `pix_cnpj`, `pix_phone`, `pix_email`, `pix_evp`, `p2p` and `none` | +| key_value | (recommended) Key used to identify the account. Max. 255 chars, string. | +| holder_name | (recommended) Name of the account holder. Max. 255 chars, string. | +| holder_tax_id | (recommended) CPF/CNPJ of the account holder. Max. 255 chars, string. | +| bank_code | (recommended) Code of the bank to which the account is linked. Max. 255 chars, string. | +| bank_name | (recommended) Name of the bank to which the account is linked. Max. 255 chars, string. | +| bank_account | (recommended) Account number. Max. 255 chars, string. | +| amount | (recommended) Amount sent to the account. Number. | ## Sending an order for analysis. @@ -214,10 +459,10 @@ order = konduto.get_order order_id # orderId is a String konduto.update_order_status(order, new_status, 'some comments'); ``` -Parameter | Description ---- | --- -status | _(required)_ New status for this transaction. Either `approved`, `declined` or `fraud`, when you have identified a fraud or chargeback. -comments | _(required)_ Reason or comments about the status update. +| Parameter | Description | +| --------- | --------------------------------------------------------------------------------------------------------------------------------------- | +| status | _(required)_ New status for this transaction. Either `approved`, `declined` or `fraud`, when you have identified a fraud or chargeback. | +| comments | _(required)_ Reason or comments about the status update. | ## Sending requests through a proxy To send requests through a proxy just build a new Konduto instance and set the proxy host passing the proxy url as parameters of `proxy=` method. If the proxy requires username and password, just set then at the proxy url you'll pass to `proxy=` method. diff --git a/Rakefile b/Rakefile index 6886192..4911758 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rake/testtask' Rake::TestTask.new do |t| @@ -6,5 +8,5 @@ Rake::TestTask.new do |t| t.verbose = true end -desc "Run tests" +desc 'Run tests' task default: :test diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..dc9f525 --- /dev/null +++ b/bin/console @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'bundler/setup' +require 'konduto-ruby' + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require 'irb' +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/build_and_install.sh b/build_and_install.sh new file mode 100755 index 0000000..9381fbd --- /dev/null +++ b/build_and_install.sh @@ -0,0 +1,6 @@ +#!/bin/sh +rvm use ruby-2.7.0@konduto-ruby +gem uninstall konduto-ruby +bundle install +gem build +gem install konduto-ruby --local konduto-ruby-2.2.0.gem \ No newline at end of file diff --git a/konduto-ruby.gemspec b/konduto-ruby.gemspec index 4c9d80b..95d25a7 100644 --- a/konduto-ruby.gemspec +++ b/konduto-ruby.gemspec @@ -1,16 +1,26 @@ +# frozen_string_literal: true + +require_relative 'lib/konduto-ruby' + Gem::Specification.new do |spec| spec.name = 'konduto-ruby' - spec.version = '2.1.2' + spec.version = KondutoRuby::VERSION spec.authors = ['Gabriel Custodio', 'Jonathan Cardoso de Campos', 'Konduto Development Team'] + spec.date = Time.now.utc.strftime('%Y-%m-%d') spec.email = [%(gcmartins93@gmail.com jonathancardosodecampos@gmail.com support@konduto.com)] spec.homepage = 'https://github.com/konduto/konduto-ruby' spec.summary = '' spec.description = 'A wrapper for konduto antifraud API' - - spec.files = Dir["{lib}/**/*.rb", "bin/*", "LICENSE", "*.md"] + spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0') + spec.files = Dir['{lib}/**/*.rb', 'LICENSE', '*.md'] spec.require_path = 'lib' - spec.license = 'MIT' - spec.add_development_dependency 'factory_girl', '~> 4.7' + # tests + spec.add_development_dependency 'factory_bot', '~> 6.4' + spec.add_development_dependency 'minitest', '~> 5.25' + spec.add_development_dependency 'rake', '~> 13.3.0' + spec.add_development_dependency 'rubocop', '~> 1.79' + spec.add_development_dependency 'rubocop-minitest', '~> 0.38.1' + spec.add_development_dependency 'simplecov', '~> 0.22.0' end diff --git a/lib/konduto-ruby.rb b/lib/konduto-ruby.rb index 90a1de6..608eaf3 100644 --- a/lib/konduto-ruby.rb +++ b/lib/konduto-ruby.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'json' require 'date' -require 'konduto-ruby/konduto_base' -require 'konduto-ruby/konduto_travel_leg' +require_relative 'konduto-ruby/konduto_base' +require_relative 'konduto-ruby/konduto_travel_leg' -Dir[__dir__ + '/konduto-ruby/*.rb'].each { |file| require file } +Dir["#{__dir__}/konduto-ruby/*.rb"].sort.each { |file| require file } class KondutoRuby require 'uri' @@ -12,95 +14,103 @@ class KondutoRuby attr_accessor :request_body, :response_body, :endpoint attr_reader :api_key - def initialize api_key, endpoint = 'https://api.konduto.com/v1' + VERSION = '2.2.0' + + def initialize(api_key, endpoint = 'https://api.konduto.com/v1') @endpoint = URI.parse(endpoint) @http_client = Net::HTTP.new(@endpoint.host, @endpoint.port) @api_key = api_key end - def api_key= api_key + def api_key=(api_key) if api_key.length == 21 @api_key = api_key else - raise ArgumentError.new "Invalid key: #{api_key}! API key length must be of 21" + raise ArgumentError, "Invalid key: #{api_key}! API key length must be of 21" end end def proxy return @proxy if @proxy - URI.parse(ENV['http_proxy']) rescue nil + + begin + URI.parse(ENV['http_proxy']) + rescue StandardError + nil + end end - def proxy= proxy_url + def proxy=(proxy_url) @proxy = URI.parse(proxy_url) end - def order_url order_id='' + def order_url(order_id = '') url = "#{@endpoint}/orders" url += "/#{order_id}" unless order_id == '' URI.parse(url) end - def send_request http_method, request_body='' + def send_request(http_method, request_body = '') headers = { 'Authorization' => "Basic #{Base64.encode64(@api_key)}", - 'Content-Type' =>'application/json', - 'Referer' => @endpoint.path + 'Content-Type' => 'application/json', + 'Referer' => @endpoint.path, + 'User-Agent' => "konduto-ruby/#{VERSION}" } http_method.initialize_http_header headers http_method.body = request_body - if proxy - http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@endpoint.host, @endpoint.port) - else - http = Net::HTTP.new(@endpoint.host, @endpoint.port) - end + http = if proxy + Net::HTTP::Proxy(proxy.host, proxy.port).new(@endpoint.host, @endpoint.port) + else + Net::HTTP.new(@endpoint.host, @endpoint.port) + end http.use_ssl = true - response = http.request(http_method) - - response + http.request(http_method) end - def get_order order_id + def get_order(order_id) get = Net::HTTP::Get.new(order_url(order_id)) response = send_request(get) - if response.kind_of? Net::HTTPSuccess + if response.is_a? Net::HTTPSuccess order = KondutoOrder.new JSON.parse(response.entity)['order'] order.id = order_id unless order.id - return order + order else - raise (JSON.parse(response.body)['message']).to_s + raise JSON.parse(response.body)['message'].to_s end - - end - def analyze order + def analyze(order) post = Net::HTTP::Post.new(order_url) response = send_request(post, order.to_json) - if response.kind_of? Net::HTTPSuccess - return KondutoOrder.new JSON.parse(response.entity)['order'] + if response.is_a? Net::HTTPSuccess + KondutoOrder.new JSON.parse(response.entity)['order'] else - raise (JSON.parse(response.body)['message']).to_s + raise JSON.parse(response.body)['message'].to_s end end - def update_order_status order, new_status, comments - raise ArgumentError("Illegal status #{new_status}") unless KondutoOrderStatus.allowed_status.include? new_status - raise ArgumentError("Commets can't be nil") unless comments + def update_order_status(order, new_status, comments) + unless KondutoOrderStatus.allowed_status.include? new_status + raise ArgumentError, + "Illegal status '#{new_status}', Allowed status #{KondutoOrderStatus.allowed_status}" + end + raise ArgumentError, "Commets can't be nil" unless comments put = Net::HTTP::Put.new(order_url(order.id)) - body = {status: new_status.downcase, comments: comments}.to_json + body = { status: new_status.downcase, comments: comments }.to_json response = send_request(put, body) - if response.kind_of? Net::HTTPSuccess + if response.is_a? Net::HTTPSuccess resposta = JSON.parse(response.entity)['order'] raise 'Update order status can\'t be done' if resposta['old_status'].nil? && resposta['new_status'].nil? + order.status = resposta['new_status'] - return order + order else - raise (JSON.parse(response.body)['message']).to_s + raise JSON.parse(response.body)['message'].to_s end end diff --git a/lib/konduto-ruby/associations/associations.rb b/lib/konduto-ruby/associations/associations.rb index d5b9de7..e827a3a 100644 --- a/lib/konduto-ruby/associations/associations.rb +++ b/lib/konduto-ruby/associations/associations.rb @@ -1,20 +1,21 @@ +# frozen_string_literal: true + module Konduto module Associations - def has_one(model, options = {}) name = options[:alias] || model - self.send(:define_method, name) do + send(:define_method, name) do instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}") end - self.send(:define_method, "#{name}=".to_sym) do |value| + send(:define_method, "#{name}=".to_sym) do |value| klass = "Konduto#{model.to_s.gsub(/_/, ' ').split.map(&:capitalize).join('')}" - if value.class.to_s == klass + if value.instance_of? Object.const_get(klass) instance_variable_set("@#{name}", value) elsif value.is_a? Hash - instance_variable_set("@#{name}", Object::const_get(klass).new(value)) + instance_variable_set("@#{name}", Object.const_get(klass).new(value)) else raise ArgumentError, "Expected class #{klass}, got #{value.class} at #{self.class}" end @@ -24,19 +25,19 @@ def has_one(model, options = {}) def has_many(model, options = {}) name = options[:alias] || model - self.send(:define_method, name) do + send(:define_method, name) do instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}") end - self.send(:define_method, "#{name}=".to_sym) do |arr| + send(:define_method, "#{name}=".to_sym) do |arr| klass = "Konduto#{model.to_s.gsub(/_/, ' ').split.map(&:capitalize).join('')}" temp_arr = [] arr.each do |value| - if value.class.to_s == klass + if value.instance_of? Object.const_get(klass) temp_arr << value elsif value.is_a? Hash - temp_arr << Object::const_get(klass).new(value) + temp_arr << Object.const_get(klass).new(value) else raise ArgumentError, "Expected class #{klass}, got #{value.class} at #{self.class}" end diff --git a/lib/konduto-ruby/attributes.rb b/lib/konduto-ruby/attributes.rb index a27578b..2b3a8fd 100644 --- a/lib/konduto-ruby/attributes.rb +++ b/lib/konduto-ruby/attributes.rb @@ -1,35 +1,37 @@ +# frozen_string_literal: true + module Konduto module Attributes def attributes(*attributes) attributes.each do |attribute| if attribute.is_a? Hash klass = attribute.values[0].to_s.gsub(/_/, ' ').split.map(&:capitalize).join('') - type = Object::const_get(klass) + type = Object.const_get(klass) name = attribute.keys[0] - define_strftime_pattern(self, name, attribute[:strftime_pattern]) if attribute.has_key?(:strftime_pattern) + define_strftime_pattern(self, name, attribute[:strftime_pattern]) if attribute.key?(:strftime_pattern) else name = attribute end - self.send(:define_method, "#{name}=".to_sym) do |value| - unless type.nil? - if value.is_a?(String) - value = type.parse(value) if type == Date || type == DateTime - value = value.to_sym if type == Symbol - end + send(:define_method, "#{name}=".to_sym) do |value| + if !type.nil? && value.is_a?(String) + value = type.parse(value) if [Date, DateTime].include?(type) + value = value.to_sym if type == Symbol end instance_variable_set("@#{name.to_s.gsub(/[?|!]$/, '')}", value) end - self.send(:define_method, name) do - instance_variable_get("@#{name.to_s.gsub(/[?|!]$/, '')}") if instance_variable_defined?("@#{name.to_s.gsub(/[?|!]$/, '')}") + send(:define_method, name) do + instance_variable_get("@#{name.to_s.gsub(/[?|!]$/, '')}") if instance_variable_defined?("@#{name.to_s.gsub( + /[?|!]$/, '' + )}") end end end - alias :attribute :attributes + alias attribute attributes def define_strftime_pattern(klass, name, value) klass.send(:define_method, "#{name.to_s.gsub(/[?|!]$/, '')}_strftime_pattern") do diff --git a/lib/konduto-ruby/konduto_address.rb b/lib/konduto-ruby/konduto_address.rb index d1e952e..6864d46 100644 --- a/lib/konduto-ruby/konduto_address.rb +++ b/lib/konduto-ruby/konduto_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class KondutoAddress < KondutoBase - attributes :name, :address1, :address2, :zip, :city, :state, :country + attributes :name, :address1, :address2, :zip, :city, :state, :country, :lat, :lon end diff --git a/lib/konduto-ruby/konduto_agent.rb b/lib/konduto-ruby/konduto_agent.rb new file mode 100644 index 0000000..8519200 --- /dev/null +++ b/lib/konduto-ruby/konduto_agent.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class KondutoAgent < KondutoBase + attributes :id, :category, :login, :name, :tax_id + attribute created_at: :date + attribute dob: :date + + validates_presence_of :id, :name +end diff --git a/lib/konduto-ruby/konduto_analysis_layer.rb b/lib/konduto-ruby/konduto_analysis_layer.rb new file mode 100644 index 0000000..22c8f83 --- /dev/null +++ b/lib/konduto-ruby/konduto_analysis_layer.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class KondutoAnalysisLayer < KondutoBase + attributes :recommendation, :original_recommendation, + :is_exploring, :analysis_type, :score +end diff --git a/lib/konduto-ruby/konduto_attendee.rb b/lib/konduto-ruby/konduto_attendee.rb new file mode 100644 index 0000000..dc7a57c --- /dev/null +++ b/lib/konduto-ruby/konduto_attendee.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class KondutoAttendee < KondutoBase + attributes :name, :document + attribute document_type: :symbol + attribute dob: :date + validates_presence_of :document + DOCUMENT_TYPE = %i[cpf cnpj rg passport other].freeze +end diff --git a/lib/konduto-ruby/konduto_base.rb b/lib/konduto-ruby/konduto_base.rb index d45ceaf..dbb46b3 100644 --- a/lib/konduto-ruby/konduto_base.rb +++ b/lib/konduto-ruby/konduto_base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'associations/associations' require_relative 'validations/validations' require_relative 'attributes' @@ -8,17 +10,16 @@ class KondutoBase include Konduto::Validations def initialize(*args) - unless args[0].nil? - args[0].each do |key, value| - unless value.nil? - if respond_to? "#{key}=".to_sym - send("#{key}=", value) - elsif key == 'class' - send('klass=', value) - else - instance_variable_set("@#{key}", value) - end - end + args[0]&.each do |key, value| + next if value.nil? + + parameterized_key = KondutoUtils.parameterize_key(key) + if respond_to? "#{parameterized_key}=".to_sym + send("#{parameterized_key}=", value) + elsif parameterized_key == 'class' + send('klass=', value) + else + instance_variable_set("@#{parameterized_key}", value) end end end @@ -31,7 +32,7 @@ def to_hash strftime_pattern = defined_strftime_pattern(name) if defined_strftime_pattern?(name) if value.respond_to? :each - value = value.map {|v| v.to_hash } + value = value.map(&:to_hash) elsif !value.instance_variables.empty? value = value.to_hash elsif value.is_a?(DateTime) @@ -47,14 +48,15 @@ def to_hash ] end - def to_json - raise RuntimeError, 'Invalid object for serialization' unless self.valid? - self.to_hash.to_json + def to_json(*_args) + raise 'Invalid object for serialization' unless valid? + + to_hash.to_json end def ==(other) - self.instance_variables.each do |name| - return false unless self.instance_variable_get(name) == other.instance_variable_get(name) + instance_variables.each do |name| + return false unless instance_variable_get(name) == other.instance_variable_get(name) end true @@ -67,4 +69,12 @@ def defined_strftime_pattern?(attr) def defined_strftime_pattern(attr) send("#{attr.to_s.gsub(/^@/, '')}_strftime_pattern") end + + def rename_attribute_on_hash(origin_name, dest_name, attr_as_hash) + unless attr_as_hash[origin_name].nil? + attr_as_hash[dest_name] = attr_as_hash[origin_name] + attr_as_hash.delete(origin_name) + end + attr_as_hash + end end diff --git a/lib/konduto-ruby/konduto_bus_leg.rb b/lib/konduto-ruby/konduto_bus_leg.rb index 76e6af6..70c02bd 100644 --- a/lib/konduto-ruby/konduto_bus_leg.rb +++ b/lib/konduto-ruby/konduto_bus_leg.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class KondutoBusLeg < KondutoTravelLeg attributes :origin_city, :destination_city validates_presence_of :origin_city, :destination_city diff --git a/lib/konduto-ruby/konduto_customer.rb b/lib/konduto-ruby/konduto_customer.rb index b70945e..2cf4858 100644 --- a/lib/konduto-ruby/konduto_customer.rb +++ b/lib/konduto-ruby/konduto_customer.rb @@ -1,6 +1,10 @@ +# frozen_string_literal: true + class KondutoCustomer < KondutoBase - attributes :id, :name, :email, :new?, :vip?, :phone1, :phone2, :tax_id + attributes :id, :name, :email, :new?, :vip?, :phone1, :phone2, :tax_id, + :document_type, :type, :risk_level, :risk_score, :mother_name attribute created_at: :date + attribute dob: :date validates_presence_of :id, :name, :email end diff --git a/lib/konduto-ruby/konduto_delivery.rb b/lib/konduto-ruby/konduto_delivery.rb index 7668998..4bfc0c1 100644 --- a/lib/konduto-ruby/konduto_delivery.rb +++ b/lib/konduto-ruby/konduto_delivery.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class KondutoDelivery < KondutoBase attributes :delivery_company, :delivery_method, :estimated_shipping_date, :estimated_delivery_date end diff --git a/lib/konduto-ruby/konduto_destination_account.rb b/lib/konduto-ruby/konduto_destination_account.rb new file mode 100644 index 0000000..f6602c8 --- /dev/null +++ b/lib/konduto-ruby/konduto_destination_account.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class KondutoDestinationAccount < KondutoBase + attributes :amount, :bank_account, :bank_branch, :bank_code, :bank_name, :holder_name, + :holder_tax_id, :id, :key_value + attribute key_type: :symbol + + KEY_TYPE = %i[pix_cpf pix_cnpj pix_phone pix_email pix_evp p2p none].freeze +end diff --git a/lib/konduto-ruby/konduto_device.rb b/lib/konduto-ruby/konduto_device.rb index 0c1cc78..20322d9 100644 --- a/lib/konduto-ruby/konduto_device.rb +++ b/lib/konduto-ruby/konduto_device.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class KondutoDevice < KondutoBase attributes :user_id, :fingerprint, :platform, :browser, :language, :timezone, \ :cookie, :javascript, :flash, :ip diff --git a/lib/konduto-ruby/konduto_event.rb b/lib/konduto-ruby/konduto_event.rb new file mode 100644 index 0000000..ca97e1e --- /dev/null +++ b/lib/konduto-ruby/konduto_event.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class KondutoEvent < KondutoBase + attributes :name, :subtype, :type + validates_presence_of :name, :date, :type + attribute date: :date_time, strftime_pattern: '%Y-%m-%dT%H:%M:%SZ' + has_many :ticket, alias: :tickets + has_one :venue +end diff --git a/lib/konduto-ruby/konduto_external_device.rb b/lib/konduto-ruby/konduto_external_device.rb new file mode 100644 index 0000000..8be27f0 --- /dev/null +++ b/lib/konduto-ruby/konduto_external_device.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class KondutoExternalDevice < KondutoBase + attributes :fingerprint, :provider, :category, :model, :platform, + :manufacturer, :os, :browser, :language +end diff --git a/lib/konduto-ruby/konduto_flight_leg.rb b/lib/konduto-ruby/konduto_flight_leg.rb index b575ad7..cec1be1 100644 --- a/lib/konduto-ruby/konduto_flight_leg.rb +++ b/lib/konduto-ruby/konduto_flight_leg.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class KondutoFlightLeg < KondutoTravelLeg - attributes :origin_airport, :origin_city, :destination_airport, :destination_city + attributes :origin_airport, :origin_city, :destination_airport, :destination_city, :company validates_presence_of :origin_airport, :destination_airport validates(:origin_airport, :destination_airport) do |attr| diff --git a/lib/konduto-ruby/konduto_geolocation.rb b/lib/konduto-ruby/konduto_geolocation.rb index 3555f80..28a5bb6 100644 --- a/lib/konduto-ruby/konduto_geolocation.rb +++ b/lib/konduto-ruby/konduto_geolocation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class KondutoGeolocation < KondutoBase attributes :city, :state, :country end diff --git a/lib/konduto-ruby/konduto_guest.rb b/lib/konduto-ruby/konduto_guest.rb new file mode 100644 index 0000000..c54e089 --- /dev/null +++ b/lib/konduto-ruby/konduto_guest.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class KondutoGuest < KondutoBase + attributes :name, :document, :document_type, :dob, :nationality +end diff --git a/lib/konduto-ruby/konduto_hotel.rb b/lib/konduto-ruby/konduto_hotel.rb new file mode 100644 index 0000000..27a1cfa --- /dev/null +++ b/lib/konduto-ruby/konduto_hotel.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class KondutoHotel < KondutoBase + attributes :name, :address1, :address2, :city, :state, :zip, :country, :category + has_many :room, alias: :rooms +end diff --git a/lib/konduto-ruby/konduto_item.rb b/lib/konduto-ruby/konduto_item.rb index f1e6010..26d9489 100644 --- a/lib/konduto-ruby/konduto_item.rb +++ b/lib/konduto-ruby/konduto_item.rb @@ -1,4 +1,14 @@ +# frozen_string_literal: true + class KondutoItem < KondutoBase - attributes :sku, :category, :name, :description, :product_code, :unit_cost, :quantity, :discount + attributes :sku, :category, :name, :description, :product_code, :unit_cost, :quantity, + :discount, :delivery_type, :delivery_sla_in_minutes, :seller_id, :image attribute created_at: :date + + def to_hash + item_as_hash = super.to_hash + item_as_hash = rename_attribute_on_hash('delivery_sla_in_minutes', 'deliverySlaInMinutes', item_as_hash) + item_as_hash = rename_attribute_on_hash('delivery_type', 'deliveryType', item_as_hash) + rename_attribute_on_hash('seller_id', 'sellerId', item_as_hash) + end end diff --git a/lib/konduto-ruby/konduto_loyalty.rb b/lib/konduto-ruby/konduto_loyalty.rb index 07a1ce9..5b2f9f6 100644 --- a/lib/konduto-ruby/konduto_loyalty.rb +++ b/lib/konduto-ruby/konduto_loyalty.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class KondutoLoyalty < KondutoBase attributes :program, :category end diff --git a/lib/konduto-ruby/konduto_navigation.rb b/lib/konduto-ruby/konduto_navigation.rb index 39d1a03..60cf35b 100644 --- a/lib/konduto-ruby/konduto_navigation.rb +++ b/lib/konduto-ruby/konduto_navigation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class KondutoNavigation < KondutoBase attributes :session_time, :referrer, :time_site_1d, :new_accounts_1d, :password_resets_1d, :sales_declined_1d,\ :sessions_1d, :time_since_last_sale, :time_site_7d, :time_per_page_7d, :new_accounts_7d, \ diff --git a/lib/konduto-ruby/konduto_options.rb b/lib/konduto-ruby/konduto_options.rb new file mode 100644 index 0000000..1a17f9a --- /dev/null +++ b/lib/konduto-ruby/konduto_options.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class KondutoOptions < KondutoBase + attributes :real_time, :sales_channel +end diff --git a/lib/konduto-ruby/konduto_order.rb b/lib/konduto-ruby/konduto_order.rb index 2edfe1c..658be00 100644 --- a/lib/konduto-ruby/konduto_order.rb +++ b/lib/konduto-ruby/konduto_order.rb @@ -1,8 +1,15 @@ +# frozen_string_literal: true + class KondutoOrder < KondutoBase has_many :item, alias: :shopping_cart has_many :payment + has_many :destination_account, alias: :destination_accounts + has_many :event, alias: :events + has_many :analysis_layer, alias: :analysis_layers + has_many :triggered_decision_list, alias: :triggered_decision_list + has_many :triggered_rule, alias: :triggered_rules - has_one :address, alias: :shipping + has_one :shipping_address, alias: :shipping has_one :address, alias: :billing has_one :customer has_one :seller @@ -11,9 +18,18 @@ class KondutoOrder < KondutoBase has_one :geolocation has_one :navigation has_one :delivery + has_one :agent + has_one :origin_account + has_one :external_device + has_one :options + has_one :point_of_sale + has_one :tenant + has_one :vehicle + has_one :hotel attributes :id, :visitor, :timestamp, :total_amount, :tax_amount, :currency, :installments, - :ip, :score, :analyze, :messages_exchanged, :shipping_amount + :ip, :score, :analyze, :messages_exchanged, :shipping_amount, :recurring, :risk_level, + :sales_channel, :scheduled attribute first_message: :date_time, strftime_pattern: '%Y-%m-%dT%H:%M:%SZ' attribute purchased_at: :date_time, strftime_pattern: '%Y-%m-%dT%H:%M:%SZ' diff --git a/lib/konduto-ruby/konduto_order_status.rb b/lib/konduto-ruby/konduto_order_status.rb index 61ef3d8..f5bcc46 100644 --- a/lib/konduto-ruby/konduto_order_status.rb +++ b/lib/konduto-ruby/konduto_order_status.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + class KondutoOrderStatus < KondutoBase attributes :status, :comments def self.allowed_status - %w(APPROVED DECLINED NOT_AUTHORIZED CANCELED FRAUD) + %w[APPROVED DECLINED NOT_AUTHORIZED CANCELED FRAUD] end end diff --git a/lib/konduto-ruby/konduto_origin_account.rb b/lib/konduto-ruby/konduto_origin_account.rb new file mode 100644 index 0000000..48011cc --- /dev/null +++ b/lib/konduto-ruby/konduto_origin_account.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class KondutoOriginAccount < KondutoBase + attributes :balance, :bank_account, :bank_branch, :bank_code, :bank_name, + :holder_name, :holder_tax_id, :id, :key_value + attribute key_type: :symbol + KEY_TYPE = %i[pix_cpf pix_cnpj pix_phone pix_email pix_evp p2p none].freeze +end diff --git a/lib/konduto-ruby/konduto_owner.rb b/lib/konduto-ruby/konduto_owner.rb new file mode 100644 index 0000000..569466e --- /dev/null +++ b/lib/konduto-ruby/konduto_owner.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class KondutoOwner < KondutoBase + attributes :tax_id, :name +end diff --git a/lib/konduto-ruby/konduto_passenger.rb b/lib/konduto-ruby/konduto_passenger.rb index 4383c5b..3176651 100644 --- a/lib/konduto-ruby/konduto_passenger.rb +++ b/lib/konduto-ruby/konduto_passenger.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + class KondutoPassenger < KondutoBase - attributes :name, :document, :nationality, :frequent_traveler, :special_needs, \ - :loyalty, :loyalty_program, :loyalty_category + attributes :name, :document, :nationality, :frequent_traveler, :special_needs, + :loyalty_program, :loyalty_category attribute dob: :date attribute document_type: :symbol + has_one :loyalty validates_presence_of :name, :document, :document_type, :nationality diff --git a/lib/konduto-ruby/konduto_payment.rb b/lib/konduto-ruby/konduto_payment.rb index db6a92b..85caa86 100644 --- a/lib/konduto-ruby/konduto_payment.rb +++ b/lib/konduto-ruby/konduto_payment.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + class KondutoPayment < KondutoBase - attributes :expiration_date, :bin, :last4 + attributes :expiration_date, :bin, :last4, :amount, :sha1, :cvv_result, + :avs_result, :number_of_retries, :tax_id, :description attribute type: :symbol attribute status: :symbol - TYPE_PAYMENT = [:credit, :boleto, :debit, :transfer, :voucher] - TYPE_STATUS = [:approved, :declined, :pending] + TYPE_PAYMENT = %i[credit boleto debit transfer voucher].freeze + TYPE_STATUS = %i[approved declined pending].freeze end diff --git a/lib/konduto-ruby/konduto_point_of_sale.rb b/lib/konduto-ruby/konduto_point_of_sale.rb new file mode 100644 index 0000000..0ab68f5 --- /dev/null +++ b/lib/konduto-ruby/konduto_point_of_sale.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class KondutoPointOfSale < KondutoBase + attributes :id, :name, :lat, :long, :address, :city, :state, :zip, :country +end diff --git a/lib/konduto-ruby/konduto_room.rb b/lib/konduto-ruby/konduto_room.rb new file mode 100644 index 0000000..cf1716e --- /dev/null +++ b/lib/konduto-ruby/konduto_room.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class KondutoRoom < KondutoBase + attributes :number, :code, :type, :check_in_date, :check_out_date, + :number_of_guests, :board_basis + has_many :guest, alias: :guests +end diff --git a/lib/konduto-ruby/konduto_seller.rb b/lib/konduto-ruby/konduto_seller.rb index f57dcf6..2486e80 100644 --- a/lib/konduto-ruby/konduto_seller.rb +++ b/lib/konduto-ruby/konduto_seller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class KondutoSeller < KondutoBase attributes :id, :name attribute created_at: :date diff --git a/lib/konduto-ruby/konduto_shipping_address.rb b/lib/konduto-ruby/konduto_shipping_address.rb new file mode 100644 index 0000000..4577915 --- /dev/null +++ b/lib/konduto-ruby/konduto_shipping_address.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class KondutoShippingAddress < KondutoAddress + attributes :estimated_date, :value + + def to_hash + shipping_address_as_hash = super.to_hash + rename_attribute_on_hash('estimated_date', 'estimatedDate', shipping_address_as_hash) + end +end diff --git a/lib/konduto-ruby/konduto_tenant.rb b/lib/konduto-ruby/konduto_tenant.rb new file mode 100644 index 0000000..29d3d0a --- /dev/null +++ b/lib/konduto-ruby/konduto_tenant.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class KondutoTenant < KondutoBase + attributes :id, :name, :created_at +end diff --git a/lib/konduto-ruby/konduto_ticket.rb b/lib/konduto-ruby/konduto_ticket.rb new file mode 100644 index 0000000..3ff15ee --- /dev/null +++ b/lib/konduto-ruby/konduto_ticket.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class KondutoTicket < KondutoBase + attributes :id, :category, :section, :premium + validates_presence_of :category, :premium + has_one :attendee +end diff --git a/lib/konduto-ruby/konduto_travel.rb b/lib/konduto-ruby/konduto_travel.rb index 58a024e..d931ea0 100644 --- a/lib/konduto-ruby/konduto_travel.rb +++ b/lib/konduto-ruby/konduto_travel.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + class KondutoTravel < KondutoBase has_one :flight_leg, alias: :departure has_one :flight_leg, alias: :return has_many :passenger, alias: :passengers + attributes :expiration_date attribute type: :symbol validates_presence_of :type, :departure, :passengers diff --git a/lib/konduto-ruby/konduto_travel_info.rb b/lib/konduto-ruby/konduto_travel_info.rb deleted file mode 100644 index 0623e41..0000000 --- a/lib/konduto-ruby/konduto_travel_info.rb +++ /dev/null @@ -1,6 +0,0 @@ -class KondutoTravelInfo < KondutoBase - attributes :number_of_connections, :class, :fare_basis - attribute date: :date - - TRAVEL_CLASS = [:economy, :business, :first] -end diff --git a/lib/konduto-ruby/konduto_travel_leg.rb b/lib/konduto-ruby/konduto_travel_leg.rb index 1c86912..ddc9ca3 100644 --- a/lib/konduto-ruby/konduto_travel_leg.rb +++ b/lib/konduto-ruby/konduto_travel_leg.rb @@ -1,4 +1,7 @@ +# frozen_string_literal: true + class KondutoTravelLeg < KondutoBase + TRAVEL_CLASS = %i[economy business first].freeze attributes :number_of_connections, :fare_basis attribute date: :date_time attribute klass: :symbol diff --git a/lib/konduto-ruby/konduto_triggered_decision_list.rb b/lib/konduto-ruby/konduto_triggered_decision_list.rb new file mode 100644 index 0000000..82b5de7 --- /dev/null +++ b/lib/konduto-ruby/konduto_triggered_decision_list.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class KondutoTriggeredDecisionList < KondutoBase + attributes :decision, :trigger, :type +end diff --git a/lib/konduto-ruby/konduto_triggered_rule.rb b/lib/konduto-ruby/konduto_triggered_rule.rb new file mode 100644 index 0000000..f03ace7 --- /dev/null +++ b/lib/konduto-ruby/konduto_triggered_rule.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class KondutoTriggeredRule < KondutoBase + attributes :priority, :name, :analysis_type, :decision +end diff --git a/lib/konduto-ruby/konduto_utils.rb b/lib/konduto-ruby/konduto_utils.rb index fe9b16a..984adec 100644 --- a/lib/konduto-ruby/konduto_utils.rb +++ b/lib/konduto-ruby/konduto_utils.rb @@ -1,15 +1,31 @@ +# frozen_string_literal: true + class KondutoUtils - def self.array_to_hash arr - arr.map{ |pair| Hash[*pair] } + def self.array_to_hash(arr) + arr.map { |pair| Hash[*pair] } + end + + def self.remove_nil_keys_from_hash(hash) + hash.delete_if { |_k, v| v.nil? || (v.respond_to?(:empty?) && v.empty?) } end - def self.remove_nil_keys_from_hash hash - hash.delete_if { |k, v| v.nil? || (v.respond_to?(:empty?) && v.empty?) } + def self.deep_symbolize_keys(hash) + if hash.is_a? Hash + return hash.each_with_object({}) do |(k, v), memo| + memo[k.to_sym] = deep_symbolize_keys(v) + end + end + if hash.is_a? Array + return hash.each_with_object([]) do |v, memo| + memo << deep_symbolize_keys(v) + end + end + + hash end - def self.deep_symbolize_keys hash - return hash.inject({}){|memo,(k,v)| memo[k.to_sym] = deep_symbolize_keys(v); memo} if hash.is_a? Hash - return hash.inject([]){|memo,v | memo << deep_symbolize_keys(v); memo} if hash.is_a? Array - return hash + def self.parameterize_key(key) + str = key.to_s + str.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase end end diff --git a/lib/konduto-ruby/konduto_vehicle.rb b/lib/konduto-ruby/konduto_vehicle.rb new file mode 100644 index 0000000..abd48ac --- /dev/null +++ b/lib/konduto-ruby/konduto_vehicle.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class KondutoVehicle < KondutoBase + attributes :make, :model, :renavam, :registration, :vid, :type, :usage + has_one :owner +end diff --git a/lib/konduto-ruby/konduto_venue.rb b/lib/konduto-ruby/konduto_venue.rb new file mode 100644 index 0000000..06416bf --- /dev/null +++ b/lib/konduto-ruby/konduto_venue.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class KondutoVenue < KondutoBase + attributes :address, :capacity, :city, :country, :name, :state + validates(:country) do |attr| + attr.match(/[a-zA-Z]{2}/) + end +end diff --git a/lib/konduto-ruby/validations/class_methods.rb b/lib/konduto-ruby/validations/class_methods.rb index 512a1d8..37b4a60 100644 --- a/lib/konduto-ruby/validations/class_methods.rb +++ b/lib/konduto-ruby/validations/class_methods.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + module Konduto module ClassMethods def validates_presence_of(*attributes) - self.send(:define_method, :required_attr) do + send(:define_method, :required_attr) do attributes end end def validates(*attributes, &block) if block_given? - self.send(:define_method, :custom_validations) do + send(:define_method, :custom_validations) do { Proc.new(&block) => attributes } end end diff --git a/lib/konduto-ruby/validations/validations.rb b/lib/konduto-ruby/validations/validations.rb index c81d0ff..f7536a2 100644 --- a/lib/konduto-ruby/validations/validations.rb +++ b/lib/konduto-ruby/validations/validations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'class_methods' module Konduto diff --git a/test/factories/konduto_address.rb b/test/factories/konduto_address.rb index 4525179..71dc1c4 100644 --- a/test/factories/konduto_address.rb +++ b/test/factories/konduto_address.rb @@ -1,11 +1,15 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_address do - name 'Konduto' - address1 'R. Teodoro Sampaio, 2393' - address2 'CJ. 111' - zip '05406-200' - city 'São Paulo' - state 'SP' - country 'BR' + name { 'Konduto' } + address1 { 'R. Teodoro Sampaio, 2393' } + address2 { 'CJ. 111' } + zip { '05406-200' } + city { 'São Paulo' } + state { 'SP' } + country { 'BR' } + lat { -23.565779450573725 } + lon { -46.691031683668946 } end end diff --git a/test/factories/konduto_agent.rb b/test/factories/konduto_agent.rb new file mode 100644 index 0000000..6c6421a --- /dev/null +++ b/test/factories/konduto_agent.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_agent do + id { '28372' } + login { 'julia.silva' } + name { 'Júlia da Silva' } + tax_id { '12345678909' } + dob { '1970-12-25' } + category { 'vendedor' } + created_at { '2010-12-25' } + end +end diff --git a/test/factories/konduto_analysis_layer.rb b/test/factories/konduto_analysis_layer.rb new file mode 100644 index 0000000..6faa9d5 --- /dev/null +++ b/test/factories/konduto_analysis_layer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_analysis_layer do + recommendation { 'REVIEW' } + original_recommendation { 'REVIEW' } + is_exploring { false } + analysis_type { 'FRAUD' } + score { 0.3017217853308364 } + end +end diff --git a/test/factories/konduto_attendee.rb b/test/factories/konduto_attendee.rb new file mode 100644 index 0000000..051e290 --- /dev/null +++ b/test/factories/konduto_attendee.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_attendee do + document { '123456789' } + document_type { :cpf } + dob { '1990-10-28' } + end +end diff --git a/test/factories/konduto_customer.rb b/test/factories/konduto_customer.rb index 5621c5f..3b16e44 100644 --- a/test/factories/konduto_customer.rb +++ b/test/factories/konduto_customer.rb @@ -1,18 +1,26 @@ +# frozen_string_literal: true + require 'date' -FactoryGirl.define do +FactoryBot.define do factory :konduto_customer do - id '1' - name 'José da Silva' - email 'jose.silva@gmail.com' + id { '1' } + name { 'José da Silva' } + email { 'jose.silva@gmail.com' } trait :complete do - new? false - vip? false - phone1 '11987654321' - phone2 '1133333333' - tax_id '01234567890' - created_at Date.new(2015, 6, 9) + new? { false } + vip? { false } + phone1 { '11987654321' } + phone2 { '1133333333' } + tax_id { '01234567890' } + created_at { Date.new(2015, 6, 9) } + dob { Date.new(1969, 7, 20) } + document_type { 'cpf' } + type { 'A1' } + risk_level { 'low' } + risk_score { 0.5 } + mother_name { 'Maria Silva' } end end end diff --git a/test/factories/konduto_delivery.rb b/test/factories/konduto_delivery.rb index 10970f6..bd7c813 100644 --- a/test/factories/konduto_delivery.rb +++ b/test/factories/konduto_delivery.rb @@ -1,8 +1,10 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_delivery do - delivery_company 'GFL' - delivery_method 'retira_loja' - estimated_shipping_date '2021-05-06' - estimated_delivery_date '2021-05-06' + delivery_company { 'GFL' } + delivery_method { 'retira_loja' } + estimated_shipping_date { '2021-05-06' } + estimated_delivery_date { '2021-05-06' } end end diff --git a/test/factories/konduto_destination_account.rb b/test/factories/konduto_destination_account.rb new file mode 100644 index 0000000..8686b71 --- /dev/null +++ b/test/factories/konduto_destination_account.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_destination_account do + amount { 200.0 } + bank_account { '01234-5' } + bank_branch { '0001' } + bank_code { '17298092' } + bank_name { 'Itaú BBA' } + holder_name { 'José Armando' } + holder_tax_id { '123.456-789-09' } + id { 'Conta 003' } + key_type { 'pix_evp' } + key_value { '123e4567-e89b-12d3-a456-426655440000' } + end +end diff --git a/test/factories/konduto_device.rb b/test/factories/konduto_device.rb index 0e8c7a1..da1401f 100644 --- a/test/factories/konduto_device.rb +++ b/test/factories/konduto_device.rb @@ -1,14 +1,16 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_device do - browser 'Chrome' - cookie true - fingerprint 'e4f2c690951038a8f77aa583847'; - flash true - ip '170.149.100.10' - javascript true - platform 'MacIntel' - user_id '405961fab293600daeed93ae561' - language 'en_US' - timezone 'GMT -1' + browser { 'Chrome' } + cookie { true } + fingerprint { 'e4f2c690951038a8f77aa583847' } + flash { true } + ip { '170.149.100.10' } + javascript { true } + platform { 'MacIntel' } + user_id { '405961fab293600daeed93ae561' } + language { 'en_US' } + timezone { 'GMT -1' } end end diff --git a/test/factories/konduto_event.rb b/test/factories/konduto_event.rb new file mode 100644 index 0000000..7bd0ae3 --- /dev/null +++ b/test/factories/konduto_event.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_event do + name { 'Tia Ana no Maracanã' } + date { '2021-01-01T03:00:00Z' } + type { 'show' } + subtype { 'sertanejo' } + venue factory: :konduto_venue, strategy: :build + tickets { build_list :konduto_ticket, 1 } + end +end diff --git a/test/factories/konduto_external_device.rb b/test/factories/konduto_external_device.rb new file mode 100644 index 0000000..a1dc2f9 --- /dev/null +++ b/test/factories/konduto_external_device.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_external_device do + fingerprint { '51asd1asd445asd85d4g98s' } + provider { 'SDK' } + category { 'Mobile' } + model { 'Galaxy S22 Ultra' } + platform { 'Android' } + manufacturer { 'Samsung ' } + os { 'Android 12 Samsung One UI 4.1' } + browser { 'Chrome 104.0.5112.79' } + language { 'pt-br' } + end +end diff --git a/test/factories/konduto_flight_leg.rb b/test/factories/konduto_flight_leg.rb index 9956782..00c86c0 100644 --- a/test/factories/konduto_flight_leg.rb +++ b/test/factories/konduto_flight_leg.rb @@ -1,25 +1,29 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_flight_leg do trait :departure_flight do - origin_airport 'CGH' - origin_city 'São Paulo' - destination_airport 'SDU' - destination_city 'Rio de Janeiro' - klass :economy - number_of_connections 0 - date '2015-05-07' - fare_basis 'Y' + origin_airport { 'CGH' } + origin_city { 'São Paulo' } + destination_airport { 'SDU' } + destination_city { 'Rio de Janeiro' } + klass { :economy } + number_of_connections { 0 } + date { '2015-05-07' } + fare_basis { 'Y' } + company { 'Gol' } end trait :return_flight do - origin_airport 'SDU' - origin_city 'Rio de Janeiro' - destination_airport 'CGH' - destination_city 'São Paulo' - klass :economy - number_of_connections 0 - date '2015-05-07' - fare_basis 'Y' + origin_airport { 'SDU' } + origin_city { 'Rio de Janeiro' } + destination_airport { 'CGH' } + destination_city { 'São Paulo' } + klass { :economy } + number_of_connections { 0 } + date { '2015-05-07' } + fare_basis { 'Y' } + company { 'Gol' } end end end diff --git a/test/factories/konduto_geolocation.rb b/test/factories/konduto_geolocation.rb index aff2075..67ffebd 100644 --- a/test/factories/konduto_geolocation.rb +++ b/test/factories/konduto_geolocation.rb @@ -1,7 +1,9 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_geolocation do - city 'São Paulo' - state 'SP' - country 'BR' + city { 'São Paulo' } + state { 'SP' } + country { 'BR' } end end diff --git a/test/factories/konduto_guest.rb b/test/factories/konduto_guest.rb new file mode 100644 index 0000000..3cbf896 --- /dev/null +++ b/test/factories/konduto_guest.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_guest do + name { 'João Silva' } + document { '12345678990' } + document_type { 'cpf' } + dob { '1985-05-08' } + nationality { 'BR' } + end +end diff --git a/test/factories/konduto_hotel.rb b/test/factories/konduto_hotel.rb new file mode 100644 index 0000000..472e540 --- /dev/null +++ b/test/factories/konduto_hotel.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_hotel do + name { 'Hotel Konduto' } + address1 { 'Rod Três, 46' } + address2 { 'Vidinha' } + city { 'Pouso Alto' } + state { 'MG' } + zip { '12345-123' } + country { 'BR' } + category { 'Gold' } + rooms { build_list :konduto_room, 1 } + end +end diff --git a/test/factories/konduto_item.rb b/test/factories/konduto_item.rb index 2ffe85e..211b65b 100644 --- a/test/factories/konduto_item.rb +++ b/test/factories/konduto_item.rb @@ -1,26 +1,34 @@ +# frozen_string_literal: true + require 'date' -FactoryGirl.define do +FactoryBot.define do factory :konduto_item do trait :green_shirt do - sku '9919023' - product_code '123456789999' - category 201 - name 'Green T-Shirt' - description 'Male Green T-Shirt V Neck' - unit_cost 1999.99 - quantity 1.0 + sku { '9919023' } + product_code { '123456789999' } + category { 201 } + name { 'Green T-Shirt' } + description { 'Male Green T-Shirt V Neck' } + unit_cost { 1999.99 } + quantity { 1.0 } + discount { -10.99 } + image { 'https://product_image.test.com/123456789999.png' } + created_at { Date.new(2022, 4, 25) } + delivery_type { 'express delivery' } + delivery_sla_in_minutes { 50 } + seller_id { '11' } end trait :yellow_socks do - sku '0017273' - category 202 - name 'Yellow Socks' - description 'Pair of Yellow Socks' - unit_cost 29.9 - quantity 2.0 - discount 5.0 - created_at Date.new(2015, 6, 9) + sku { '0017273' } + category { 202 } + name { 'Yellow Socks' } + description { 'Pair of Yellow Socks' } + unit_cost { 29.9 } + quantity { 2.0 } + discount { 5.0 } + created_at { Date.new(2015, 6, 9) } end end end diff --git a/test/factories/konduto_loyalty.rb b/test/factories/konduto_loyalty.rb index 33e831b..114498e 100644 --- a/test/factories/konduto_loyalty.rb +++ b/test/factories/konduto_loyalty.rb @@ -1,6 +1,8 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_loyalty do - program 'advantage' - category 'gold' + program { 'advantage' } + category { 'gold' } end end diff --git a/test/factories/konduto_navigation.rb b/test/factories/konduto_navigation.rb index 7a3ee89..b8904d1 100644 --- a/test/factories/konduto_navigation.rb +++ b/test/factories/konduto_navigation.rb @@ -1,21 +1,23 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_navigation do - session_time 12 - referrer 'http://www.google.com?q=buy+shirt' - time_since_last_sale 4 + session_time { 12 } + referrer { 'http://www.google.com?q=buy+shirt' } + time_since_last_sale { 4 } - time_site_1d 26 - new_accounts_1d 2 - password_resets_1d 0 - sales_declined_1d 1 - sessions_1d 4 + time_site_1d { 26 } + new_accounts_1d { 2 } + password_resets_1d { 0 } + sales_declined_1d { 1 } + sessions_1d { 4 } - time_site_7d 58 - time_per_page_7d 7 - new_accounts_7d 9 - password_resets_7d 3 - checkout_count_7d 4 - sales_declined_7d 5 - sessions_7d 12 + time_site_7d { 58 } + time_per_page_7d { 7 } + new_accounts_7d { 9 } + password_resets_7d { 3 } + checkout_count_7d { 4 } + sales_declined_7d { 5 } + sessions_7d { 12 } end end diff --git a/test/factories/konduto_options.rb b/test/factories/konduto_options.rb new file mode 100644 index 0000000..588af7c --- /dev/null +++ b/test/factories/konduto_options.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_options do + real_time { true } + sales_channel { 'app' } + end +end diff --git a/test/factories/konduto_order.rb b/test/factories/konduto_order.rb new file mode 100644 index 0000000..136d546 --- /dev/null +++ b/test/factories/konduto_order.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'date' + +FactoryBot.define do + factory :konduto_order do + id { '1' } + total_amount { 120.5 } + + customer factory: :konduto_customer, strategy: :build + + trait :complete do + analyze { true } + visitor { 'a9031kdlas' } + currency { 'USD' } + installments { 1 } + ip { '192.168.0.1' } + shipping_amount { 5.0 } + tax_amount { 3.0 } + timestamp { 123_123_123_123 } + status { :approved } + recommendation { :approve } + first_message { DateTime.new(2015, 6, 9, 18, 27, 1) } + purchased_at { DateTime.new(2015, 6, 9, 18, 27, 1) } + messages_exchanged { 2 } + recurring { true } + risk_level { 'low' } + sales_channel { 'e-commerce' } + scheduled { false } + customer factory: %i[konduto_customer complete], strategy: :build + shipping factory: :konduto_shipping_address, strategy: :build + billing factory: :konduto_address, strategy: :build + geolocation factory: :konduto_geolocation, strategy: :build + payment { build_list :konduto_payment, 1, :credit_card } + shopping_cart { [build(:konduto_item, :green_shirt), build(:konduto_item, :yellow_socks)] } + travel factory: :konduto_travel, strategy: :build + seller factory: :konduto_seller, strategy: :build + delivery factory: :konduto_delivery, strategy: :build + agent factory: :konduto_agent, strategy: :build + origin_account factory: :konduto_origin_account, strategy: :build + destination_accounts { build_list :konduto_destination_account, 1 } + events { build_list :konduto_event, 1 } + external_device factory: :konduto_external_device, strategy: :build + hotel factory: :konduto_hotel, strategy: :build + options factory: :konduto_options, strategy: :build + point_of_sale factory: :konduto_point_of_sale, strategy: :build + tenant factory: :konduto_tenant, strategy: :build + vehicle factory: :konduto_vehicle, strategy: :build + analysis_layers { build_list :konduto_analysis_layer, 1 } + triggered_decision_list { build_list :konduto_triggered_decision_list, 1 } + triggered_rules { build_list :konduto_triggered_rule, 1 } + end + end +end diff --git a/test/factories/konduto_origin_account.rb b/test/factories/konduto_origin_account.rb new file mode 100644 index 0000000..6320832 --- /dev/null +++ b/test/factories/konduto_origin_account.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_origin_account do + balance { 250.0 } + bank_account { '123123' } + bank_branch { '0001' } + bank_code { '00000000' } + bank_name { 'Banco do Brasil' } + holder_name { 'Alberto Armando' } + holder_tax_id { '123.456.789-09' } + id { 'ABC123DEF' } + key_type { 'pix_phone' } + key_value { '+5511912341234' } + end +end diff --git a/test/factories/konduto_owner.rb b/test/factories/konduto_owner.rb new file mode 100644 index 0000000..eed3aa8 --- /dev/null +++ b/test/factories/konduto_owner.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_owner do + tax_id { '123.123.123-12' } + name { 'Cicero' } + end +end diff --git a/test/factories/konduto_passenger.rb b/test/factories/konduto_passenger.rb index 5c04a2b..8ce3cd8 100644 --- a/test/factories/konduto_passenger.rb +++ b/test/factories/konduto_passenger.rb @@ -1,36 +1,36 @@ +# frozen_string_literal: true + require 'date' -FactoryGirl.define do +FactoryBot.define do factory :konduto_passenger do - frequent_traveler false - sequence(:name) { |n| "Milton Tavares #{n}" } - sequence(:document) { |n| "A1B2C3D#{n}" } - document_type :passport - special_needs false + frequent_traveler { false } + name { 'Júlia da Silva' } + nationality { 'BR' } + special_needs { false } + document_type { :passport } trait :basic do - name 'Júlia da Silva' - document 'A1B2C3D4' - document_type :id + name { 'Júlia da Silva' } + nationality { 'BR' } + special_needs { false } end trait :complete do - dob Date.new(1970, 1, 1) - nationality 'BR' - frequent_traveler true - special_needs false - loyalty_program 'advantage' - loyalty_category 'gold' + dob { Date.new(1970, 1, 1) } + nationality { 'BR' } + frequent_traveler { true } + special_needs { false } end trait :fixed_complete do - name 'Júlia da Silva' - document 'A1B2C3D4' - document_type :id - dob Date.new(1970, 1, 1) - nationality 'BR' - frequent_traveler true - special_needs false + name { 'Júlia da Silva' } + document { 'A1B2C3D4' } + document_type { :id } + dob { Date.new(1970, 1, 1) } + nationality { 'BR' } + frequent_traveler { true } + special_needs { false } loyalty factory: :konduto_loyalty, strategy: :build end end diff --git a/test/factories/konduto_payment.rb b/test/factories/konduto_payment.rb index 20b9c48..cecf22b 100644 --- a/test/factories/konduto_payment.rb +++ b/test/factories/konduto_payment.rb @@ -1,11 +1,25 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_payment do trait :credit_card do - bin '123' - expiration_date '012014' - last4 '1234' - status :approved - type :credit + bin { '123456' } + expiration_date { '012014' } + last4 { '1234' } + status { :approved } + type { :credit } + amount { 100.65 } + sha1 { '1a2b3c4d5e6f7A8B9C10D11E12F1a2b3c4d5e6f7' } + cvv_result { 'valid' } + avs_result { 'ok' } + number_of_retries { 1 } + tax_id { '12345678990' } + end + + trait :voucher do + type { 'voucher' } + amount { 10.0 } + description { 'Desconto de 10%' } end end end diff --git a/test/factories/konduto_point_of_sale.rb b/test/factories/konduto_point_of_sale.rb new file mode 100644 index 0000000..5b18986 --- /dev/null +++ b/test/factories/konduto_point_of_sale.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_point_of_sale do + id { '000500' } + name { 'Capital Representações' } + lat { -23.5677666 } + long { -46.6487763 } + address { 'Rua Dez de Abril, 23' } + city { 'São Paulo' } + state { 'SP' } + zip { '01001-001' } + country { 'BR' } + end +end diff --git a/test/factories/konduto_room.rb b/test/factories/konduto_room.rb new file mode 100644 index 0000000..56c0019 --- /dev/null +++ b/test/factories/konduto_room.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_room do + number { '201A' } + code { '25487' } + type { 'A1' } + check_in_date { '2022-02-14' } + check_out_date { '2022-03-01' } + number_of_guests { 1 } + board_basis { 'economy' } + guests { build_list :konduto_guest, 1 } + end +end diff --git a/test/factories/konduto_seller.rb b/test/factories/konduto_seller.rb index 9ada2b4..0be9b84 100644 --- a/test/factories/konduto_seller.rb +++ b/test/factories/konduto_seller.rb @@ -1,7 +1,9 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_seller do - id 'seller_id' - name 'Seller Name' - created_at Date.new(2015, 6, 9) + id { 'seller_id' } + name { 'Seller Name' } + created_at { Date.new(2015, 6, 9) } end end diff --git a/test/factories/konduto_shipping_address.rb b/test/factories/konduto_shipping_address.rb new file mode 100644 index 0000000..1b20256 --- /dev/null +++ b/test/factories/konduto_shipping_address.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_shipping_address do + name { 'Konduto' } + address1 { 'R. Teodoro Sampaio, 2393' } + address2 { 'CJ. 111' } + zip { '05406-200' } + city { 'São Paulo' } + state { 'SP' } + country { 'BR' } + estimated_date { '2022-02-15T12:00:25Z' } + value { 20.0 } + lat { -23.565779450573725 } + lon { -46.691031683668946 } + end +end diff --git a/test/factories/konduto_tenant.rb b/test/factories/konduto_tenant.rb new file mode 100644 index 0000000..db7f8f2 --- /dev/null +++ b/test/factories/konduto_tenant.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_tenant do + id { '548btm' } + name { 'Tenant' } + created_at { '2022-02-12T12:52:00Z' } + end +end diff --git a/test/factories/konduto_ticket.rb b/test/factories/konduto_ticket.rb new file mode 100644 index 0000000..f6155ad --- /dev/null +++ b/test/factories/konduto_ticket.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_ticket do + id { '123456' } + category { 'regular' } + premium { true } + section { 'Pista Premium' } + attendee factory: :konduto_attendee, strategy: :build + end +end diff --git a/test/factories/konduto_travel.rb b/test/factories/konduto_travel.rb index e2c7854..7d5b5e5 100644 --- a/test/factories/konduto_travel.rb +++ b/test/factories/konduto_travel.rb @@ -1,8 +1,11 @@ -FactoryGirl.define do +# frozen_string_literal: true + +FactoryBot.define do factory :konduto_travel do - type :flight - departure factory: [:konduto_flight_leg, :departure_flight], strategy: :build + type { :flight } + expiration_date { '2022-05-12T15:25:30Z' } + departure factory: %i[konduto_flight_leg departure_flight], strategy: :build add_attribute(:return) { build :konduto_flight_leg, :return_flight } - passengers { build_list :konduto_passenger, 2 } + passengers { build_list :konduto_passenger, 1, :fixed_complete } end end diff --git a/test/factories/konduto_triggered_decision_list.rb b/test/factories/konduto_triggered_decision_list.rb new file mode 100644 index 0000000..05494d6 --- /dev/null +++ b/test/factories/konduto_triggered_decision_list.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_triggered_decision_list do + decision { 'DECLINE' } + trigger { 'GUEST_DOCUMENT' } + type { 'tax_id' } + end +end diff --git a/test/factories/konduto_triggered_rule.rb b/test/factories/konduto_triggered_rule.rb new file mode 100644 index 0000000..4346877 --- /dev/null +++ b/test/factories/konduto_triggered_rule.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_triggered_rule do + priority { -2 } + name { 'CPFs Monitorados' } + analysis_type { 'FRAUD' } + decision { 'REVIEW' } + end +end diff --git a/test/factories/konduto_vehicle.rb b/test/factories/konduto_vehicle.rb new file mode 100644 index 0000000..b11ead4 --- /dev/null +++ b/test/factories/konduto_vehicle.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_vehicle do + make { 'Bentley' } + model { 'Bacalar' } + renavam { '12312312312' } + registration { 'ABC1234' } + vid { '5GZCZ43D13S812715' } + type { 'car' } + usage { 'private' } + owner factory: :konduto_owner, strategy: :build + end +end diff --git a/test/factories/konduto_venue.rb b/test/factories/konduto_venue.rb new file mode 100644 index 0000000..baea0db --- /dev/null +++ b/test/factories/konduto_venue.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :konduto_venue do + name { 'Estádio do Maracanã' } + capacity { 8000 } + address { 'Av. Maracanã s/n' } + city { 'Rio de Janeiro' } + state { 'RJ' } + country { 'BR' } + end +end diff --git a/test/factories/kondutor_order.rb b/test/factories/kondutor_order.rb deleted file mode 100644 index 268ea4e..0000000 --- a/test/factories/kondutor_order.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'date' - -FactoryGirl.define do - factory :konduto_order do - id "1" - total_amount 120.5 - - customer factory: :konduto_customer, strategy: :build - - trait :complete do - analyze true - visitor "a9031kdlas" - currency 'USD' - installments 1 - ip '192.168.0.1' - shipping_amount 5.0 - tax_amount 3.0 - timestamp 123123123123 - customer factory: [:konduto_customer, :complete], strategy: :build - shipping factory: :konduto_address, strategy: :build - billing factory: :konduto_address, strategy: :build - geolocation factory: :konduto_geolocation, strategy: :build - status :approved - recommendation :approve - payment { build_list :konduto_payment, 1, :credit_card } - shopping_cart { [build(:konduto_item, :green_shirt), build(:konduto_item, :yellow_socks)] } - travel factory: :konduto_travel, strategy: :build - first_message DateTime.new(2015, 6, 9, 18, 27, 1) - purchased_at DateTime.new(2015, 6, 9, 18, 27, 1) - messages_exchanged 2 - seller factory: :konduto_seller, strategy: :build - delivery factory: :konduto_delivery, strategy: :build - end - end -end diff --git a/test/resources/address.json b/test/resources/address.json index 3e12fa0..a1258c5 100644 --- a/test/resources/address.json +++ b/test/resources/address.json @@ -5,5 +5,7 @@ "zip": "05406-200", "city": "São Paulo", "state": "SP", - "country": "BR" + "country": "BR", + "lat": -23.565779450573725, + "lon": -46.691031683668946 } diff --git a/test/resources/agent.json b/test/resources/agent.json new file mode 100644 index 0000000..d296a58 --- /dev/null +++ b/test/resources/agent.json @@ -0,0 +1,9 @@ +{ + "id":"28372", + "login":"julia.silva", + "name":"Júlia da Silva", + "tax_id":"12345678909", + "dob":"1970-12-25", + "category":"vendedor", + "created_at":"2010-12-25" +} \ No newline at end of file diff --git a/test/resources/analysis_layers.json b/test/resources/analysis_layers.json new file mode 100644 index 0000000..ecc00e8 --- /dev/null +++ b/test/resources/analysis_layers.json @@ -0,0 +1,9 @@ +[ + { + "recommendation": "REVIEW", + "original_recommendation": "REVIEW", + "is_exploring": false, + "analysis_type": "FRAUD", + "score": 0.3017217853308364 + } +] \ No newline at end of file diff --git a/test/resources/attendee.json b/test/resources/attendee.json new file mode 100644 index 0000000..216c6fa --- /dev/null +++ b/test/resources/attendee.json @@ -0,0 +1,5 @@ +{ + "document": "123456789", + "document_type": "cpf", + "dob": "1990-10-28" +} diff --git a/test/resources/bus_travel.json b/test/resources/bus_travel.json new file mode 100644 index 0000000..70be512 --- /dev/null +++ b/test/resources/bus_travel.json @@ -0,0 +1,37 @@ +{ + "type": "bus", + "expiration_date": "2022-05-12T15:25:30Z", + "departure":{ + "origin_city": "Guarulhos - SP", + "destination_city": "Fortaleza - CE", + "date": "2022-05-01", + "class": "economy", + "number_of_connections": 0, + "fare_basis": "A1", + "company": "Gol" + }, + "return":{ + "origin_city": "Fortaleza - CE", + "destination_city": "Guarulhos - SP", + "date": "2022-05-12", + "class": "economy", + "number_of_connections": 0, + "fare_basis": "A1", + "company": "Gol" + }, + "passengers": [ + { + "name":"Júlia da Silva", + "document": "A1B2C3D4", + "document_type": "id", + "dob": "1970-01-01", + "nationality": "BR", + "frequent_traveler": true, + "special_needs": false, + "loyalty": { + "program": "advantage", + "category": "gold" + } + } + ] +} \ No newline at end of file diff --git a/test/resources/customer.json b/test/resources/customer.json index c1632a7..b720800 100644 --- a/test/resources/customer.json +++ b/test/resources/customer.json @@ -2,10 +2,16 @@ "id": "1", "name": "José da Silva", "email": "jose.silva@gmail.com", + "dob": "1969-07-20", + "document_type": "cpf", "tax_id": "01234567890", "phone1": "11987654321", "phone2": "1133333333", "vip": false, "new": false, - "created_at": "2015-06-09" + "created_at": "2015-06-09", + "type": "A1", + "risk_level": "low", + "risk_score": 0.5, + "mother_name": "Maria Silva" } diff --git a/test/resources/destination_accounts.json b/test/resources/destination_accounts.json new file mode 100644 index 0000000..f07ec4b --- /dev/null +++ b/test/resources/destination_accounts.json @@ -0,0 +1,26 @@ +[ + { + "id": "Conta 003", + "key_type": "pix_evp", + "key_value": "123e4567-e89b-12d3-a456-426655440000", + "bank_code": "17298092", + "bank_name": "Itaú BBA", + "bank_branch": "0001", + "bank_account": "01234-5", + "holder_name": "José Armando", + "holder_tax_id": "123.456-789-09", + "amount": 200.0 + }, + { + "id": "Conta 007", + "key_type": "pix_phone", + "key_value": "(11) 911112222", + "bank_code": "60872504", + "bank_name": "Banco Itaú", + "bank_branch": "0001", + "bank_account": "12345-6", + "holder_name": "Laura Armando", + "holder_tax_id": "046.123.123-13", + "amount": 50.0 + } +] \ No newline at end of file diff --git a/test/resources/events.json b/test/resources/events.json new file mode 100644 index 0000000..fe09841 --- /dev/null +++ b/test/resources/events.json @@ -0,0 +1,47 @@ +[ + { + "name":"Tia Ana no Maracanã", + "date":"2021-01-01T03:00:00Z", + "type":"show", + "subtype":"sertanejo", + "venue":{ + "name":"Estádio do Maracanã", + "capacity":8000, + "address":"Av. Maracanã s/n", + "city":"Rio de Janeiro", + "state":"RJ", + "country":"BR" + }, + "tickets":[ + { + "id": "123456", + "category":"regular", + "premium":true, + "section":"Pista Premium", + "attendee":{ + "document":"123456789", + "document_type":"cpf", + "dob":"1990-10-28" + } + } + ] + }, + { + "name":"Heat @ Knicks", + "date":"2020-11-21T01:00:00Z", + "type":"sports", + "subtype":"NBA", + "tickets":[ + { + "category":"regular", + "section":"General", + "premium":true + }, + { + "category":"regular", + "section":"General", + "premium":true + } + ] + } +] \ No newline at end of file diff --git a/test/resources/external_device.json b/test/resources/external_device.json new file mode 100644 index 0000000..1cd1f13 --- /dev/null +++ b/test/resources/external_device.json @@ -0,0 +1,11 @@ +{ + "fingerprint": "51asd1asd445asd85d4g98s", + "provider": "SDK", + "category": "Mobile", + "model": "Galaxy S22 Ultra", + "platform": "Android", + "manufacturer": "Samsung ", + "os": "Android 12 Samsung One UI 4.1", + "browser": "Chrome 104.0.5112.79", + "language": "pt-br" +} \ No newline at end of file diff --git a/test/resources/flight_travel.json b/test/resources/flight_travel.json new file mode 100644 index 0000000..e695fb7 --- /dev/null +++ b/test/resources/flight_travel.json @@ -0,0 +1,41 @@ +{ + "type": "flight", + "expiration_date": "2022-05-12T15:25:30Z", + "departure":{ + "origin_airport": "GRU", + "destination_airport": "FOR", + "origin_city": "Guarulhos - SP", + "destination_city": "Fortaleza - CE", + "date": "2022-05-01", + "class": "economy", + "number_of_connections": 0, + "fare_basis": "A1", + "company": "Gol" + }, + "return":{ + "origin_airport": "FOR", + "destination_airport": "GRU", + "origin_city": "Fortaleza - CE", + "destination_city": "Guarulhos - SP", + "date": "2022-05-12", + "class": "economy", + "number_of_connections": 0, + "fare_basis": "A1", + "company": "Gol" + }, + "passengers": [ + { + "name":"Júlia da Silva", + "document": "A1B2C3D4", + "document_type": "id", + "dob": "1970-01-01", + "nationality": "BR", + "frequent_traveler": true, + "special_needs": false, + "loyalty": { + "program": "advantage", + "category": "gold" + } + } + ] +} \ No newline at end of file diff --git a/test/resources/guest.json b/test/resources/guest.json new file mode 100644 index 0000000..0be7a94 --- /dev/null +++ b/test/resources/guest.json @@ -0,0 +1,7 @@ +{ + "name": "João Silva", + "document": "12345678990", + "document_type": "cpf", + "dob": "1985-05-08", + "nationality": "BR" +} \ No newline at end of file diff --git a/test/resources/hotel.json b/test/resources/hotel.json new file mode 100644 index 0000000..a098445 --- /dev/null +++ b/test/resources/hotel.json @@ -0,0 +1,30 @@ +{ + "name": "Hotel Konduto", + "address1": "Rod Três, 46", + "address2": "Vidinha", + "city": "Pouso Alto", + "state": "MG", + "zip": "12345-123", + "country": "BR", + "category": "Gold", + "rooms": [ + { + "number": "201A", + "code": "25487", + "type": "A1", + "check_in_date": "2022-02-14", + "check_out_date": "2022-03-01", + "number_of_guests": 1, + "board_basis": "economy", + "guests": [ + { + "name": "João Silva", + "document": "12345678990", + "document_type": "cpf", + "dob": "1985-05-08", + "nationality": "BR" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/resources/loyalty.json b/test/resources/loyalty.json new file mode 100644 index 0000000..04071c6 --- /dev/null +++ b/test/resources/loyalty.json @@ -0,0 +1,4 @@ +{ + "program": "advantage", + "category": "gold" +} \ No newline at end of file diff --git a/test/resources/options.json b/test/resources/options.json new file mode 100644 index 0000000..d1c6cb8 --- /dev/null +++ b/test/resources/options.json @@ -0,0 +1,4 @@ +{ + "real_time": true, + "sales_channel": "app" +} \ No newline at end of file diff --git a/test/resources/order.json b/test/resources/order.json index afc28d2..921f3ab 100644 --- a/test/resources/order.json +++ b/test/resources/order.json @@ -1,131 +1,352 @@ { - "id": "1", - "visitor": "a9031kdlas", - "timestamp": 123123123123, - "total_amount": 120.5, - "shipping_amount": 5.0, - "tax_amount": 3.0, + "agent": + { + "category": "vendedor", + "created_at": "2010-12-25", + "dob": "1970-12-25", + "id": "28372", + "login": "julia.silva", + "name": "Júlia da Silva", + "tax_id": "12345678909" + }, + "analyze": true, + "billing": + { + "address1": "R. Teodoro Sampaio, 2393", + "address2": "CJ. 111", + "city": "São Paulo", + "country": "BR", + "name": "Konduto", + "state": "SP", + "zip": "05406-200", + "lat": -23.565779450573725, + "lon": -46.691031683668946 + }, "currency": "USD", - "installments": 1, - "ip": "192.168.0.1", - "first_message": "2015-06-09T18:27:01Z", - "messages_exchanged": 2, - "purchased_at": "2015-06-09T18:27:01Z", - "customer": { + "customer": + { + "created_at": "2015-06-09", + "dob": "1969-07-20", + "document_type": "cpf", + "email": "jose.silva@gmail.com", "id": "1", + "mother_name": "Maria Silva", "name": "José da Silva", - "email": "jose.silva@gmail.com", - "tax_id": "01234567890", + "new": false, "phone1": "11987654321", "phone2": "1133333333", - "vip": false, - "new": false, - "created_at": "2015-06-09" + "risk_level": "low", + "risk_score": 0.5, + "tax_id": "01234567890", + "type": "A1", + "vip": false }, - "recommendation": "approve", - "geolocation": { - "city": "São Paulo", - "state": "SP", - "country": "BR" + "delivery": + { + "delivery_company": "GFL", + "delivery_method": "retira_loja", + "estimated_delivery_date": "2021-05-06", + "estimated_shipping_date": "2021-05-06" }, - "analyze": true, - "shipping": { - "name": "Konduto", - "address1": "R. Teodoro Sampaio, 2393", - "address2": "CJ. 111", - "zip": "05406-200", - "city": "São Paulo", - "state": "SP", - "country": "BR" + "destination_accounts": + [ + { + "amount": 200.0, + "bank_account": "01234-5", + "bank_branch": "0001", + "bank_code": "17298092", + "bank_name": "Itaú BBA", + "holder_name": "José Armando", + "holder_tax_id": "123.456-789-09", + "id": "Conta 003", + "key_type": "pix_evp", + "key_value": "123e4567-e89b-12d3-a456-426655440000" + } + ], + "events": + [ + { + "date": "2021-01-01T03:00:00Z", + "name": "Tia Ana no Maracanã", + "subtype": "sertanejo", + "tickets": + [ + { + "attendee": + { + "dob": "1990-10-28", + "document": "123456789", + "document_type": "cpf" + }, + "category": "regular", + "id": "123456", + "premium": true, + "section": "Pista Premium" + } + ], + "type": "show", + "venue": + { + "address": "Av. Maracanã s/n", + "capacity": 8000, + "city": "Rio de Janeiro", + "country": "BR", + "name": "Estádio do Maracanã", + "state": "RJ" + } + } + ], + "external_device": + { + "browser": "Chrome 104.0.5112.79", + "category": "Mobile", + "fingerprint": "51asd1asd445asd85d4g98s", + "language": "pt-br", + "manufacturer": "Samsung ", + "model": "Galaxy S22 Ultra", + "os": "Android 12 Samsung One UI 4.1", + "platform": "Android", + "provider": "SDK" }, - "billing": { - "name": "Konduto", - "address1": "R. Teodoro Sampaio, 2393", - "address2": "CJ. 111", - "zip": "05406-200", + "first_message": "2015-06-09T18:27:01Z", + "geolocation": + { "city": "São Paulo", - "state": "SP", - "country": "BR" + "country": "BR", + "state": "SP" + }, + "hotel": + { + "address1": "Rod Três, 46", + "address2": "Vidinha", + "category": "Gold", + "city": "Pouso Alto", + "country": "BR", + "name": "Hotel Konduto", + "rooms": + [ + { + "board_basis": "economy", + "check_in_date": "2022-02-14", + "check_out_date": "2022-03-01", + "code": "25487", + "guests": + [ + { + "dob": "1985-05-08", + "document": "12345678990", + "document_type": "cpf", + "name": "João Silva", + "nationality": "BR" + } + ], + "number": "201A", + "number_of_guests": 1, + "type": "A1" + } + ], + "state": "MG", + "zip": "12345-123" + }, + "id": "1", + "installments": 1, + "ip": "192.168.0.1", + "messages_exchanged": 2, + "options": + { + "real_time": true, + "sales_channel": "app" + }, + "origin_account": + { + "balance": 250.0, + "bank_account": "123123", + "bank_branch": "0001", + "bank_code": "00000000", + "bank_name": "Banco do Brasil", + "holder_name": "Alberto Armando", + "holder_tax_id": "123.456.789-09", + "id": "ABC123DEF", + "key_type": "pix_phone", + "key_value": "+5511912341234" }, - "payment": [ + "payment": + [ { - "bin": "123", - "last4": "1234", + "amount": 100.65, + "avs_result": "ok", + "bin": "123456", + "tax_id": "12345678990", + "cvv_result": "valid", "expiration_date": "012014", + "last4": "1234", + "number_of_retries": 1, + "sha1": "1a2b3c4d5e6f7A8B9C10D11E12F1a2b3c4d5e6f7", "status": "approved", "type": "credit" } ], - "shopping_cart": [ + "point_of_sale": + { + "address": "Rua Dez de Abril, 23", + "city": "São Paulo", + "country": "BR", + "id": "000500", + "lat": -23.5677666, + "long": -46.6487763, + "name": "Capital Representações", + "state": "SP", + "zip": "01001-001" + }, + "purchased_at": "2015-06-09T18:27:01Z", + "recommendation": "approve", + "recurring": true, + "risk_level": "low", + "sales_channel": "e-commerce", + "scheduled": false, + "seller": + { + "created_at": "2015-06-09", + "id": "seller_id", + "name": "Seller Name" + }, + "shipping": + { + "address1": "R. Teodoro Sampaio, 2393", + "address2": "CJ. 111", + "city": "São Paulo", + "country": "BR", + "name": "Konduto", + "state": "SP", + "zip": "05406-200", + "estimatedDate": "2022-02-15T12:00:25Z", + "value": 20.0, + "lat": -23.565779450573725, + "lon": -46.691031683668946 + }, + "shipping_amount": 5.0, + "shopping_cart": + [ { - "sku": "9919023", - "product_code": "123456789999", "category": 201, - "name": "Green T-Shirt", + "created_at": "2022-04-25", "description": "Male Green T-Shirt V Neck", + "discount": -10.99, + "image": "https://product_image.test.com/123456789999.png", + "name": "Green T-Shirt", + "product_code": "123456789999", + "quantity": 1.0, + "sku": "9919023", "unit_cost": 1999.99, - "quantity": 1 + "deliveryType": "express delivery", + "deliverySlaInMinutes": 50, + "sellerId": "11" }, { - "sku": "0017273", "category": 202, - "name": "Yellow Socks", + "created_at": "2015-06-09", "description": "Pair of Yellow Socks", - "unit_cost": 29.9, - "quantity": 2, "discount": 5.0, - "created_at": "2015-06-09" + "name": "Yellow Socks", + "quantity": 2.0, + "sku": "0017273", + "unit_cost": 29.9 } ], - "travel": { - "type": "flight", - "departure": { - "origin_airport": "CGH", + "status": "approved", + "tax_amount": 3.0, + "tenant": + { + "created_at": "2022-02-12T12:52:00Z", + "id": "548btm", + "name": "Tenant" + }, + "timestamp": 123123123123, + "total_amount": 120.5, + "travel": + { + "departure": + { + "class": "economy", + "company": "Gol", + "date": "2015-05-07T00:00Z", "destination_airport": "SDU", - "origin_city": "São Paulo", "destination_city": "Rio de Janeiro", - "date": "2015-05-07T00:00Z", + "fare_basis": "Y", "number_of_connections": 0, - "class": "economy", - "fare_basis": "Y" + "origin_airport": "CGH", + "origin_city": "São Paulo" }, - "return": { - "origin_airport": "SDU", + "expiration_date": "2022-05-12T15:25:30Z", + "passengers": + [ + { + "dob": "1970-01-01", + "document": "A1B2C3D4", + "document_type": "id", + "frequent_traveler": true, + "loyalty": + { + "category": "gold", + "program": "advantage" + }, + "name": "Júlia da Silva", + "nationality": "BR", + "special_needs": false + } + ], + "return": + { + "class": "economy", + "company": "Gol", + "date": "2015-05-07T00:00Z", "destination_airport": "CGH", - "origin_city": "Rio de Janeiro", "destination_city": "São Paulo", - "date": "2015-05-07T00:00Z", + "fare_basis": "Y", "number_of_connections": 0, - "class": "economy", - "fare_basis": "Y" + "origin_airport": "SDU", + "origin_city": "Rio de Janeiro" }, - "passengers": [ - { - "name": "Milton Tavares 1", - "document": "A1B2C3D1", - "document_type": "passport", - "frequent_traveler": false, - "special_needs": false - }, - { - "name": "Milton Tavares 2", - "document": "A1B2C3D2", - "document_type": "passport", - "frequent_traveler": false, - "special_needs": false - } - ] + "type": "flight" }, - "seller": { - "id": "seller_id", - "name": "Seller Name", - "created_at": "2015-06-09" + "vehicle": + { + "make": "Bentley", + "model": "Bacalar", + "owner": + { + "name": "Cicero", + "tax_id": "123.123.123-12" + }, + "registration": "ABC1234", + "renavam": "12312312312", + "type": "car", + "usage": "private", + "vid": "5GZCZ43D13S812715" }, - "status": "approved", - "delivery": { - "delivery_company": "GFL", - "delivery_method": "retira_loja", - "estimated_shipping_date": "2021-05-06", - "estimated_delivery_date": "2021-05-06" - } -} + "visitor": "a9031kdlas", + "triggered_decision_list": [ + { + "decision": "DECLINE", + "trigger": "GUEST_DOCUMENT", + "type": "tax_id" + } + ], + "triggered_rules": [ + { + "priority": -2, + "name": "CPFs Monitorados", + "analysis_type": "FRAUD", + "decision": "REVIEW" + } + ], + "analysis_layers": [ + { + "recommendation": "REVIEW", + "original_recommendation": "REVIEW", + "is_exploring": false, + "analysis_type": "FRAUD", + "score": 0.3017217853308364 + } + ] +} \ No newline at end of file diff --git a/test/resources/origin_account.json b/test/resources/origin_account.json new file mode 100644 index 0000000..90feeb3 --- /dev/null +++ b/test/resources/origin_account.json @@ -0,0 +1,12 @@ +{ + "id": "ABC123DEF", + "balance": 250.0, + "key_type": "pix_phone", + "key_value": "+5511912341234", + "bank_code": "00000000", + "bank_name": "Banco do Brasil", + "bank_branch": "0001", + "bank_account": "123123", + "holder_name": "Alberto Armando", + "holder_tax_id": "123.456.789-09" +} \ No newline at end of file diff --git a/test/resources/owner.json b/test/resources/owner.json new file mode 100644 index 0000000..d0b40f0 --- /dev/null +++ b/test/resources/owner.json @@ -0,0 +1,4 @@ +{ + "tax_id": "123.123.123-12", + "name": "Cicero" +} \ No newline at end of file diff --git a/test/resources/payments.json b/test/resources/payments.json index a063607..fc6e7f9 100644 --- a/test/resources/payments.json +++ b/test/resources/payments.json @@ -1,9 +1,20 @@ [ { - "bin": "123", + "bin": "123456", "last4": "1234", "expiration_date": "012014", "status": "approved", - "type": "credit" + "type": "credit", + "amount": 100.65, + "sha1": "1a2b3c4d5e6f7A8B9C10D11E12F1a2b3c4d5e6f7", + "cvv_result": "valid", + "avs_result": "ok", + "number_of_retries": 1, + "tax_id": "12345678990" + }, + { + "type":"voucher", + "amount":10.0, + "description":"Desconto de 10%" } ] diff --git a/test/resources/point_of_sale.json b/test/resources/point_of_sale.json new file mode 100644 index 0000000..09902aa --- /dev/null +++ b/test/resources/point_of_sale.json @@ -0,0 +1,11 @@ +{ + "id":"000500", + "name":"Capital Representações", + "lat":-23.5677666, + "long":-46.6487763, + "address":"Rua Dez de Abril, 23", + "city":"São Paulo", + "state":"SP", + "zip":"01001-001", + "country":"BR" +} \ No newline at end of file diff --git a/test/resources/room.json b/test/resources/room.json new file mode 100644 index 0000000..ac88b49 --- /dev/null +++ b/test/resources/room.json @@ -0,0 +1,18 @@ +{ + "number": "201A", + "code": "25487", + "type": "A1", + "check_in_date": "2022-02-14", + "check_out_date": "2022-03-01", + "number_of_guests": 1, + "board_basis": "economy", + "guests": [ + { + "name": "João Silva", + "document": "12345678990", + "document_type": "cpf", + "dob": "1985-05-08", + "nationality": "BR" + } + ] +} \ No newline at end of file diff --git a/test/resources/shipping_address.json b/test/resources/shipping_address.json new file mode 100644 index 0000000..ea8f7c7 --- /dev/null +++ b/test/resources/shipping_address.json @@ -0,0 +1,13 @@ +{ + "name": "Konduto", + "address1": "R. Teodoro Sampaio, 2393", + "address2": "CJ. 111", + "zip": "05406-200", + "city": "São Paulo", + "state": "SP", + "country": "BR", + "estimatedDate": "2022-02-15T12:00:25Z", + "value": 20.0, + "lat": -23.565779450573725, + "lon": -46.691031683668946 +} diff --git a/test/resources/shopping_cart.json b/test/resources/shopping_cart.json index 2c9e293..a468a30 100644 --- a/test/resources/shopping_cart.json +++ b/test/resources/shopping_cart.json @@ -6,7 +6,13 @@ "name": "Green T-Shirt", "description": "Male Green T-Shirt V Neck", "unit_cost": 1999.99, - "quantity": 1 + "quantity": 1.0, + "discount": -10.99, + "image": "https://product_image.test.com/123456789999.png", + "created_at": "2022-04-25", + "deliveryType": "express delivery", + "deliverySlaInMinutes": 50, + "sellerId": "11" }, { "sku": "0017273", @@ -14,7 +20,7 @@ "name": "Yellow Socks", "description": "Pair of Yellow Socks", "unit_cost": 29.90, - "quantity": 2, + "quantity": 2.0, "discount": 5.00, "created_at": "2015-06-09" } diff --git a/test/resources/tenant.json b/test/resources/tenant.json new file mode 100644 index 0000000..2692790 --- /dev/null +++ b/test/resources/tenant.json @@ -0,0 +1,5 @@ +{ + "id": "548btm", + "name": "Tenant", + "created_at": "2022-02-12T12:52:00Z" +} \ No newline at end of file diff --git a/test/resources/ticket.json b/test/resources/ticket.json new file mode 100644 index 0000000..a62400d --- /dev/null +++ b/test/resources/ticket.json @@ -0,0 +1,11 @@ +{ + "id": "123456", + "category": "regular", + "premium": true, + "section": "Pista Premium", + "attendee": { + "document": "123456789", + "document_type": "cpf", + "dob": "1990-10-28" + } +} \ No newline at end of file diff --git a/test/resources/triggered_decision_list.json b/test/resources/triggered_decision_list.json new file mode 100644 index 0000000..5e6b15c --- /dev/null +++ b/test/resources/triggered_decision_list.json @@ -0,0 +1,7 @@ +[ + { + "decision": "DECLINE", + "trigger": "GUEST_DOCUMENT", + "type": "tax_id" + } +] \ No newline at end of file diff --git a/test/resources/triggered_rules.json b/test/resources/triggered_rules.json new file mode 100644 index 0000000..3af1e50 --- /dev/null +++ b/test/resources/triggered_rules.json @@ -0,0 +1,8 @@ +[ + { + "priority": -2, + "name": "CPFs Monitorados", + "analysis_type": "FRAUD", + "decision": "REVIEW" + } +] \ No newline at end of file diff --git a/test/resources/vehicle.json b/test/resources/vehicle.json new file mode 100644 index 0000000..89cbbbc --- /dev/null +++ b/test/resources/vehicle.json @@ -0,0 +1,13 @@ +{ + "vid": "5GZCZ43D13S812715", + "renavam": "12312312312", + "registration": "ABC1234", + "make": "Bentley", + "model": "Bacalar", + "owner": { + "tax_id": "123.123.123-12", + "name": "Cicero" + }, + "type": "car", + "usage": "private" +} \ No newline at end of file diff --git a/test/resources/venue.json b/test/resources/venue.json new file mode 100644 index 0000000..12e2985 --- /dev/null +++ b/test/resources/venue.json @@ -0,0 +1,8 @@ +{ + "name": "Estádio do Maracanã", + "capacity": 8000, + "address": "Av. Maracanã s/n", + "city": "Rio de Janeiro", + "state": "RJ", + "country": "BR" +} \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 8ae44db..28b00b6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,12 @@ -require 'factory_girl' +# frozen_string_literal: true + +# These lines must go first +require 'factory_bot' +require 'simplecov' +SimpleCov.start def load_resource(resource) JSON.parse(File.read("test/resources/#{resource}")) end -FactoryGirl.find_definitions +FactoryBot.find_definitions diff --git a/test/test_konduto-ruby.rb b/test/test_konduto-ruby.rb index d28edae..c9048c6 100644 --- a/test/test_konduto-ruby.rb +++ b/test/test_konduto-ruby.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'minitest/autorun' require 'konduto-ruby' -class KondutoRubyTest < MiniTest::Test +class KondutoRubyTest < Minitest::Test def test_order_url - assert_equal "https://api.konduto.com/v1/orders", KondutoRuby.new("T738D516F09CAB3A2C1EE").order_url.to_s - assert_equal "https://api.konduto.com/v1/orders/1", KondutoRuby.new("T738D516F09CAB3A2C1EE").order_url(1).to_s + assert_equal 'https://api.konduto.com/v1/orders', KondutoRuby.new('T738D516F09CAB3A2C1EE').order_url.to_s + assert_equal 'https://api.konduto.com/v1/orders/1', KondutoRuby.new('T738D516F09CAB3A2C1EE').order_url(1).to_s end end diff --git a/test/test_konduto_address.rb b/test/test_konduto_address.rb index 3034bbf..3aba9ad 100644 --- a/test/test_konduto_address.rb +++ b/test/test_konduto_address.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' -class KondutoAddressTest < MiniTest::Test - include FactoryGirl::Syntax::Methods +class KondutoAddressTest < Minitest::Test + include FactoryBot::Syntax::Methods def test_serialization address = build(:konduto_address) expectedJSON = load_resource('address.json') actualJSON = address.to_hash - + assert_equal expectedJSON, actualJSON, 'address serialization failed' address_from_json = KondutoAddress.new expectedJSON diff --git a/test/test_konduto_agent.rb b/test/test_konduto_agent.rb new file mode 100644 index 0000000..4d9b07b --- /dev/null +++ b/test/test_konduto_agent.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoAgentTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + agent = build(:konduto_agent) + + expectedJSON = load_resource('agent.json') + actualJSON = agent.to_hash + + assert_equal expectedJSON, actualJSON, 'agent serialization failed' + + agent_from_json = KondutoAgent.new expectedJSON + + assert_equal agent, agent_from_json, 'agent deserialization failed' + end +end diff --git a/test/test_konduto_attendee.rb b/test/test_konduto_attendee.rb new file mode 100644 index 0000000..46eea65 --- /dev/null +++ b/test/test_konduto_attendee.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoAttendeeTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + agent = build(:konduto_attendee) + + expectedJSON = load_resource('attendee.json') + actualJSON = agent.to_hash + + assert_equal expectedJSON, actualJSON, 'attendee serialization failed' + + attendee_from_json = KondutoAttendee.new expectedJSON + + assert_equal agent, attendee_from_json, 'attendee deserialization failed' + end +end diff --git a/test/test_konduto_bus_leg.rb b/test/test_konduto_bus_leg.rb index f1162af..56175cf 100644 --- a/test/test_konduto_bus_leg.rb +++ b/test/test_konduto_bus_leg.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'minitest/autorun' require 'date' @@ -13,9 +15,9 @@ def setup def test_validation bus_leg = KondutoBusLeg.new - assert_equal false, bus_leg.valid? + refute bus_leg.valid? bus_leg.origin_city = 'São Paulo' - assert_equal false, bus_leg.valid? + refute bus_leg.valid? bus_leg.destination_city = 'Rio de Janeiro' assert bus_leg.valid? end diff --git a/test/test_konduto_customer.rb b/test/test_konduto_customer.rb index a572911..66efc0a 100644 --- a/test/test_konduto_customer.rb +++ b/test/test_konduto_customer.rb @@ -1,21 +1,23 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' -class KondutoCustomerTest < MiniTest::Test - include FactoryGirl::Syntax::Methods +class KondutoCustomerTest < Minitest::Test + include FactoryBot::Syntax::Methods def test_validation customer = KondutoCustomer.new - assert_equal false, customer.valid?, 'customer should be invalid without id' + refute customer.valid?, 'customer should be invalid without id' customer.id = 'customer1' - assert_equal false, customer.valid?, 'customer should be invalid without name' + refute customer.valid?, 'customer should be invalid without name' customer.name = 'José da Silva' - assert_equal false, customer.valid?, 'customer should be invalid without email' + refute customer.valid?, 'customer should be invalid without email' customer.email = 'jose.silva@gmail.com' - assert_equal true, customer.valid?, 'customer should be valid' + assert customer.valid?, 'customer should be valid' end def test_serialization diff --git a/test/test_konduto_delivery.rb b/test/test_konduto_delivery.rb index 741faa7..ba038f0 100644 --- a/test/test_konduto_delivery.rb +++ b/test/test_konduto_delivery.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' -class KondutoDeliveryTest < MiniTest::Test - include FactoryGirl::Syntax::Methods +class KondutoDeliveryTest < Minitest::Test + include FactoryBot::Syntax::Methods def setup @json = load_resource('delivery.json') diff --git a/test/test_konduto_destination_account.rb b/test/test_konduto_destination_account.rb new file mode 100644 index 0000000..8febd55 --- /dev/null +++ b/test/test_konduto_destination_account.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoDestinationAccountTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + dest_account = build(:konduto_destination_account) + + expectedJSON = load_resource('destination_accounts.json').first + actualJSON = dest_account.to_hash + + assert_equal expectedJSON, actualJSON, 'Destination account serialization failed' + + dest_account_from_json = KondutoDestinationAccount.new expectedJSON + + assert_equal dest_account, dest_account_from_json, 'Destination account deserialization failed' + end +end diff --git a/test/test_konduto_device.rb b/test/test_konduto_device.rb index 57de5ab..ef816a6 100644 --- a/test/test_konduto_device.rb +++ b/test/test_konduto_device.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' -class KondutoDeviceTest < MiniTest::Test - include FactoryGirl::Syntax::Methods +class KondutoDeviceTest < Minitest::Test + include FactoryBot::Syntax::Methods def test_serialization device = build(:konduto_device) diff --git a/test/test_konduto_event.rb b/test/test_konduto_event.rb new file mode 100644 index 0000000..54de932 --- /dev/null +++ b/test/test_konduto_event.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoEventTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + event = build(:konduto_event) + + expectedJSON = load_resource('events.json').first + actualJSON = event.to_hash + + assert_equal expectedJSON, actualJSON, 'Event serialization failed' + + event_from_json = KondutoEvent.new expectedJSON + + assert_equal event, event_from_json, 'Event deserialization failed' + end +end diff --git a/test/test_konduto_external_device.rb b/test/test_konduto_external_device.rb new file mode 100644 index 0000000..8d12200 --- /dev/null +++ b/test/test_konduto_external_device.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoExternalDeviceTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + ext_device = build(:konduto_external_device) + + expectedJSON = load_resource('external_device.json') + actualJSON = ext_device.to_hash + + assert_equal expectedJSON, actualJSON, 'External Device serialization failed' + + ext_device_from_json = KondutoExternalDevice.new expectedJSON + + assert_equal ext_device, ext_device_from_json, 'External Device deserialization failed' + end +end diff --git a/test/test_konduto_flight_leg.rb b/test/test_konduto_flight_leg.rb index fc429b8..c30b3db 100644 --- a/test/test_konduto_flight_leg.rb +++ b/test/test_konduto_flight_leg.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'minitest/autorun' require 'date' require 'konduto-ruby' @@ -7,7 +9,7 @@ def setup @params = { origin_airport: 'CGH', destination_airport: 'SDU', - date: 2015-05-07, + date: 2015 - 0o5 - 0o7, fare_basis: 'Y', number_of_connections: 1, class: 'economy' @@ -16,19 +18,19 @@ def setup def test_validation travel_leg = KondutoFlightLeg.new - assert_equal false, travel_leg.valid?, 'travel leg should be invalid' + refute travel_leg.valid?, 'travel leg should be invalid' # is invalid if airport IATA code is missing or not formed by 3 letters travel_leg.origin_airport = '123' - assert_equal false, travel_leg.valid?, 'airport name must be formed by letters' + refute travel_leg.valid?, 'airport name must be formed by letters' travel_leg.origin_airport = 'CGH' - assert_equal false, travel_leg.valid?, 'travel leg must have a destination_airport' + refute travel_leg.valid?, 'travel leg must have a destination_airport' - travel_leg.destination_airport = "123" - assert_equal false, travel_leg.valid?, 'airport name must be formed by letters' + travel_leg.destination_airport = '123' + refute travel_leg.valid?, 'airport name must be formed by letters' travel_leg.destination_airport = 'SDU' - assert_equal true, travel_leg.valid?, 'travel leg should be valid' + assert travel_leg.valid?, 'travel leg should be valid' end def test_serialization diff --git a/test/test_konduto_geolocation.rb b/test/test_konduto_geolocation.rb index 916271a..a5090b5 100644 --- a/test/test_konduto_geolocation.rb +++ b/test/test_konduto_geolocation.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' class TestKondutoGeolocation < Minitest::Test - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods def test_serialization geolocation = build(:konduto_geolocation) diff --git a/test/test_konduto_guest.rb b/test/test_konduto_guest.rb new file mode 100644 index 0000000..0829d30 --- /dev/null +++ b/test/test_konduto_guest.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoGuestTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + guest = build(:konduto_guest) + + expectedJSON = load_resource('guest.json') + actualJSON = guest.to_hash + + assert_equal expectedJSON, actualJSON, 'Guest serialization failed' + + guest_from_json = KondutoGuest.new expectedJSON + + assert_equal guest, guest_from_json, 'Guest deserialization failed' + end +end diff --git a/test/test_konduto_hotel.rb b/test/test_konduto_hotel.rb new file mode 100644 index 0000000..04194dd --- /dev/null +++ b/test/test_konduto_hotel.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoHotelTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + hotel = build(:konduto_hotel) + + expectedJSON = load_resource('hotel.json') + actualJSON = hotel.to_hash + + assert_equal expectedJSON, actualJSON, 'Hotel serialization failed' + + hotel_from_json = KondutoHotel.new expectedJSON + + assert_equal hotel, hotel_from_json, 'Hotel deserialization failed' + end +end diff --git a/test/test_konduto_item.rb b/test/test_konduto_item.rb index 2b02322..763d62e 100644 --- a/test/test_konduto_item.rb +++ b/test/test_konduto_item.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' class TestKondutoItem < Minitest::Test - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods def test_serialization item = build(:konduto_item, :green_shirt) diff --git a/test/test_konduto_loyalty.rb b/test/test_konduto_loyalty.rb new file mode 100644 index 0000000..64f5593 --- /dev/null +++ b/test/test_konduto_loyalty.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoLoyaltyTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + loyalty = build(:konduto_loyalty) + + expectedJSON = load_resource('loyalty.json') + actualJSON = loyalty.to_hash + + assert_equal expectedJSON, actualJSON, 'loyalty serialization failed' + + loyalty_from_json = KondutoLoyalty.new expectedJSON + + assert_equal loyalty, loyalty_from_json, 'loyalty deserialization failed' + end +end diff --git a/test/test_konduto_navigation.rb b/test/test_konduto_navigation.rb index 9aee194..7c2b5e5 100644 --- a/test/test_konduto_navigation.rb +++ b/test/test_konduto_navigation.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' class TestKondutoNavigation < Minitest::Test - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods def test_serialization navigation = build(:konduto_navigation) diff --git a/test/test_konduto_options.rb b/test/test_konduto_options.rb new file mode 100644 index 0000000..98c09a5 --- /dev/null +++ b/test/test_konduto_options.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoOptionsTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + options = build(:konduto_options) + + expectedJSON = load_resource('options.json') + actualJSON = options.to_hash + + assert_equal expectedJSON, actualJSON, 'options serialization failed' + + options_from_json = KondutoOptions.new expectedJSON + + assert_equal options, options_from_json, 'options deserialization failed' + end +end diff --git a/test/test_konduto_order.rb b/test/test_konduto_order.rb index ccf1502..d5890c7 100644 --- a/test/test_konduto_order.rb +++ b/test/test_konduto_order.rb @@ -1,23 +1,25 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' require 'konduto-ruby' -class KondutoOrderTest < MiniTest::Test - include FactoryGirl::Syntax::Methods +class KondutoOrderTest < Minitest::Test + include FactoryBot::Syntax::Methods def setup - FactoryGirl.reload + FactoryBot.reload end def test_valid order = KondutoOrder.new - assert_equal false, order.valid?, 'order should be invalid without id' + refute order.valid?, 'order should be invalid without id' order.id = 'order1' - assert_equal false, order.valid?, 'order should be invalid without total amount' + refute order.valid?, 'order should be invalid without total amount' order.total_amount = 120.1 - assert_equal false, order.valid?, 'order should be invalid without customer' + refute order.valid?, 'order should be invalid without customer' order.customer = KondutoCustomer.new assert order.valid?, 'order should be valid' @@ -36,6 +38,6 @@ def test_serialization def test_invalid_serialization order = KondutoOrder.new - assert_raises(RuntimeError){ order.to_json } + assert_raises(RuntimeError) { order.to_json } end end diff --git a/test/test_konduto_origin_account.rb b/test/test_konduto_origin_account.rb new file mode 100644 index 0000000..78f75dd --- /dev/null +++ b/test/test_konduto_origin_account.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoOriginAccountTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + origin_account = build(:konduto_origin_account) + + expectedJSON = load_resource('origin_account.json') + actualJSON = origin_account.to_hash + + assert_equal expectedJSON, actualJSON, 'origin account serialization failed' + + origin_account_from_json = KondutoOriginAccount.new expectedJSON + + assert_equal origin_account, origin_account_from_json, 'origin account deserialization failed' + end +end diff --git a/test/test_konduto_owner.rb b/test/test_konduto_owner.rb new file mode 100644 index 0000000..ce54f40 --- /dev/null +++ b/test/test_konduto_owner.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoOwnerTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + owner = build(:konduto_owner) + + expectedJSON = load_resource('owner.json') + actualJSON = owner.to_hash + + assert_equal expectedJSON, actualJSON, 'owner serialization failed' + + owner_from_json = KondutoOwner.new expectedJSON + + assert_equal owner, owner_from_json, 'owner deserialization failed' + end +end diff --git a/test/test_konduto_passenger.rb b/test/test_konduto_passenger.rb index e7d9613..fcb74b3 100644 --- a/test/test_konduto_passenger.rb +++ b/test/test_konduto_passenger.rb @@ -1,26 +1,28 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' class TestKondutoPassenger < Minitest::Test - include FactoryGirl::Syntax::Methods + include FactoryBot::Syntax::Methods def test_validation passenger = KondutoPassenger.new - assert_equal false, passenger.valid?, 'should be invalid without name' + refute passenger.valid?, 'should be invalid without name' passenger.name = 'Milton Tavares' - assert_equal false, passenger.valid?, 'should be invalid without document' + refute passenger.valid?, 'should be invalid without document' passenger.document = 'A1B2C3D4' - assert_equal false, passenger.valid?, 'should be invalid without document type' + refute passenger.valid?, 'should be invalid without document type' passenger.document_type = :passport - assert_equal false, passenger.valid?, 'should be invalid without nationality' + refute passenger.valid?, 'should be invalid without nationality' passenger.nationality = '123' - assert_equal false, passenger.valid?, 'should be invalid if not a 2 chars string' + refute passenger.valid?, 'should be invalid if not a 2 chars string' passenger.nationality = 'BR' - assert_equal true, passenger.valid?, 'should be a valid passenger' + assert passenger.valid?, 'should be a valid passenger' end def test_serialization diff --git a/test/test_konduto_payment.rb b/test/test_konduto_payment.rb index c67283c..3409b7f 100644 --- a/test/test_konduto_payment.rb +++ b/test/test_konduto_payment.rb @@ -1,13 +1,17 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' -class KondutoPaymentTest < MiniTest::Test - include FactoryGirl::Syntax::Methods +class KondutoPaymentTest < Minitest::Test + include FactoryBot::Syntax::Methods def test_serialization - payment = build_list(:konduto_payment, 1, :credit_card) + payments = [] + payments << build(:konduto_payment, :credit_card) + payments << build(:konduto_payment, :voucher) payment_json = load_resource('payments.json') - assert_equal payment_json, payment.map { |value| value.to_hash }, 'serialization failed' + assert_equal payment_json, payments.map(&:to_hash), 'serialization failed' end end diff --git a/test/test_konduto_point_of_sale.rb b/test/test_konduto_point_of_sale.rb new file mode 100644 index 0000000..b3dcef6 --- /dev/null +++ b/test/test_konduto_point_of_sale.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoPointOfSaleTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + point_of_sale = build(:konduto_point_of_sale) + + expectedJSON = load_resource('point_of_sale.json') + actualJSON = point_of_sale.to_hash + + assert_equal expectedJSON, actualJSON, 'point of sale serialization failed' + + point_of_sale_from_json = KondutoPointOfSale.new expectedJSON + + assert_equal point_of_sale, point_of_sale_from_json, 'point of sale deserialization failed' + end +end diff --git a/test/test_konduto_room.rb b/test/test_konduto_room.rb new file mode 100644 index 0000000..2921a28 --- /dev/null +++ b/test/test_konduto_room.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoRoomTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + room_account = build(:konduto_room) + + expectedJSON = load_resource('room.json') + actualJSON = room_account.to_hash + + assert_equal expectedJSON, actualJSON, 'room serialization failed' + + room_from_json = KondutoRoom.new expectedJSON + + assert_equal room_account, room_from_json, 'room deserialization failed' + end +end diff --git a/test/test_konduto_seller.rb b/test/test_konduto_seller.rb index e253c5b..411beb2 100644 --- a/test/test_konduto_seller.rb +++ b/test/test_konduto_seller.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' class TestKondutoSeller < Minitest::Test - include FactoryGirl::Syntax::Methods - + include FactoryBot::Syntax::Methods + def test_serialization seller = build(:konduto_seller) sellerJSON = load_resource('seller.json') diff --git a/test/test_konduto_shipping_address.rb b/test/test_konduto_shipping_address.rb new file mode 100644 index 0000000..ccc4edb --- /dev/null +++ b/test/test_konduto_shipping_address.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoShippingAddressTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + address = build(:konduto_shipping_address) + + expectedJSON = load_resource('shipping_address.json') + actualJSON = address.to_hash + + assert_equal expectedJSON, actualJSON, 'address serialization failed' + + address_from_json = KondutoShippingAddress.new expectedJSON + + assert_equal address, address_from_json, 'address deserialization failed' + end +end diff --git a/test/test_konduto_tenant.rb b/test/test_konduto_tenant.rb new file mode 100644 index 0000000..ff1514c --- /dev/null +++ b/test/test_konduto_tenant.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoTenantTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + tenant = build(:konduto_tenant) + + expectedJSON = load_resource('tenant.json') + actualJSON = tenant.to_hash + + assert_equal expectedJSON, actualJSON, 'tenant serialization failed' + + tenant_from_json = KondutoTenant.new expectedJSON + + assert_equal tenant, tenant_from_json, 'tenant deserialization failed' + end +end diff --git a/test/test_konduto_ticket.rb b/test/test_konduto_ticket.rb new file mode 100644 index 0000000..1d92798 --- /dev/null +++ b/test/test_konduto_ticket.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoTicketTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + ticket = build(:konduto_ticket) + + expectedJSON = load_resource('ticket.json') + actualJSON = ticket.to_hash + + assert_equal expectedJSON, actualJSON, 'ticket serialization failed' + + ticket_from_json = KondutoTicket.new expectedJSON + + assert_equal ticket, ticket_from_json, 'ticket deserialization failed' + end +end diff --git a/test/test_konduto_travel.rb b/test/test_konduto_travel.rb index 02231ae..f8150de 100644 --- a/test/test_konduto_travel.rb +++ b/test/test_konduto_travel.rb @@ -1,21 +1,23 @@ +# frozen_string_literal: true + require 'minitest/autorun' -require 'factory_girl' +require 'factory_bot' -class KondutoTravelTest < MiniTest::Test - include FactoryGirl::Syntax::Methods +class KondutoTravelTest < Minitest::Test + include FactoryBot::Syntax::Methods def test_validation travel = KondutoTravel.new - assert_equal false, travel.valid?, 'should be invalid without a type' + refute travel.valid?, 'should be invalid without a type' travel.type = :flight - assert_equal false, travel.valid?, 'should be invalid without departure leg' + refute travel.valid?, 'should be invalid without departure leg' travel.departure = build(:konduto_flight_leg) - assert_equal false, travel.valid?, 'should be invalid without passengers' + refute travel.valid?, 'should be invalid without passengers' travel.passengers = build_list(:konduto_passenger, 2) - assert_equal true, travel.valid?, 'should be valid without a return leg' + assert travel.valid?, 'should be valid without a return leg' travel.return = build(:konduto_flight_leg) assert travel.valid?, 'should continue value' diff --git a/test/test_konduto_utils.rb b/test/test_konduto_utils.rb new file mode 100644 index 0000000..dc9a27e --- /dev/null +++ b/test/test_konduto_utils.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoUtilsTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_parameterize_key_with_single_word + assert_equal 'classe', KondutoUtils.parameterize_key('Classe') + end + + def test_parameterize_key_with_pascal_case + assert_equal 'some_classe', KondutoUtils.parameterize_key('SomeClasse') + end + + def test_parameterize_key_with_camel_case + assert_equal 'some_classe_name', KondutoUtils.parameterize_key('someClasseName') + end + + def test_parameterize_key_with_long_pascal_case + assert_equal 'another_classe_with_a_long_name', KondutoUtils.parameterize_key('AnotherClasseWithALongName') + end + + def test_parameterize_key_with_acronym + assert_equal 'http_request_handler', KondutoUtils.parameterize_key('HTTPRequestHandler') + end + + def test_parameterize_key_with_symbol + assert_equal 'some_key', KondutoUtils.parameterize_key(:SomeKey) + end + + def test_parameterize_key_with_snake_case + assert_equal 'already_snake_case', KondutoUtils.parameterize_key('already_snake_case') + end + + def test_parameterize_key_with_empty_string + assert_equal '', KondutoUtils.parameterize_key('') + end + + def test_parameterize_key_with_numbers + assert_equal 'version2_controller', KondutoUtils.parameterize_key('Version2Controller') + end +end diff --git a/test/test_konduto_vehicle.rb b/test/test_konduto_vehicle.rb new file mode 100644 index 0000000..ffc7dca --- /dev/null +++ b/test/test_konduto_vehicle.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoVehicleTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + vehicle = build(:konduto_vehicle) + + expectedJSON = load_resource('vehicle.json') + actualJSON = vehicle.to_hash + + assert_equal expectedJSON, actualJSON, 'vehicle serialization failed' + + vehicle_from_json = KondutoVehicle.new expectedJSON + + assert_equal vehicle, vehicle_from_json, 'vehicle deserialization failed' + end +end diff --git a/test/test_konduto_venue.rb b/test/test_konduto_venue.rb new file mode 100644 index 0000000..7ac4508 --- /dev/null +++ b/test/test_konduto_venue.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'factory_bot' + +class KondutoVenueTest < Minitest::Test + include FactoryBot::Syntax::Methods + + def test_serialization + venue = build(:konduto_venue) + + expectedJSON = load_resource('venue.json') + actualJSON = venue.to_hash + + assert_equal expectedJSON, actualJSON, 'venue serialization failed' + + venue_from_json = KondutoVenue.new expectedJSON + + assert_equal venue, venue_from_json, 'venue deserialization failed' + end +end