diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..13566b81b0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000000..a55e7a179b --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/desafio-dev.iml b/.idea/desafio-dev.iml new file mode 100644 index 0000000000..6e7c09c280 --- /dev/null +++ b/.idea/desafio-dev.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..75f7d7b91d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..e790241d40 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/billing.iml b/.idea/modules/billing.iml new file mode 100644 index 0000000000..ddb090beaf --- /dev/null +++ b/.idea/modules/billing.iml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..cabddbfef4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/billing/.gitattributes b/billing/.gitattributes new file mode 100644 index 0000000000..31eeee0b6a --- /dev/null +++ b/billing/.gitattributes @@ -0,0 +1,7 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored diff --git a/billing/.gitignore b/billing/.gitignore new file mode 100644 index 0000000000..e16dc71d2b --- /dev/null +++ b/billing/.gitignore @@ -0,0 +1,31 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore uploaded files in development. +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +/public/assets + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/billing/.rspec b/billing/.rspec new file mode 100644 index 0000000000..c99d2e7396 --- /dev/null +++ b/billing/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/billing/.ruby-version b/billing/.ruby-version new file mode 100644 index 0000000000..2a49746976 --- /dev/null +++ b/billing/.ruby-version @@ -0,0 +1 @@ +ruby-3.1.1 diff --git a/billing/Dockerfile b/billing/Dockerfile new file mode 100644 index 0000000000..e8d061b1c1 --- /dev/null +++ b/billing/Dockerfile @@ -0,0 +1,31 @@ +FROM ruby:3.1.1 + +# add nodejs and yarn dependencies for the frontend +RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - && \ +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ +echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + +# Instala nossas dependencias +RUN apt-get update && apt-get install -qq -y --no-install-recommends \ +nodejs yarn build-essential libpq-dev imagemagick git-all nano + +# Instalar bundler +RUN gem install bundler + +# Seta nosso path +ENV INSTALL_PATH /billing + +# Cria nosso diretório +RUN mkdir -p $INSTALL_PATH + +# Seta o nosso path como o diretório principal +WORKDIR $INSTALL_PATH + +# Copia o nosso Gemfile para dentro do container +COPY Gemfile ./ + +# Seta o path para as Gems +ENV BUNDLE_PATH /gems + +# Copia nosso código para dentro do container +COPY . . \ No newline at end of file diff --git a/billing/Gemfile b/billing/Gemfile new file mode 100644 index 0000000000..ff205db96e --- /dev/null +++ b/billing/Gemfile @@ -0,0 +1,82 @@ +source "https://rubygems.org" +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby "3.1.1" + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 7.0.2", ">= 7.0.2.4" + +# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] +gem "sprockets-rails" + +# Use postgresql as the database for Active Record +gem "pg", "~> 1.1" + +# Use the Puma web server [https://github.com/puma/puma] +gem "puma", "~> 5.0" + +# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] +gem "importmap-rails" + +# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] +gem "turbo-rails" + +# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] +gem "stimulus-rails" + +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +gem "jbuilder" + +# Use Redis adapter to run Action Cable in production +# gem "redis", "~> 4.0" + +# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] +# gem "kredis" + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] + +# Reduces boot times through caching; required in config/boot.rb +gem "bootsnap", require: false + +#validate CPF +gem 'cpf_cnpj' + +# Use Sass to process CSS +# gem "sassc-rails" + +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem "image_processing", "~> 1.2" + +group :development, :test do + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem "debug", platforms: %i[ mri mingw x64_mingw ] + gem 'factory_bot_rails' + gem 'faker' + gem 'rspec-rails', '~> 4.0.1' + gem 'shoulda-matchers', '~> 4.0' + gem 'ffaker' + gem 'pry' + gem 'cpf_faker' +end + +group :development do + # Use console on exceptions pages [https://github.com/rails/web-console] + gem "web-console" + + # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] + # gem "rack-mini-profiler" + + # Speed up commands on slow machines / big apps [https://github.com/rails/spring] + # gem "spring" +end + +group :test do + # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] + gem "capybara" + gem "selenium-webdriver" + gem "webdrivers" +end diff --git a/billing/Gemfile.lock b/billing/Gemfile.lock new file mode 100644 index 0000000000..05e4204631 --- /dev/null +++ b/billing/Gemfile.lock @@ -0,0 +1,278 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.0.2.4) + actionpack (= 7.0.2.4) + activesupport (= 7.0.2.4) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.2.4) + actionpack (= 7.0.2.4) + activejob (= 7.0.2.4) + activerecord (= 7.0.2.4) + activestorage (= 7.0.2.4) + activesupport (= 7.0.2.4) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.2.4) + actionpack (= 7.0.2.4) + actionview (= 7.0.2.4) + activejob (= 7.0.2.4) + activesupport (= 7.0.2.4) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.0) + actionpack (7.0.2.4) + actionview (= 7.0.2.4) + activesupport (= 7.0.2.4) + rack (~> 2.0, >= 2.2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.2.4) + actionpack (= 7.0.2.4) + activerecord (= 7.0.2.4) + activestorage (= 7.0.2.4) + activesupport (= 7.0.2.4) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.2.4) + activesupport (= 7.0.2.4) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.2.4) + activesupport (= 7.0.2.4) + globalid (>= 0.3.6) + activemodel (7.0.2.4) + activesupport (= 7.0.2.4) + activerecord (7.0.2.4) + activemodel (= 7.0.2.4) + activesupport (= 7.0.2.4) + activestorage (7.0.2.4) + actionpack (= 7.0.2.4) + activejob (= 7.0.2.4) + activerecord (= 7.0.2.4) + activesupport (= 7.0.2.4) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.2.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.0) + public_suffix (>= 2.0.2, < 5.0) + bindex (0.8.1) + bootsnap (1.11.1) + msgpack (~> 1.2) + builder (3.2.4) + capybara (3.36.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + childprocess (4.1.0) + clipboard (1.3.6) + coderay (1.1.3) + concurrent-ruby (1.1.10) + cpf_cnpj (0.5.0) + cpf_faker (1.3.0) + clipboard + crass (1.0.6) + debug (1.5.0) + irb (>= 1.3.6) + reline (>= 0.2.7) + diff-lcs (1.5.0) + digest (3.1.0) + erubi (1.10.0) + factory_bot (6.2.1) + activesupport (>= 5.0.0) + factory_bot_rails (6.2.0) + factory_bot (~> 6.2.0) + railties (>= 5.0.0) + faker (2.20.0) + i18n (>= 1.8.11, < 2) + ffaker (2.21.0) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.10.0) + concurrent-ruby (~> 1.0) + importmap-rails (1.0.3) + actionpack (>= 6.0.0) + railties (>= 6.0.0) + io-console (0.5.11) + irb (1.4.1) + reline (>= 0.3.0) + jbuilder (2.11.5) + actionview (>= 5.0.0) + activesupport (>= 5.0.0) + loofah (2.17.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (1.0.2) + matrix (0.4.2) + method_source (1.0.0) + mini_mime (1.1.2) + minitest (5.15.0) + msgpack (1.5.1) + net-imap (0.2.3) + digest + net-protocol + strscan + net-pop (0.1.1) + digest + net-protocol + timeout + net-protocol (0.1.3) + timeout + net-smtp (0.3.1) + digest + net-protocol + timeout + nio4r (2.5.8) + nokogiri (1.13.4-x86_64-linux) + racc (~> 1.4) + pg (1.3.5) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (4.0.7) + puma (5.6.4) + nio4r (~> 2.0) + racc (1.6.0) + rack (2.2.3) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (7.0.2.4) + actioncable (= 7.0.2.4) + actionmailbox (= 7.0.2.4) + actionmailer (= 7.0.2.4) + actionpack (= 7.0.2.4) + actiontext (= 7.0.2.4) + actionview (= 7.0.2.4) + activejob (= 7.0.2.4) + activemodel (= 7.0.2.4) + activerecord (= 7.0.2.4) + activestorage (= 7.0.2.4) + activesupport (= 7.0.2.4) + bundler (>= 1.15.0) + railties (= 7.0.2.4) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.2) + loofah (~> 2.3) + railties (7.0.2.4) + actionpack (= 7.0.2.4) + activesupport (= 7.0.2.4) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rake (13.0.6) + regexp_parser (2.3.1) + reline (0.3.1) + io-console (~> 0.5) + rexml (3.2.5) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.11.0) + rspec-rails (4.0.2) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.11.0) + rubyzip (2.3.2) + selenium-webdriver (4.1.0) + childprocess (>= 0.5, < 5.0) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2) + shoulda-matchers (4.5.1) + activesupport (>= 4.2.0) + sprockets (4.0.3) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + stimulus-rails (1.0.4) + railties (>= 6.0.0) + strscan (3.0.1) + thor (1.2.1) + timeout (0.2.0) + turbo-rails (1.0.1) + actionpack (>= 6.0.0) + railties (>= 6.0.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + web-console (4.2.0) + actionview (>= 6.0.0) + activemodel (>= 6.0.0) + bindex (>= 0.4.0) + railties (>= 6.0.0) + webdrivers (5.0.0) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (~> 4.0) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.5.4) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + bootsnap + capybara + cpf_cnpj + cpf_faker + debug + factory_bot_rails + faker + ffaker + importmap-rails + jbuilder + pg (~> 1.1) + pry + puma (~> 5.0) + rails (~> 7.0.2, >= 7.0.2.4) + rspec-rails (~> 4.0.1) + selenium-webdriver + shoulda-matchers (~> 4.0) + sprockets-rails + stimulus-rails + turbo-rails + tzinfo-data + web-console + webdrivers + +RUBY VERSION + ruby 3.1.1p18 + +BUNDLED WITH + 2.3.12 diff --git a/billing/README.md b/billing/README.md new file mode 100644 index 0000000000..acdbb33fd8 --- /dev/null +++ b/billing/README.md @@ -0,0 +1,66 @@ +# README +💻 **Stack** + +- Ruby 3.1.1 + +- Rails 7.0.2 + +- Host machine dependencies + - [Docker (CE)](https://docs.docker.com/engine/installation/) + - [Docker Compose](https://docs.docker.com/compose/install/) + +🚀 **To start the Rails app, run:** + +- ⚠️ Is it your first time? ⚠️ + + - Create a external volume to share gems across containers: + ```bash + docker-compose build + ``` + Note: If your docker commands only work using sudo before, run the following command in the console to fix it: + - ```bash + sudo groupadd docker + ``` + - ```bash + sudo usermod -aG docker $USER + ``` + - ```bash + sudo service docker restart + ``` + - Load all needed gems into `gems_ops` external volume: + ```bash + docker-compose run --rm app bundle install + ``` +- Starting all stack (_add `-d` flag to run in background_): + + - Follow the `Starting all stack` section + ```bash + docker-compose up + ``` +🛠 **Useful commands:** + +- Start Rails console: + ```bash + docker-compose run --rm app bundle exec rails c + ``` +- Execute create DB: + ```bash + docker-compose run --rm app bundle exec rails db:create + ``` +- Execute migration: + ```bash + docker-compose run --rm app bundle exec rails db:migrate + ``` +- Execute Webpack: + ```bash + docker-compose run --rm app bundle exec rails webpacker:install + ``` +- Access database console: + ```bash + docker-compose run --rm app bundle exec rails dbconsole + ``` +- Test a specific file + + ```bash + docker-compose run --rm app bundle exec rspec ./spec/services/name_file.rb' + ``` \ No newline at end of file diff --git a/billing/Rakefile b/billing/Rakefile new file mode 100644 index 0000000000..9a5ea7383a --- /dev/null +++ b/billing/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/billing/app/assets/config/manifest.js b/billing/app/assets/config/manifest.js new file mode 100644 index 0000000000..591819335f --- /dev/null +++ b/billing/app/assets/config/manifest.js @@ -0,0 +1,2 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css diff --git a/billing/app/assets/images/.keep b/billing/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/app/assets/stylesheets/application.css b/billing/app/assets/stylesheets/application.css new file mode 100644 index 0000000000..288b9ab718 --- /dev/null +++ b/billing/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/billing/app/channels/application_cable/channel.rb b/billing/app/channels/application_cable/channel.rb new file mode 100644 index 0000000000..d672697283 --- /dev/null +++ b/billing/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/billing/app/channels/application_cable/connection.rb b/billing/app/channels/application_cable/connection.rb new file mode 100644 index 0000000000..0ff5442f47 --- /dev/null +++ b/billing/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/billing/app/controllers/application_controller.rb b/billing/app/controllers/application_controller.rb new file mode 100644 index 0000000000..09705d12ab --- /dev/null +++ b/billing/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/billing/app/controllers/concerns/.keep b/billing/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/app/controllers/imports_controller.rb b/billing/app/controllers/imports_controller.rb new file mode 100644 index 0000000000..367fe1082a --- /dev/null +++ b/billing/app/controllers/imports_controller.rb @@ -0,0 +1,28 @@ +class ImportsController < ApplicationController + before_action :importer_params + + def import_file + key_file = params.keys.reject { |x| ['action', 'controller'].include?(x) }&.first + path = params[key_file]&.path + + return default_error unless path.present? + + importer = Importer.new(path) + + if importer.import_and_create_data + render json: { success: true, message: 'Upload and creation data make with successful!' } + else + default_error + end + end + + private + + def default_error + render json: { success: false, message: 'Something is wrong!' } + end + + def valid_params + params.permit(:files) + end +end \ No newline at end of file diff --git a/billing/app/controllers/transactions_controller.rb b/billing/app/controllers/transactions_controller.rb new file mode 100644 index 0000000000..7b0df7a4e7 --- /dev/null +++ b/billing/app/controllers/transactions_controller.rb @@ -0,0 +1,37 @@ +class TransactionsController < ApplicationController + before_action :transactions_params + + def index + transactions = [] + @providers = Provider.all + + @providers.each do |provider| + transactions_by_provider = Transaction.where(provider_id: provider.id) + provider_name = capitalize_name(provider.name_provider) + provider_owner = capitalize_name(provider.name_owner) + total_balance = transactions_by_provider.map(&:value).sum + + transactions << { + provider_name: provider_name, + provider_owner: provider_owner, + total_balance: "R$#{total_balance.to_s}" + } + end + + render json: { success: true, transactions: transactions } + end + + private + + def capitalize_name(name) + name.split(' ')&.map { |x| x.capitalize }.join(' ') + end + + def default_error + render json: { success: false, message: 'Something is wrong!' } + end + + def transactions_params + params.permit(:id) + end +end \ No newline at end of file diff --git a/billing/app/helpers/application_helper.rb b/billing/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/billing/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/billing/app/jobs/application_job.rb b/billing/app/jobs/application_job.rb new file mode 100644 index 0000000000..d394c3d106 --- /dev/null +++ b/billing/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/billing/app/mailers/application_mailer.rb b/billing/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..3c34c8148f --- /dev/null +++ b/billing/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout "mailer" +end diff --git a/billing/app/models/application_record.rb b/billing/app/models/application_record.rb new file mode 100644 index 0000000000..b63caeb8a5 --- /dev/null +++ b/billing/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/billing/app/models/concerns/.keep b/billing/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/app/models/customer.rb b/billing/app/models/customer.rb new file mode 100644 index 0000000000..be8646866b --- /dev/null +++ b/billing/app/models/customer.rb @@ -0,0 +1,16 @@ +class Customer < ApplicationRecord + validate :cpf_valid, on: %i[create update] + validates :cpf, presence: true, uniqueness: true + + def cpf_valid + return errors.add(:base, "CPF #{self.cpf} invalid") unless CPF.valid?(self.cpf) + end + + private + + def record_exists? + return false unless Customer.find_by_cpf(self.cpf).present? + + true + end +end diff --git a/billing/app/models/provider.rb b/billing/app/models/provider.rb new file mode 100644 index 0000000000..626c779b92 --- /dev/null +++ b/billing/app/models/provider.rb @@ -0,0 +1,15 @@ +class Provider < ApplicationRecord + validate :name_provider_valid, on: %i[create] + + def name_provider_valid + return errors.add(:base, "Nome da Loja #{self.name_provider} já cadastrado") if name_provider_exists? + end + + private + + def name_provider_exists? + return false unless Provider.where('lower(name_provider) LIKE ?', "%#{self.name_provider.downcase}%").present? + + true + end +end diff --git a/billing/app/models/transaction.rb b/billing/app/models/transaction.rb new file mode 100644 index 0000000000..bb6b8e405b --- /dev/null +++ b/billing/app/models/transaction.rb @@ -0,0 +1,19 @@ +class Transaction < ApplicationRecord + before_save :set_transaction_nature_and_signal + + TRANSACTION_TYPES_DEBITS = %w[boleto financiamento aluguel].freeze + + validates :transaction_type, presence: true + belongs_to :customer + belongs_to :provider + + enum transaction_type: %i[debit credit ticket financing receivable sales ted doc rent] + + + def set_transaction_nature_and_signal + signal = !TRANSACTION_TYPES_DEBITS.include?(self.transaction_type) + nature = signal ? 'Entrada' : 'Saída'/ + self.signal = signal + self.nature = nature + end +end diff --git a/billing/app/services/importer.rb b/billing/app/services/importer.rb new file mode 100644 index 0000000000..ddf4e55e08 --- /dev/null +++ b/billing/app/services/importer.rb @@ -0,0 +1,61 @@ +class Importer + attr_reader :read_file, :open_file + + def initialize(file) + @open_file = File.open(file) + @read_file = @open_file&.readlines + end + + def import_and_create_data + return false unless is_valid_extension?(open_file) + + read_file.each do |line| + data = convert_line_to_hash(line) + provider = find_or_create_provider(data['provider']) + customer = find_or_create_customer(data['customer']) + data_transaction = data['transaction'].merge({ customer_id: customer.reload.id, provider_id: provider.reload.id }) + + Transaction.create(data_transaction) + end + + true + end + + private + + def is_valid_extension?(file) + return true if File.extname(file).match(/txt|csv/) + false + end + + def find_or_create_provider(provider) + object = Provider.where(name_provider: provider[:name_provider]) + + return object if object.present? + Provider.create!(provider) + end + + def find_or_create_customer(customer) + object = Customer.where(cpf: customer[:cpf]) + + return object if object.present? + Customer.create!(customer) + end + + def convert_line_to_hash(line) + type = line[0, 1].strip + date = Date.parse(line[1, 8].strip).strftime("%d/%m/%Y") + value = (line[9, 10].strip.to_f) / 100 + cpf = line[19, 11].strip + card = line[30, 12].strip + hour = line[42, 6].strip.scan(/[0-9]{2}/).join(':') + name_owner = line[48, 14].strip + name_provider = line[62, 19].strip + + { + 'transaction' => { type_transaction: type.to_i, date_transaction: date, value: value, hour: hour, number_card: card }, + 'customer' => { cpf: cpf }, + 'provider' => { name_owner: name_owner, name_provider: name_provider} + } + end +end \ No newline at end of file diff --git a/billing/app/views/layouts/application.html.erb b/billing/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..7025e20c69 --- /dev/null +++ b/billing/app/views/layouts/application.html.erb @@ -0,0 +1,15 @@ + + + + Billing + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + + + + <%= yield %> + + diff --git a/billing/app/views/layouts/mailer.html.erb b/billing/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000000..cbd34d2e9d --- /dev/null +++ b/billing/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/billing/app/views/layouts/mailer.text.erb b/billing/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000000..37f0bddbd7 --- /dev/null +++ b/billing/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/billing/bin/rails b/billing/bin/rails new file mode 100755 index 0000000000..efc0377492 --- /dev/null +++ b/billing/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/billing/bin/rake b/billing/bin/rake new file mode 100755 index 0000000000..4fbf10b960 --- /dev/null +++ b/billing/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/billing/bin/setup b/billing/bin/setup new file mode 100755 index 0000000000..ec47b79b3b --- /dev/null +++ b/billing/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require "fileutils" + +# path to your application root. +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + puts "\n== Restarting application server ==" + system! "bin/rails restart" +end diff --git a/billing/config.ru b/billing/config.ru new file mode 100644 index 0000000000..4a3c09a688 --- /dev/null +++ b/billing/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/billing/config/application.rb b/billing/config/application.rb new file mode 100644 index 0000000000..409ce6c9da --- /dev/null +++ b/billing/config/application.rb @@ -0,0 +1,22 @@ +require_relative "boot" + +require "rails/all" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Billing + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 7.0 + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + end +end diff --git a/billing/config/boot.rb b/billing/config/boot.rb new file mode 100644 index 0000000000..988a5ddc46 --- /dev/null +++ b/billing/config/boot.rb @@ -0,0 +1,4 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/billing/config/cable.yml b/billing/config/cable.yml new file mode 100644 index 0000000000..b48aee3b3c --- /dev/null +++ b/billing/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: billing_production diff --git a/billing/config/credentials.yml.enc b/billing/config/credentials.yml.enc new file mode 100644 index 0000000000..b2537169dd --- /dev/null +++ b/billing/config/credentials.yml.enc @@ -0,0 +1 @@ +NncYRlzhay4q8xDhIUA21ReCvawELEsbyV8B4RSO86c70lx9yM9iejD8GOd1xPZe8raHoZRszxUNZ2uD3DwGYXq3ZFIJ4EKf6sGA9a93HQaAhIloneoZtgMA+yBhgeLhCdYKs+e/4xItqU9RHYEBVA5wDYq3SIPmW+HqTDAT3KEI6Wlryrnmw+3bkQHhaiYNxJd64FoRKGqFfLd6iIEWekYcwDBedCZ+yShyDuXX5AS467e9OUym5GjNGBTXnGTVmLq7xrxlln4OWCpiMl2PjtPCFiKMKZPK9YVwktzG+foqk1RH9u2uNm4GbH2ex/FWAjbHe4QDm2skFY5X+rMqxT0aL/1NLiY51+D1h+Tztp8WtANkO7kRnnI8kqML/BwMYS6N9OR8VRAdZZKeHU3weje+ncWMDTPvC7rM--WheY72HjdgGrNYNG--5Ujd5hwwlFdEMqTAtwrsXA== \ No newline at end of file diff --git a/billing/config/database.yml b/billing/config/database.yml new file mode 100644 index 0000000000..6eaabe88d5 --- /dev/null +++ b/billing/config/database.yml @@ -0,0 +1,21 @@ +default: &default + adapter: postgresql + encoding: unicode + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + host: db + user: postgres + password: <%= ENV['DB_PASSWORD'] %> + +development: + <<: *default + database: billing_development + +test: + <<: *default + database: billing_test + +production: + <<: *default + database: billing_production + username: billing + password: <%= ENV["BILLING_DATABASE_PASSWORD"] %> diff --git a/billing/config/environment.rb b/billing/config/environment.rb new file mode 100644 index 0000000000..cac5315775 --- /dev/null +++ b/billing/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/billing/config/environments/development.rb b/billing/config/environments/development.rb new file mode 100644 index 0000000000..8500f459a8 --- /dev/null +++ b/billing/config/environments/development.rb @@ -0,0 +1,70 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing + config.server_timing = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true +end diff --git a/billing/config/environments/production.rb b/billing/config/environments/production.rb new file mode 100644 index 0000000000..cbfb75c8d3 --- /dev/null +++ b/billing/config/environments/production.rb @@ -0,0 +1,93 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + + # Compress CSS using a preprocessor. + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). + config.log_level = :info + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "billing_production" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require "syslog/logger" + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/billing/config/environments/test.rb b/billing/config/environments/test.rb new file mode 100644 index 0000000000..6ea4d1e706 --- /dev/null +++ b/billing/config/environments/test.rb @@ -0,0 +1,60 @@ +require "active_support/core_ext/integer/time" + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Turn false under Spring and add config.action_view.cache_template_loading = true. + config.cache_classes = true + + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + config.eager_load = ENV["CI"].present? + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true +end diff --git a/billing/config/initializers/assets.rb b/billing/config/initializers/assets.rb new file mode 100644 index 0000000000..2eeef966fe --- /dev/null +++ b/billing/config/initializers/assets.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = "1.0" + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/billing/config/initializers/content_security_policy.rb b/billing/config/initializers/content_security_policy.rb new file mode 100644 index 0000000000..3621f97f8e --- /dev/null +++ b/billing/config/initializers/content_security_policy.rb @@ -0,0 +1,26 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap and inline scripts +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src) +# +# # Report CSP violations to a specified URI. See: +# # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# # config.content_security_policy_report_only = true +# end diff --git a/billing/config/initializers/filter_parameter_logging.rb b/billing/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..adc6568ce8 --- /dev/null +++ b/billing/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be filtered from the log file. Use this to limit dissemination of +# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported +# notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/billing/config/initializers/inflections.rb b/billing/config/initializers/inflections.rb new file mode 100644 index 0000000000..3860f659ea --- /dev/null +++ b/billing/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/billing/config/initializers/permissions_policy.rb b/billing/config/initializers/permissions_policy.rb new file mode 100644 index 0000000000..00f64d71b0 --- /dev/null +++ b/billing/config/initializers/permissions_policy.rb @@ -0,0 +1,11 @@ +# Define an application-wide HTTP permissions policy. For further +# information see https://developers.google.com/web/updates/2018/06/feature-policy +# +# Rails.application.config.permissions_policy do |f| +# f.camera :none +# f.gyroscope :none +# f.microphone :none +# f.usb :none +# f.fullscreen :self +# f.payment :self, "https://secure.example.com" +# end diff --git a/billing/config/locales/en.yml b/billing/config/locales/en.yml new file mode 100644 index 0000000000..8ca56fc74f --- /dev/null +++ b/billing/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# "true": "foo" +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/billing/config/puma.rb b/billing/config/puma.rb new file mode 100644 index 0000000000..daaf036999 --- /dev/null +++ b/billing/config/puma.rb @@ -0,0 +1,43 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `worker_timeout` threshold that Puma will use to wait before +# terminating a worker in development environments. +# +worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart diff --git a/billing/config/routes.rb b/billing/config/routes.rb new file mode 100644 index 0000000000..1f8d41a9de --- /dev/null +++ b/billing/config/routes.rb @@ -0,0 +1,7 @@ +Rails.application.routes.draw do + resources :importer, only: [:index] do + collection { post :import_file, via: :options } + end + + resources :transactions, only: [:index] +end diff --git a/billing/config/storage.yml b/billing/config/storage.yml new file mode 100644 index 0000000000..4942ab6694 --- /dev/null +++ b/billing/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/billing/db/migrate/20220504205720_create_customers.rb b/billing/db/migrate/20220504205720_create_customers.rb new file mode 100644 index 0000000000..f6f6993011 --- /dev/null +++ b/billing/db/migrate/20220504205720_create_customers.rb @@ -0,0 +1,9 @@ +class CreateCustomers < ActiveRecord::Migration[7.0] + def change + create_table :customers do |t| + t.string :cpf + + t.timestamps + end + end +end diff --git a/billing/db/migrate/20220504205941_create_providers.rb b/billing/db/migrate/20220504205941_create_providers.rb new file mode 100644 index 0000000000..5b77e32a56 --- /dev/null +++ b/billing/db/migrate/20220504205941_create_providers.rb @@ -0,0 +1,10 @@ +class CreateProviders < ActiveRecord::Migration[7.0] + def change + create_table :providers do |t| + t.string :name_owner + t.string :name_provider + + t.timestamps + end + end +end diff --git a/billing/db/migrate/20220504210141_create_transactions.rb b/billing/db/migrate/20220504210141_create_transactions.rb new file mode 100644 index 0000000000..29f655d70c --- /dev/null +++ b/billing/db/migrate/20220504210141_create_transactions.rb @@ -0,0 +1,20 @@ +class CreateTransactions < ActiveRecord::Migration[7.0] + def change + create_table :transactions do |t| + t.references :customers, foreign_key: true + t.references :providers, foreign_key: true + + t.integer :transaction_type + t.string :nature + t.boolean :signal + t.float :value + t.date :transaction_date + t.string :hour + t.string :card_number + t.bigint :customer_id + t.bigint :provider_id + + t.timestamps + end + end +end diff --git a/billing/db/schema.rb b/billing/db/schema.rb new file mode 100644 index 0000000000..3feabfe13b --- /dev/null +++ b/billing/db/schema.rb @@ -0,0 +1,50 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.0].define(version: 2022_05_04_210141) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "customers", force: :cascade do |t| + t.string "cpf" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "providers", force: :cascade do |t| + t.string "name_owner" + t.string "name_provider" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "transactions", force: :cascade do |t| + t.bigint "customers_id" + t.bigint "providers_id" + t.integer "transaction_type" + t.string "nature" + t.boolean "signal" + t.float "value" + t.date "transaction_date" + t.string "hour" + t.string "card_number" + t.bigint "customer_id" + t.bigint "provider_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["customers_id"], name: "index_transactions_on_customers_id" + t.index ["providers_id"], name: "index_transactions_on_providers_id" + end + + add_foreign_key "transactions", "customers", column: "customers_id" + add_foreign_key "transactions", "providers", column: "providers_id" +end diff --git a/billing/db/seeds.rb b/billing/db/seeds.rb new file mode 100644 index 0000000000..2ecb15835d --- /dev/null +++ b/billing/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) +# Character.create(name: " Luke", movie: movies.first) diff --git a/billing/docker-compose.yml b/billing/docker-compose.yml new file mode 100644 index 0000000000..7451ebd941 --- /dev/null +++ b/billing/docker-compose.yml @@ -0,0 +1,26 @@ +version: "3.8" + +services: + db: + image: "postgres:12.2" + environment: + - POSTGRES_PASSWORD=postgres + volumes: + - postgres:/var/lib/postgresql/data + + app: + build: . + command: bash start.sh + ports: + - "3000:3000" + environment: + - DB_PASSWORD=postgres + volumes: + - .:/billing + - gems:/gems + depends_on: + - db + +volumes: + postgres: + gems: \ No newline at end of file diff --git a/billing/lib/assets/.keep b/billing/lib/assets/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/lib/tasks/.keep b/billing/lib/tasks/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/log/.keep b/billing/log/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/public/404.html b/billing/public/404.html new file mode 100644 index 0000000000..2be3af26fc --- /dev/null +++ b/billing/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/billing/public/422.html b/billing/public/422.html new file mode 100644 index 0000000000..c08eac0d1d --- /dev/null +++ b/billing/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/billing/public/500.html b/billing/public/500.html new file mode 100644 index 0000000000..78a030af22 --- /dev/null +++ b/billing/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/billing/public/apple-touch-icon-precomposed.png b/billing/public/apple-touch-icon-precomposed.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/public/apple-touch-icon.png b/billing/public/apple-touch-icon.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/public/favicon.ico b/billing/public/favicon.ico new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/public/robots.txt b/billing/public/robots.txt new file mode 100644 index 0000000000..c19f78ab68 --- /dev/null +++ b/billing/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/billing/spec/controllers/importers_controller_spec.rb b/billing/spec/controllers/importers_controller_spec.rb new file mode 100644 index 0000000000..49e0d8b2cd --- /dev/null +++ b/billing/spec/controllers/importers_controller_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe 'ImporterController', type: :request do + context 'when try make a post with txt file and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'file_example.txt') } + let!(:file) { Rack::Test::UploadedFile.new(path) } + + it 'return successful' do + post '/importer/import_file', params: { file: file } + json_response = JSON.parse(@response.body) + + expect(@response.code).to eq('200') + expect(json_response).to eq({ + 'success' => true, + 'message' => 'Upload and creation data make with successful!' + }) + end + end + + context 'when try make a post with another extension file and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'rails.png') } + let!(:file) { Rack::Test::UploadedFile.new(path) } + + it 'return fails' do + post '/importer/import_file', params: { file: file } + json_response = JSON.parse(@response.body) + + expect(json_response).to eq({ + 'success' => false, + 'message' => 'Something is wrong!' + }) + end + end +end \ No newline at end of file diff --git a/billing/spec/controllers/transactions_controller_spec.rb b/billing/spec/controllers/transactions_controller_spec.rb new file mode 100644 index 0000000000..bd7e99e309 --- /dev/null +++ b/billing/spec/controllers/transactions_controller_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +RSpec.describe 'TransactionsController', type: :request do + context 'when make request GET and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'file_example.txt') } + let(:data) do + [ + { "provider_name"=>"Bar Do João", "provider_owner"=>"João Macedo", "total_balance"=>"R$406.0" }, + { "provider_name"=>"Loja Do Ó - Matriz", "provider_owner"=>"Maria Josefina", "total_balance"=>"R$434.0" }, + { "provider_name"=>"Mercado Da Avenida", "provider_owner"=>"Marcos Pereira", "total_balance"=>"R$2335.2" }, + { "provider_name"=>"Mercearia 3 Irmãos", "provider_owner"=>"José Costa", "total_balance"=>"R$7023.0" }, + { "provider_name"=>"Loja Do Ó - Filial", "provider_owner"=>"Maria Josefina", "total_balance"=>"R$152.32" } + ] + end + + before do + Importer.new(path).import_and_create_data + end + + it 'return successful with array with transactions' do + get '/transactions' + json_response = JSON.parse(@response.body) + + expect(@response.code).to eq('200') + expect(json_response).to eq({ + 'success' => true, + 'transactions' => data + }) + end + end + + context 'when make request GET and havent anyone register and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'rails.png') } + let!(:file) { Rack::Test::UploadedFile.new(path) } + + it 'return successful with empty array' do + get '/transactions' + json_response = JSON.parse(@response.body) + + expect(json_response).to eq({ + 'success' => true, + 'transactions' => [] + }) + end + end +end diff --git a/billing/spec/factories/customers.rb b/billing/spec/factories/customers.rb new file mode 100644 index 0000000000..b0ae4b0228 --- /dev/null +++ b/billing/spec/factories/customers.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + factory :customer do + cpf { Faker::CPF.numeric.to_s } + + trait :invalid do + cpf { '123456' } + end + end +end diff --git a/billing/spec/factories/providers.rb b/billing/spec/factories/providers.rb new file mode 100644 index 0000000000..36867167fc --- /dev/null +++ b/billing/spec/factories/providers.rb @@ -0,0 +1,10 @@ +FactoryBot.define do + factory :provider do + name_owner { Faker::Name.name } + name_provider { Faker::Name.first_name } + + trait :invalid do + name_provider { nil } + end + end +end diff --git a/billing/spec/factories/transactions.rb b/billing/spec/factories/transactions.rb new file mode 100644 index 0000000000..070a572c10 --- /dev/null +++ b/billing/spec/factories/transactions.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + factory :transaction do + transaction_type { 'credit' } + value { 249.0 } + transaction_date { '2022-05-03' } + hour { '17:00:51' } + card_number { '9876****1234' } + end +end diff --git a/billing/spec/fixtures/files/file_example.txt b/billing/spec/fixtures/files/file_example.txt new file mode 100644 index 0000000000..0a81268be2 --- /dev/null +++ b/billing/spec/fixtures/files/file_example.txt @@ -0,0 +1,21 @@ +3201903010000014200096206760174753****3153153453JOÃO MACEDO BAR DO JOÃO +5201903010000013200556418150633123****7687145607MARIA JOSEFINALOJA DO Ó - MATRIZ +3201903010000012200845152540736777****1313172712MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000011200096206760173648****0099234234JOÃO MACEDO BAR DO JOÃO +1201903010000015200096206760171234****7890233000JOÃO MACEDO BAR DO JOÃO +2201903010000010700845152540738723****9987123333MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000050200845152540738473****1231231233MARCOS PEREIRAMERCADO DA AVENIDA +3201903010000060200232702980566777****1313172712JOSÉ COSTA MERCEARIA 3 IRMÃOS +1201903010000020000556418150631234****3324090002MARIA JOSEFINALOJA DO Ó - MATRIZ +5201903010000080200845152540733123****7687145607MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000010200232702980568473****1231231233JOSÉ COSTA MERCEARIA 3 IRMÃOS +3201903010000610200232702980566777****1313172712JOSÉ COSTA MERCEARIA 3 IRMÃOS +4201903010000015232556418150631234****6678100000MARIA JOSEFINALOJA DO Ó - FILIAL +8201903010000010203845152540732344****1222123222MARCOS PEREIRAMERCADO DA AVENIDA +3201903010000010300232702980566777****1313172712JOSÉ COSTA MERCEARIA 3 IRMÃOS +9201903010000010200556418150636228****9090000000MARIA JOSEFINALOJA DO Ó - MATRIZ +4201906010000050617845152540731234****2231100000MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000010900232702980568723****9987123333JOSÉ COSTA MERCEARIA 3 IRMÃOS +8201903010000000200845152540732344****1222123222MARCOS PEREIRAMERCADO DA AVENIDA +2201903010000000500232702980567677****8778141808JOSÉ COSTA MERCEARIA 3 IRMÃOS +3201903010000019200845152540736777****1313172712MARCOS PEREIRAMERCADO DA AVENIDA \ No newline at end of file diff --git a/billing/spec/fixtures/files/rails.png b/billing/spec/fixtures/files/rails.png new file mode 100644 index 0000000000..9e5b7f139a Binary files /dev/null and b/billing/spec/fixtures/files/rails.png differ diff --git a/billing/spec/models/customer_spec.rb b/billing/spec/models/customer_spec.rb new file mode 100644 index 0000000000..1dea6abc26 --- /dev/null +++ b/billing/spec/models/customer_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +RSpec.describe Customer, type: :model do + context 'when create a new Customer with valid CPF' do + subject(:customer) { build :customer } + + describe 'validation' do + it { should be_valid } + end + end + + context 'when create a new Customer with invalid CPF' do + subject(:customer) { build :customer , :invalid } + describe 'validation' do + it { should_not be_valid } + end + end + + context 'when try create a Customer but it already exists and' do + let(:cpf) { Faker::CPF.numeric.to_s } + subject(:customer) { create :customer, cpf: cpf } + subject(:customer2) { build :customer, cpf: cpf } + + it 'fails' do + expect(customer).to be_valid + expect(customer2.save).to eq(false) + expect { customer2.save! }.to raise_error + end + end + + context 'when try update a Customer with a invalid CPF and' do + subject(:customer) { create :customer } + + it 'fails' do + expect(customer.update(cpf: '123456789')).to eq(false) + expect { customer.update!(cpf: '123456789') }.to raise_error + end + end +end diff --git a/billing/spec/models/provider_spec.rb b/billing/spec/models/provider_spec.rb new file mode 100644 index 0000000000..62d44a2052 --- /dev/null +++ b/billing/spec/models/provider_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe Provider, type: :model do + context 'when create a new Provider with valid name provider and' do + it 'create with successful' do + expect(Provider.create(name_provider: 'Teste')).to be_valid + end + end + + context 'when try create a Provider but it already exists and' do + let(:cpf) { Faker::CPF.numeric.to_s } + let(:provider) { Provider.create(name_provider: 'Teste') } + let(:provider2) { Provider.create(name_provider: 'Teste') } + + it 'fails' do + expect(provider).to be_valid + expect(provider2.save).to eq(false) + expect { provider2.save! }.to raise_error + end + end +end diff --git a/billing/spec/models/transaction_spec.rb b/billing/spec/models/transaction_spec.rb new file mode 100644 index 0000000000..855b7613d2 --- /dev/null +++ b/billing/spec/models/transaction_spec.rb @@ -0,0 +1,68 @@ +require 'rails_helper' + +RSpec.describe Transaction, type: :model do + + let!(:customer) {Customer.create(cpf: Faker::CPF.numeric.to_s) } + let!(:provider) { Provider.create(name_provider: 'Teste') } + + context 'when create a new Transaction with valid data and' do + let(:transaction) do + Transaction.create( + provider_id: provider.id, + customer_id: customer.id, + transaction_type: 'credit', + value: 192.0, + transaction_date: '2022-03-01', + hour: '17:27:12', + card_number: '6777****1313' + ) + end + + it 'create with successful' do + expect(transaction).to be_valid + expect(transaction.provider_id).to eq(provider.id) + expect(transaction.customer_id).to eq(customer.id) + expect(transaction.transaction_type).to eq('credit') + expect(transaction.value).to eq(192.0) + expect(transaction.transaction_date.class).to eq(Date) + expect(transaction.hour).to eq('17:27:12') + expect(transaction.card_number).to eq('6777****1313') + end + end + + context 'when try create a Transaction without Provider and' do + let(:transaction) do + Transaction.create( + customer_id: customer.id, + transaction_type: 'credit', + value: 192.0, + transaction_date: '2022-03-01', + hour: '17:27:12', + card_number: '6777****1313' + ) + end + + it 'fails' do + expect(transaction).to be_invalid + expect { transaction.save! }.to raise_error(StandardError) + end + end + + context 'when try create a Transaction without Customer' do + let(:transaction) do + Transaction.create( + provider_id: provider.id, + transaction_type: :credit, + value: 192.0, + transaction_date: '2022-03-01', + hour: '17:27:12', + card_number: '6777****1313' + ) + end + + it 'when exist fails in transaction' do + expect(transaction).to be_invalid + expect { transaction.save! }.to raise_error(StandardError) + end + end +end diff --git a/billing/spec/rails_helper.rb b/billing/spec/rails_helper.rb new file mode 100644 index 0000000000..c07db81449 --- /dev/null +++ b/billing/spec/rails_helper.rb @@ -0,0 +1,27 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../config/environment', __dir__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' + +Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } + + +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + config.use_transactional_fixtures = true + + config.infer_spec_type_from_file_location! + + config.filter_rails_from_backtrace! + +end diff --git a/billing/spec/services/importer_spec.rb b/billing/spec/services/importer_spec.rb new file mode 100644 index 0000000000..2e96e578ac --- /dev/null +++ b/billing/spec/services/importer_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe Importer do + context 'when call the service with file txt and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'file_example.txt') } + let(:importer) { Importer.new(path) } + + it 'return successful' do + expect(importer.import_and_create_data).to eq(true) + expect(Customer.last).to be_present + expect(Provider.last).to be_present + expect(Transaction.last).to be_present + end + end + + context 'when call the service with another extension file and' do + let!(:path) { Rails.root.join('spec', 'fixtures', 'files', 'rails.png') } + let(:importer) { Importer.new(path) } + + it 'return fails' do + expect(importer.import_and_create_data).to eq(false) + expect(Customer.last).to be(nil) + expect(Provider.last).to be(nil) + expect(Transaction.last).to be(nil) + end + end +end \ No newline at end of file diff --git a/billing/spec/spec_helper.rb b/billing/spec/spec_helper.rb new file mode 100644 index 0000000000..a0d4080592 --- /dev/null +++ b/billing/spec/spec_helper.rb @@ -0,0 +1,94 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/billing/spec/support/factory_bot.rb b/billing/spec/support/factory_bot.rb new file mode 100644 index 0000000000..329748fc9d --- /dev/null +++ b/billing/spec/support/factory_bot.rb @@ -0,0 +1,3 @@ +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods +end \ No newline at end of file diff --git a/billing/spec/support/shoulda_matchers.rb b/billing/spec/support/shoulda_matchers.rb new file mode 100644 index 0000000000..1c55e783af --- /dev/null +++ b/billing/spec/support/shoulda_matchers.rb @@ -0,0 +1,6 @@ +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end \ No newline at end of file diff --git a/billing/start.sh b/billing/start.sh new file mode 100644 index 0000000000..53952ba72c --- /dev/null +++ b/billing/start.sh @@ -0,0 +1,5 @@ +# Instala as Gems +bundle check || bundle install + +# Roda nosso servidor +bundle exec puma -C config/puma.rb \ No newline at end of file diff --git a/billing/storage/.keep b/billing/storage/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/tmp/.keep b/billing/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/tmp/pids/.keep b/billing/tmp/pids/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/tmp/storage/.keep b/billing/tmp/storage/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/billing/vendor/.keep b/billing/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2