1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

update rails to 5.1.7

This commit is contained in:
Du Peng 2020-03-13 17:10:38 +01:00 committed by Sylvain
parent 9ca9425ef4
commit b3313d3e75
37 changed files with 374 additions and 335 deletions

View File

@ -4,7 +4,7 @@ source 'https://rubygems.org'
gem 'compass-rails', '3.0.2' gem 'compass-rails', '3.0.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.7.2' gem 'rails', '~> 5.1.7'
# Use Puma as web server # Use Puma as web server
gem 'puma', '3.12.4' gem 'puma', '3.12.4'
# Use SCSS for stylesheets # Use SCSS for stylesheets
@ -30,6 +30,7 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console
# comment over to use visual debugger (eg. RubyMine), uncomment to use manual debugging # comment over to use visual debugger (eg. RubyMine), uncomment to use manual debugging
# gem 'byebug' # gem 'byebug'
gem 'dotenv-rails'
end end
group :development do group :development do
@ -54,7 +55,6 @@ end
group :test do group :test do
gem 'database_cleaner' gem 'database_cleaner'
gem 'dotenv-rails'
gem 'faker' gem 'faker'
gem 'minitest-reporters' gem 'minitest-reporters'
gem 'pdf-reader' gem 'pdf-reader'

View File

@ -4,42 +4,42 @@ GEM
Ascii85 (1.0.3) Ascii85 (1.0.3)
aasm (5.0.8) aasm (5.0.8)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
actioncable (5.0.7.2) actioncable (5.1.7)
actionpack (= 5.0.7.2) actionpack (= 5.1.7)
nio4r (>= 1.2, < 3.0) nio4r (~> 2.0)
websocket-driver (~> 0.6.1) websocket-driver (~> 0.6.1)
actionmailer (5.0.7.2) actionmailer (5.1.7)
actionpack (= 5.0.7.2) actionpack (= 5.1.7)
actionview (= 5.0.7.2) actionview (= 5.1.7)
activejob (= 5.0.7.2) activejob (= 5.1.7)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (5.0.7.2) actionpack (5.1.7)
actionview (= 5.0.7.2) actionview (= 5.1.7)
activesupport (= 5.0.7.2) activesupport (= 5.1.7)
rack (~> 2.0) rack (~> 2.0)
rack-test (~> 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionpack-page_caching (1.1.0) actionpack-page_caching (1.1.0)
actionpack (>= 4.0.0, < 6) actionpack (>= 4.0.0, < 6)
actionview (5.0.7.2) actionview (5.1.7)
activesupport (= 5.0.7.2) activesupport (= 5.1.7)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_record_query_trace (1.7) active_record_query_trace (1.7)
activejob (5.0.7.2) activejob (5.1.7)
activesupport (= 5.0.7.2) activesupport (= 5.1.7)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.0.7.2) activemodel (5.1.7)
activesupport (= 5.0.7.2) activesupport (= 5.1.7)
activerecord (5.0.7.2) activerecord (5.1.7)
activemodel (= 5.0.7.2) activemodel (= 5.1.7)
activesupport (= 5.0.7.2) activesupport (= 5.1.7)
arel (~> 7.0) arel (~> 8.0)
activesupport (5.0.7.2) activesupport (5.1.7)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
@ -51,7 +51,7 @@ GEM
api-pagination (4.8.2) api-pagination (4.8.2)
apipie-rails (0.5.17) apipie-rails (0.5.17)
rails (>= 4.1) rails (>= 4.1)
arel (7.1.4) arel (8.0.0)
ast (2.4.0) ast (2.4.0)
autoprefixer-rails (9.7.4) autoprefixer-rails (9.7.4)
execjs execjs
@ -147,7 +147,7 @@ GEM
faraday faraday
multi_json multi_json
equalizer (0.0.11) equalizer (0.0.11)
erubis (2.7.0) erubi (1.9.0)
et-orbi (1.2.1) et-orbi (1.2.1)
tzinfo tzinfo
execjs (2.7.0) execjs (2.7.0)
@ -286,20 +286,20 @@ GEM
rack (2.2.2) rack (2.2.2)
rack-protection (2.0.8.1) rack-protection (2.0.8.1)
rack rack
rack-test (0.6.3) rack-test (1.1.0)
rack (>= 1.0) rack (>= 1.0, < 3)
railroady (1.5.3) railroady (1.5.3)
rails (5.0.7.2) rails (5.1.7)
actioncable (= 5.0.7.2) actioncable (= 5.1.7)
actionmailer (= 5.0.7.2) actionmailer (= 5.1.7)
actionpack (= 5.0.7.2) actionpack (= 5.1.7)
actionview (= 5.0.7.2) actionview (= 5.1.7)
activejob (= 5.0.7.2) activejob (= 5.1.7)
activemodel (= 5.0.7.2) activemodel (= 5.1.7)
activerecord (= 5.0.7.2) activerecord (= 5.1.7)
activesupport (= 5.0.7.2) activesupport (= 5.1.7)
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.0.7.2) railties (= 5.1.7)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
@ -313,9 +313,9 @@ GEM
rails_stdout_logging rails_stdout_logging
rails_serve_static_assets (0.0.5) rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5) rails_stdout_logging (0.0.5)
railties (5.0.7.2) railties (5.1.7)
actionpack (= 5.0.7.2) actionpack (= 5.1.7)
activesupport (= 5.0.7.2) activesupport (= 5.1.7)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
@ -493,7 +493,7 @@ DEPENDENCIES
puma (= 3.12.4) puma (= 3.12.4)
pundit pundit
railroady railroady
rails (~> 5.0.7.2) rails (~> 5.1.7)
rails-observers rails-observers
rails_12factor rails_12factor
rb-readline rb-readline

View File

@ -1,3 +1,3 @@
web: bundle exec rails server puma -p $PORT -b0.0.0.0 web: bundle exec rails server puma -p $PORT
worker: bundle exec sidekiq -C ./config/sidekiq.yml worker: bundle exec sidekiq -C ./config/sidekiq.yml
mail: mailcatcher --foreground --http-ip=0.0.0.0 mail: mailcatcher --foreground --http-ip=0.0.0.0

View File

@ -11,7 +11,7 @@ class EventService
start_at: range[:start_at], start_at: range[:start_at],
end_at: range[:end_at], end_at: range[:end_at],
available_type: 'event' }) available_type: 'event' })
.except!(:start_date, :end_date, :start_time, :end_time, :all_day) .extract!(:start_date, :end_date, :start_time, :end_time, :all_day)
# convert main price to centimes # convert main price to centimes
params[:amount] = (params[:amount].to_f * 100 if params[:amount].present?) params[:amount] = (params[:amount].to_f * 100 if params[:amount].present?)
# delete non-complete "other" prices and convert them to centimes # delete non-complete "other" prices and convert them to centimes

View File

@ -2,7 +2,6 @@
# Provides helper methods for User actions # Provides helper methods for User actions
class Members::MembersService class Members::MembersService
attr_accessor :member attr_accessor :member
def initialize(member) def initialize(member)
@ -10,10 +9,9 @@ class Members::MembersService
end end
def update(params) def update(params)
if params[:group_id] && @member.group_id != params[:group_id].to_i && !@member.subscribed_plan.nil? if params[:group_id] && @member.group_id != params[:group_id].to_i && !@member.subscribed_plan.nil?
# here a group change is requested but unprocessable, handle the exception # here a group change is requested but unprocessable, handle the exception
@member.errors[:group_id] = I18n.t('members.unable_to_change_the_group_while_a_subscription_is_running') @member.errors.add(:group_id, I18n.t('members.unable_to_change_the_group_while_a_subscription_is_running'))
return false return false
end end
@ -80,5 +78,4 @@ class Members::MembersService
params[:password] params[:password]
end end
end end
end end

View File

@ -18,6 +18,10 @@ chdir APP_ROOT do
system! 'gem install bundler --conservative' system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install') system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
# puts "\n== Copying sample files ==" # puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml') # unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml' # cp 'config/database.yml.sample', 'config/database.yml'

11
bin/yarn Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env ruby
VENDOR_PATH = File.expand_path('..', __dir__)
Dir.chdir(VENDOR_PATH) do
begin
exec "yarnpkg #{ARGV.join(" ")}"
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end

View File

@ -14,6 +14,10 @@ Bundler.require(*Rails.groups)
module Fablab module Fablab
class Application < Rails::Application class Application < Rails::Application
require 'fab_manager' require 'fab_manager'
# Initialize configuration defaults for originally generated Rails version.
# config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
@ -30,20 +34,10 @@ module Fablab
config.i18n.default_locale = Rails.application.secrets.rails_locale config.i18n.default_locale = Rails.application.secrets.rails_locale
config.i18n.fallbacks = [Rails.application.secrets.app_locale, :en] config.i18n.fallbacks = [Rails.application.secrets.app_locale, :en]
config.assets.paths << Rails.root.join('node_modules').to_s
config.to_prepare do config.to_prepare do
Devise::Mailer.layout 'notifications_mailer' Devise::Mailer.layout 'notifications_mailer'
end end
# allow use rails helpers in angular templates
Rails.application.config.assets.configure do |env|
env.context_class.class_eval do
include ActionView::Helpers
include Rails.application.routes.url_helpers
end
end
config.active_job.queue_adapter = :sidekiq config.active_job.queue_adapter = :sidekiq
config.generators do |g| config.generators do |g|

View File

@ -7,3 +7,4 @@ test:
production: production:
adapter: redis adapter: redis
url: redis://localhost:6379/1 url: redis://localhost:6379/1
channel_prefix: fablab_production

View File

@ -20,7 +20,7 @@ Rails.application.configure do
config.cache_store = :memory_store config.cache_store = :memory_store
config.public_file_server.headers = { config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800' 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
} }
else else
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
@ -74,7 +74,7 @@ Rails.application.configure do
# Use an evented file watcher to asynchronously detect changes in source code, # Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem. # routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.log_level = Rails.application.secrets.log_level || :debug config.log_level = Rails.application.secrets.log_level || :debug
end end

View File

@ -17,7 +17,7 @@ Rails.application.configure do
# Configure public file server for tests with Cache-Control for performance. # Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true config.public_file_server.enabled = true
config.public_file_server.headers = { config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=3600' 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
} }
# Show full error reports and disable caching. # Show full error reports and disable caching.

View File

@ -1,14 +1,27 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # 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. # Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0' Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path # allow use rails helpers in angular templates
Rails.application.config.assets.configure do |env|
env.context_class.class_eval do
include ActionView::Helpers
include Rails.application.routes.url_helpers
end
end
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path # Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # application.js, application.css, and all non-JS/CSS in the app/assets
# Rails.application.config.assets.precompile += %w( search.js ) # folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile += %w[ Rails.application.config.assets.precompile += %w[
fontawesome-webfont.eot fontawesome-webfont.eot

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# #
# This file contains migration options to ease your Rails 5.0 upgrade. # This file contains migration options to ease your Rails 5.0 upgrade.
@ -6,6 +8,7 @@
# #
# Read the Guide for Upgrading Ruby on Rails for more info on each option. # Read the Guide for Upgrading Ruby on Rails for more info on each option.
# DEPRECATION WARNING: raise_on_unfiltered_parameters is deprecated and has no effect in Rails 5.1.
Rails.application.config.action_controller.raise_on_unfiltered_parameters = true Rails.application.config.action_controller.raise_on_unfiltered_parameters = true
# Enable per-form CSRF tokens. Previous versions had false. # Enable per-form CSRF tokens. Previous versions had false.
@ -21,5 +24,6 @@ ActiveSupport.to_time_preserves_timezone = false
# Require `belongs_to` associations by default. Previous versions had false. # Require `belongs_to` associations by default. Previous versions had false.
Rails.application.config.active_record.belongs_to_required_by_default = false Rails.application.config.active_record.belongs_to_required_by_default = false
# DEPRECATION WARNING: ActiveSupport.halt_callback_chains_on_return_false= is deprecated and will be removed in Rails 5.2.
# Do not halt callback chains when a callback returns false. Previous versions had true. # Do not halt callback chains when a callback returns false. Previous versions had true.
ActiveSupport.halt_callback_chains_on_return_false = true ActiveSupport.halt_callback_chains_on_return_false = true

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 5.1 upgrade.
#
# Once upgraded flip defaults one by one to migrate to the new default.
#
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
# Make `form_with` generate non-remote forms.
Rails.application.config.action_view.form_with_generates_remote_forms = false
# Unknown asset fallback will return the path passed in when the given
# asset is not present in the asset pipeline.
# Rails.application.config.assets.unknown_asset_fallback = false
# ActiveSupport::Deprecation.silenced = true

View File

@ -1,13 +1,13 @@
# Puma can serve each request in a thread from an internal thread pool. # Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum. # The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match # 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 # 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. # and maximum; this matches the default thread size of Active Record.
# #
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests, default is 3000. # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
# #
port ENV.fetch("PORT") { 3000 } port ENV.fetch("PORT") { 3000 }
@ -32,16 +32,25 @@ environment ENV.fetch("RAILS_ENV") { "development" }
# #
# preload_app! # preload_app!
# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
# are forked to prevent connection leakage.
#
# before_fork do
# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
# end
# The code in the `on_worker_boot` will be called if you are using # The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker # clustered mode by specifying a number of `workers`. After each worker
# process is booted this block will be run, if you are using `preload_app!` # process is booted, this block will be run. If you are using the `preload_app!`
# option you will want to use this block to reconnect to any threads # option, you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby # or connections that may have been created at application boot, as Ruby
# cannot share connections between processes. # cannot share connections between processes.
# #
# on_worker_boot do # on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end # end
#
# Allow puma to be restarted by `rails restart` command. # Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart plugin :tmp_restart

View File

@ -1,5 +1,6 @@
class AbusesTest < ActionDispatch::IntegrationTest # frozen_string_literal: true
class AbusesTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used # Called before every test method runs. Can be used
# to set up fixture information. # to set up fixture information.
def setup def setup
@ -18,21 +19,21 @@ class AbusesTest < ActionDispatch::IntegrationTest
project = Project.take project = Project.take
post '/api/abuses', post '/api/abuses',
{ params: {
abuse: { abuse: {
signaled_type: 'Project', signaled_type: 'Project',
signaled_id: project.id, signaled_id: project.id,
first_name: 'William', first_name: 'William',
last_name: 'Prindle', last_name: 'Prindle',
email: 'wprindle@iastate.edu', email: 'wprindle@iastate.edu',
message: 'This project is in infringement with the patent US5014921 A.' message: 'This project is in infringement with the patent US5014921 A.'
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct object was signaled # Check the correct object was signaled
abuse = json_response(response.body) abuse = json_response(response.body)
@ -42,7 +43,7 @@ class AbusesTest < ActionDispatch::IntegrationTest
# Check notifications were sent for every admins # Check notifications were sent for every admins
notifications = Notification.where(notification_type_id: NotificationType.find_by_name('notify_admin_abuse_reported'), attached_object_type: 'Abuse', attached_object_id: abuse[:reporting][:id]) notifications = Notification.where(notification_type_id: NotificationType.find_by_name('notify_admin_abuse_reported'), attached_object_type: 'Abuse', attached_object_id: abuse[:reporting][:id])
assert_not_empty notifications, 'no notifications were created' assert_not_empty notifications, 'no notifications were created'
notified_users_ids = notifications.map {|n| n.receiver_id } notified_users_ids = notifications.map(&:receiver_id)
User.admins.each do |adm| User.admins.each do |adm|
assert_includes notified_users_ids, adm.id, "Admin #{adm.id} was not notified" assert_includes notified_users_ids, adm.id, "Admin #{adm.id} was not notified"
end end
@ -53,20 +54,19 @@ class AbusesTest < ActionDispatch::IntegrationTest
project = Project.first project = Project.first
post '/api/abuses', post '/api/abuses',
{ params: {
abuse: { abuse: {
signaled_type: 'Project', signaled_type: 'Project',
signaled_id: project.id, signaled_id: project.id,
first_name: 'John', first_name: 'John',
last_name: 'Wrong', last_name: 'Wrong',
email: '', email: '',
message: '' message: ''
} }
}.to_json, }.to_json,
default_headers headers: default_headers
assert_equal 422, response.status, response.body assert_equal 422, response.status, response.body
assert_match /can't be blank/, response.body assert_match /can't be blank/, response.body
end end
end end

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
class AccountingPeriodTest < ActionDispatch::IntegrationTest class AccountingPeriodTest < ActionDispatch::IntegrationTest
def setup def setup
@admin = User.find_by(username: 'admin') @admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user) login_as(@admin, scope: :user)
@ -12,16 +11,16 @@ class AccountingPeriodTest < ActionDispatch::IntegrationTest
end_at = '2012-12-31T00:00:00.000Z' end_at = '2012-12-31T00:00:00.000Z'
post '/api/accounting_periods', post '/api/accounting_periods',
{ params: {
accounting_period: { accounting_period: {
start_at: start_at, start_at: start_at,
end_at: end_at end_at: end_at
} }
}.to_json, default_headers }.to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct period was closed successfully # Check the correct period was closed successfully
period = json_response(response.body) period = json_response(response.body)
@ -39,16 +38,16 @@ class AccountingPeriodTest < ActionDispatch::IntegrationTest
diff = (end_at.to_date - start_at.to_date).to_i diff = (end_at.to_date - start_at.to_date).to_i
post '/api/accounting_periods', post '/api/accounting_periods',
{ params: {
accounting_period: { accounting_period: {
start_at: start_at, start_at: start_at,
end_at: end_at end_at: end_at
} }
}.to_json, default_headers }.to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 422, response.status, response.body assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# check the error # check the error
assert_match(/#{I18n.t('errors.messages.invalid_duration', DAYS: diff)}/, response.body) assert_match(/#{I18n.t('errors.messages.invalid_duration', DAYS: diff)}/, response.body)
@ -59,16 +58,16 @@ class AccountingPeriodTest < ActionDispatch::IntegrationTest
end_at = '2015-02-27T00:00:00.000Z' end_at = '2015-02-27T00:00:00.000Z'
post '/api/accounting_periods', post '/api/accounting_periods',
{ params: {
accounting_period: { accounting_period: {
start_at: start_at, start_at: start_at,
end_at: end_at end_at: end_at
} }
}.to_json, default_headers }.to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 422, response.status, response.body assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# check the error # check the error
assert_match(/#{I18n.t('errors.messages.cannot_overlap')}/, response.body) assert_match(/#{I18n.t('errors.messages.cannot_overlap')}/, response.body)
@ -79,16 +78,16 @@ class AccountingPeriodTest < ActionDispatch::IntegrationTest
end_at = Date.today.end_of_day.iso8601 end_at = Date.today.end_of_day.iso8601
post '/api/accounting_periods', post '/api/accounting_periods',
{ params: {
accounting_period: { accounting_period: {
start_at: start_at, start_at: start_at,
end_at: end_at end_at: end_at
} }
}.to_json, default_headers }.to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 422, response.status, response.body assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# check the error # check the error
assert_match(/#{I18n.t('errors.messages.must_be_in_the_past')}/, response.body) assert_match(/#{I18n.t('errors.messages.must_be_in_the_past')}/, response.body)

View File

@ -1,5 +1,6 @@
class AdminsTest < ActionDispatch::IntegrationTest # frozen_string_literal: true
class AdminsTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used # Called before every test method runs. Can be used
# to set up fixture information. # to set up fixture information.
def setup def setup
@ -16,7 +17,7 @@ class AdminsTest < ActionDispatch::IntegrationTest
test 'create an admin' do test 'create an admin' do
post '/api/admins', post '/api/admins',
{ params: {
admin: { admin: {
username: 'glepower', username: 'glepower',
email: 'gerard.lepower@admins.net', email: 'gerard.lepower@admins.net',
@ -36,11 +37,11 @@ class AdminsTest < ActionDispatch::IntegrationTest
} }
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct admin was created # Check the correct admin was created
admin = json_response(response.body) admin = json_response(response.body)
@ -54,10 +55,9 @@ class AdminsTest < ActionDispatch::IntegrationTest
test 'list all admins' do test 'list all admins' do
get '/api/admins' get '/api/admins'
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the list items are ok # Check the list items are ok
admins = json_response(response.body) admins = json_response(response.body)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Availabilities module Availabilities
class AsAdminTest < ActionDispatch::IntegrationTest class AsAdminTest < ActionDispatch::IntegrationTest
setup do setup do
@ -12,7 +14,7 @@ module Availabilities
# Check response format & status # Check response format & status
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct availability was returned # Check the correct availability was returned
availability = json_response(response.body) availability = json_response(response.body)
@ -26,7 +28,7 @@ module Availabilities
# Check response format & status # Check response format & status
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct availabilities was returned # Check the correct availabilities was returned
availabilities = json_response(response.body) availabilities = json_response(response.body)
@ -50,7 +52,7 @@ module Availabilities
# Check response format & status # Check response format & status
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct availabilities was returned # Check the correct availabilities was returned
availabilities = json_response(response.body) availabilities = json_response(response.body)
@ -72,15 +74,14 @@ module Availabilities
# Check response format & status # Check response format & status
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct availabilities was returned # Check the correct availabilities was returned
availabilities = json_response(response.body) availabilities = json_response(response.body)
assert_not_empty availabilities, 'no availabilities were found' assert_not_empty availabilities, 'no availabilities were found'
assert_not_nil availabilities[0], 'first availability was unexpectedly nil' assert_not_nil availabilities[0], 'first availability was unexpectedly nil'
assert availabilities.map {|a| a[:available_type] }.include?('space'), 'space availability not found instead that it was enabled' assert availabilities.map { |a| a[:available_type] }.include?('space'), 'space availability not found instead that it was enabled'
end end
end end
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Availabilities::AsUserTest < ActionDispatch::IntegrationTest class Availabilities::AsUserTest < ActionDispatch::IntegrationTest
setup do setup do
user = User.find_by(username: 'kdumas') user = User.find_by(username: 'kdumas')
@ -11,7 +13,7 @@ class Availabilities::AsUserTest < ActionDispatch::IntegrationTest
# Check response format & status # Check response format & status
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct availabilities was returned # Check the correct availabilities was returned
availabilities = json_response(response.body) availabilities = json_response(response.body)
@ -27,8 +29,7 @@ class Availabilities::AsUserTest < ActionDispatch::IntegrationTest
# Check that we don't get availabilities in more than a month # Check that we don't get availabilities in more than a month
availabilities.each do |a| availabilities.each do |a|
assert_not a[:start] > 1.month.from_now , 'retrieved a slot in more than 1 month for user who has no yearly subscription' assert_not a[:start] > 1.month.from_now, 'retrieved a slot in more than 1 month for user who has no yearly subscription'
end end
end end
end end

View File

@ -2,7 +2,6 @@
module Credits module Credits
class TrainingTest < ActionDispatch::IntegrationTest class TrainingTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used # Called before every test method runs. Can be used
# to set up fixture information. # to set up fixture information.
def setup def setup
@ -11,10 +10,9 @@ module Credits
end end
test 'create machine credit' do test 'create machine credit' do
# First, we create a new credit # First, we create a new credit
post '/api/credits', post '/api/credits',
{ params: {
credit: { credit: {
creditable_id: 5, creditable_id: 5,
creditable_type: 'Machine', creditable_type: 'Machine',
@ -22,11 +20,11 @@ module Credits
plan_id: 1 plan_id: 1
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the credit was created correctly # Check the credit was created correctly
credit = json_response(response.body) credit = json_response(response.body)
@ -39,7 +37,7 @@ module Credits
test 'update a credit' do test 'update a credit' do
put '/api/credits/13', put '/api/credits/13',
{ params: {
credit: { credit: {
creditable_id: 4, creditable_id: 4,
creditable_type: 'Machine', creditable_type: 'Machine',
@ -47,11 +45,11 @@ module Credits
plan_id: 3 plan_id: 3
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the credit was correctly updated # Check the credit was correctly updated
credit = json_response(response.body) credit = json_response(response.body)

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module Credits module Credits
class TrainingTest < ActionDispatch::IntegrationTest class TrainingTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used # Called before every test method runs. Can be used
# to set up fixture information. # to set up fixture information.
def setup def setup
@ -9,21 +10,20 @@ module Credits
end end
test 'create training credit' do test 'create training credit' do
# First, we create a new credit # First, we create a new credit
post '/api/credits', post '/api/credits',
{ params: {
credit: { credit: {
creditable_id: 4, creditable_id: 4,
creditable_type: 'Training', creditable_type: 'Training',
plan_id: '1', plan_id: '1'
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the credit was created correctly # Check the credit was created correctly
credit = json_response(response.body) credit = json_response(response.body)
@ -36,18 +36,18 @@ module Credits
test 'create a existing credit' do test 'create a existing credit' do
post '/api/credits', post '/api/credits',
{ params: {
credit: { credit: {
creditable_id: 4, creditable_id: 4,
creditable_type: 'Training', creditable_type: 'Training',
plan_id: '2' plan_id: '2'
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 422, response.status, response.body assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
end end
end end
end end

View File

@ -1,17 +1,16 @@
# frozen_string_literal: true # frozen_string_literal: true
module Events module Events
class AsAdminTest < ActionDispatch::IntegrationTest class AsAdminTest < ActionDispatch::IntegrationTest
setup do setup do
admin = User.with_role(:admin).first admin = User.with_role(:admin).first
login_as(admin, scope: :user) login_as(admin, scope: :user)
end end
test 'creation modification reservation and re-modification scenario' do test 'creation modification reservation and re-modification scenario' do
# First, we create a new event # First, we create a new event
post '/api/events', post '/api/events',
{ params: {
event: { event: {
title: 'OpenLab discovery day', title: 'OpenLab discovery day',
description: 'A day to discover the Fablab and try its machines and possibilities.', description: 'A day to discover the Fablab and try its machines and possibilities.',
@ -23,11 +22,11 @@ module Events
amount: 0 amount: 0
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the event was created correctly # Check the event was created correctly
event = json_response(response.body) event = json_response(response.body)
@ -39,21 +38,23 @@ module Events
# Then, modify the event to set a nb of places # Then, modify the event to set a nb of places
put "/api/events/#{e.id}", put "/api/events/#{e.id}",
event: { params: {
title: 'OpenLab discovery day', event: {
description: 'A day to discover the Fablab and try its machines and possibilities.', title: 'OpenLab discovery day',
start_date: 1.week.from_now.utc, description: 'A day to discover the Fablab and try its machines and possibilities.',
start_time: 1.week.from_now.utc.change(hour: 16), start_date: 1.week.from_now.utc,
end_date: 1.week.from_now.utc, start_time: 1.week.from_now.utc.change(hour: 16),
end_time: 1.week.from_now.utc.change(hour: 20), end_date: 1.week.from_now.utc,
category_id: Category.first.id, end_time: 1.week.from_now.utc.change(hour: 20),
amount: 0, category_id: Category.first.id,
nb_total_places: 10 amount: 0,
nb_total_places: 10
}
} }
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the places numbers were updated successfully # Check the places numbers were updated successfully
e = Event.where(id: event[:id]).first e = Event.where(id: event[:id]).first
@ -62,7 +63,7 @@ module Events
# Now, let's make a reservation on this event # Now, let's make a reservation on this event
post '/api/reservations', post '/api/reservations',
{ params: {
reservation: { reservation: {
user_id: User.find_by(username: 'pdurand').id, user_id: User.find_by(username: 'pdurand').id,
reservable_id: e.id, reservable_id: e.id,
@ -78,11 +79,11 @@ module Events
] ]
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the remaining places were updated successfully # Check the remaining places were updated successfully
e = Event.where(id: event[:id]).first e = Event.where(id: event[:id]).first
@ -90,21 +91,23 @@ module Events
# Finally, modify the event to add some places # Finally, modify the event to add some places
put "/api/events/#{e.id}", put "/api/events/#{e.id}",
event: { params: {
title: 'OpenLab discovery day', event: {
description: 'A day to discover the Fablab and try its machines and possibilities.', title: 'OpenLab discovery day',
start_date: 1.week.from_now.utc, description: 'A day to discover the Fablab and try its machines and possibilities.',
start_time: 1.week.from_now.utc.change(hour: 16), start_date: 1.week.from_now.utc,
end_date: 1.week.from_now.utc, start_time: 1.week.from_now.utc.change(hour: 16),
end_time: 1.week.from_now.utc.change(hour: 20), end_date: 1.week.from_now.utc,
category_id: Category.first.id, end_time: 1.week.from_now.utc.change(hour: 20),
amount: 0, category_id: Category.first.id,
nb_total_places: 20 amount: 0,
nb_total_places: 20
}
} }
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the places numbers were updated successfully # Check the places numbers were updated successfully
e = Event.where(id: event[:id]).first e = Event.where(id: event[:id]).first
@ -113,12 +116,11 @@ module Events
end end
test 'create event with custom price and reserve it with success' do test 'create event with custom price and reserve it with success' do
price_category = PriceCategory.first price_category = PriceCategory.first
# First, we create a new event # First, we create a new event
post '/api/events', post '/api/events',
{ params: {
event: { event: {
title: 'Electronics initiation', title: 'Electronics initiation',
description: 'A workshop about electronics and the abilities to create robots.', description: 'A workshop about electronics and the abilities to create robots.',
@ -137,11 +139,11 @@ module Events
] ]
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the event was created correctly # Check the event was created correctly
event = json_response(response.body) event = json_response(response.body)
@ -155,7 +157,7 @@ module Events
# Now, let's make a reservation on this event # Now, let's make a reservation on this event
post '/api/reservations', post '/api/reservations',
{ params: {
reservation: { reservation: {
user_id: User.find_by(username: 'lseguin').id, user_id: User.find_by(username: 'lseguin').id,
reservable_id: e.id, reservable_id: e.id,
@ -177,11 +179,11 @@ module Events
] ]
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the reservation match the required event # Check the reservation match the required event
reservation = json_response(response.body) reservation = json_response(response.body)
@ -197,7 +199,6 @@ module Events
# Check the resulting invoice generation and it has right price # Check the resulting invoice generation and it has right price
assert_invoice_pdf r.invoice assert_invoice_pdf r.invoice
assert_equal (4 * 20) + (4 * 16), r.invoice.total / 100.0 assert_equal (4 * 20) + (4 * 16), r.invoice.total / 100.0
end end
end end
end end

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true
module Events module Events
class AsUserTest < ActionDispatch::IntegrationTest class AsUserTest < ActionDispatch::IntegrationTest
test 'reserve event with many prices and payment means and VAT' do test 'reserve event with many prices and payment means and VAT' do
vlonchamp = User.find_by(username: 'vlonchamp') vlonchamp = User.find_by(username: 'vlonchamp')
login_as(vlonchamp, scope: :user) login_as(vlonchamp, scope: :user)
@ -27,7 +27,7 @@ module Events
# Reserve the 'radio' event # Reserve the 'radio' event
VCR.use_cassette('reserve_event_with_many_prices_and_payment_means') do VCR.use_cassette('reserve_event_with_many_prices_and_payment_means') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
reservation: { reservation: {
@ -56,7 +56,7 @@ module Events
}, },
coupon_code: 'SUNNYFABLAB' coupon_code: 'SUNNYFABLAB'
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
vlonchamp.wallet.reload vlonchamp.wallet.reload
@ -80,14 +80,14 @@ module Events
refute invoice.stp_payment_intent_id.blank? refute invoice.stp_payment_intent_id.blank?
refute invoice.total.blank? refute invoice.total.blank?
assert_equal 43350, invoice.total # total minus coupon assert_equal 43_350, invoice.total # total minus coupon
# invoice_items assertions # invoice_items assertions
## reservation ## reservation
reservation_item = invoice.invoice_items.first reservation_item = invoice.invoice_items.first
assert_not_nil reservation_item assert_not_nil reservation_item
assert_equal 51000, reservation_item.amount # full total assert_equal 51_000, reservation_item.amount # full total
# invoice assertions # invoice assertions
invoice = Invoice.find_by(invoiced: reservation) invoice = Invoice.find_by(invoiced: reservation)
@ -109,7 +109,6 @@ module Events
# notifications # notifications
assert_not_empty Notification.where(attached_object: reservation) assert_not_empty Notification.where(attached_object: reservation)
assert_not_empty Notification.where(attached_object: invoice) assert_not_empty Notification.where(attached_object: invoice)
end end
end end
end end

View File

@ -3,17 +3,15 @@
module Exports; end module Exports; end
class Exports::AccountingExportTest < ActionDispatch::IntegrationTest class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
setup do setup do
admin = User.with_role(:admin).first admin = User.with_role(:admin).first
login_as(admin, scope: :user) login_as(admin, scope: :user)
end end
test 'creation modification reservation and re-modification scenario' do test 'creation modification reservation and re-modification scenario' do
# First, we create a new export # First, we create a new export
post '/api/accounting/export', post '/api/accounting/export',
{ params: {
query: { query: {
columns: %w[journal_code date account_code account_label piece line_label debit_origin credit_origin debit_euro credit_euro lettering], columns: %w[journal_code date account_code account_label piece line_label debit_origin credit_origin debit_euro credit_euro lettering],
encoding: 'ISO-8859-1', encoding: 'ISO-8859-1',
@ -28,11 +26,11 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
type: 'acd', type: 'acd',
key: ';' key: ';'
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the export was created correctly # Check the export was created correctly
res = json_response(response.body) res = json_response(response.body)
@ -134,10 +132,8 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest
STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{last_invoice.id} is not a Machine reservation" STDERR.puts "WARNING: unable to test accurately accounting export: invoice #{last_invoice.id} is not a Machine reservation"
end end
# Clean CSV file # Clean CSV file
require 'fileutils' require 'fileutils'
FileUtils.rm(e.file) FileUtils.rm(e.file)
end end
end end

View File

@ -1,7 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
class InvoicesTest < ActionDispatch::IntegrationTest class InvoicesTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used # Called before every test method runs. Can be used
# to set up fixture information. # to set up fixture information.
def setup def setup
@ -10,18 +9,18 @@ class InvoicesTest < ActionDispatch::IntegrationTest
end end
test 'admin list invoices' do test 'admin list invoices' do
post '/api/invoices/list', { query: { post '/api/invoices/list', params: { query: {
number: '', number: '',
customer: '', customer: '',
date: nil, date: nil,
order_by: '-reference', order_by: '-reference',
page: 1, page: 1,
size: 20 # test db may have < 20 invoices size: 20 # test db may have < 20 invoices
} }.to_json, default_headers } }.to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check that we have all invoices # Check that we have all invoices
invoices = json_response(response.body) invoices = json_response(response.body)
@ -35,18 +34,18 @@ class InvoicesTest < ActionDispatch::IntegrationTest
test 'admin generates a refund' do test 'admin generates a refund' do
date = DateTime.current.iso8601 date = DateTime.current.iso8601
post '/api/invoices', { avoir: { post '/api/invoices', params: { avoir: {
avoir_date: date, avoir_date: date,
payment_method: 'cash', payment_method: 'cash',
description: 'Lorem ipsum', description: 'Lorem ipsum',
invoice_id: 4, invoice_id: 4,
invoice_items_ids: [4], invoice_items_ids: [4],
subscription_to_expire: false subscription_to_expire: false
} }.to_json, default_headers } }.to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check that the refund match # Check that the refund match
refund = json_response(response.body) refund = json_response(response.body)
@ -68,22 +67,20 @@ class InvoicesTest < ActionDispatch::IntegrationTest
test 'admin fails generates a refund in closed period' do test 'admin fails generates a refund in closed period' do
date = '2015-10-01T13:09:55+01:00'.to_datetime date = '2015-10-01T13:09:55+01:00'.to_datetime
post '/api/invoices', { avoir: { post '/api/invoices', params: { avoir: {
avoir_date: date, avoir_date: date,
payment_method: 'cash', payment_method: 'cash',
description: 'Unable to refund', description: 'Unable to refund',
invoice_id: 5, invoice_id: 5,
invoice_items_ids: [5], invoice_items_ids: [5],
subscription_to_expire: false subscription_to_expire: false
} }.to_json, default_headers } }.to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 422, response.status, response.body assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the error was handled # Check the error was handled
assert_match(/#{I18n.t('errors.messages.in_closed_period')}/, response.body) assert_match(/#{I18n.t('errors.messages.in_closed_period')}/, response.body)
end end
end end

View File

@ -13,7 +13,7 @@ class MembersTest < ActionDispatch::IntegrationTest
email = 'robert.dubois@gmail.com' email = 'robert.dubois@gmail.com'
VCR.use_cassette('members_admin_create_success') do VCR.use_cassette('members_admin_create_success') do
post members_path, { user: { post members_path, params: { user: {
username: 'bob', username: 'bob',
email: email, email: email,
group_id: group_id, group_id: group_id,
@ -31,12 +31,12 @@ class MembersTest < ActionDispatch::IntegrationTest
gender: true, gender: true,
birthday: '2018-02-08' birthday: '2018-02-08'
} }
} }.to_json, default_headers } }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check that the user's match # Check that the user's match
user = json_response(response.body) user = json_response(response.body)
@ -48,13 +48,13 @@ class MembersTest < ActionDispatch::IntegrationTest
user = User.friendly.find('kdumas') user = User.friendly.find('kdumas')
# we cannot update an kevin's group because he's got a running subscription # we cannot update an kevin's group because he's got a running subscription
put "/api/members/#{user.id}", { user: { put "/api/members/#{user.id}", params: { user: {
group_id: 1 group_id: 1
} }.to_json, default_headers } }.to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 422, response.status, response.body assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check error message # Check error message
res = json_response(response.body) res = json_response(response.body)
@ -70,18 +70,18 @@ class MembersTest < ActionDispatch::IntegrationTest
} }
instagram = 'https://www.instagram.com/vanessa/' instagram = 'https://www.instagram.com/vanessa/'
put "/api/members/#{user.id}", user_hash.deep_merge( put "/api/members/#{user.id}", params: user_hash.deep_merge(
user: { user: {
group_id: 2, group_id: 2,
profile_attributes: { profile_attributes: {
instagram: instagram instagram: instagram
} }
} }
).to_json, default_headers ).to_json, headers: default_headers
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check update result # Check update result
res = json_response(response.body) res = json_response(response.body)
@ -94,7 +94,7 @@ class MembersTest < ActionDispatch::IntegrationTest
## Check response format & status ## Check response format & status
# assert_equal 200, response.status, response.body # assert_equal 200, response.status, response.body
# assert_equal Mime::JSON, response.content_type # assert_equal Mime[:json], response.content_type
## Check search result ## Check search result
# res = json_response(response.body) # res = json_response(response.body)

View File

@ -9,16 +9,15 @@ class ImportTest < ActionDispatch::IntegrationTest
end end
test 'bulk import members through CSV' do test 'bulk import members through CSV' do
bulk_csv = fixture_file_upload('files/members.csv', 'text/csv') bulk_csv = fixture_file_upload('files/members.csv', 'text/csv')
post '/api/imports/members', post '/api/imports/members',
{ params: {
import_members: bulk_csv, import_members: bulk_csv,
update_field: 'id' update_field: 'id'
}, default_headers }, headers: default_headers
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check that the returned import was created # Check that the returned import was created
import = json_response(response.body) import = json_response(response.body)
@ -66,6 +65,5 @@ class ImportTest < ActionDispatch::IntegrationTest
assert_equal 'update', res[10][:status], 'wrong operation: jean dupont should have been updated' assert_equal 'update', res[10][:status], 'wrong operation: jean dupont should have been updated'
assert res[10][:result], 'wrong result: operation should have succeeded' assert res[10][:result], 'wrong result: operation should have succeeded'
assert_equal res[9][:row]['email'], User.find(res[10][:user]).email, 'jean dupont email was not updated' assert_equal res[9][:row]['email'], User.find(res[10][:user]).email, 'jean dupont email was not updated'
end end
end end

View File

@ -1,6 +1,7 @@
# frozen_string_literal: true
module Prices module Prices
class AsAdminTest < ActionDispatch::IntegrationTest class AsAdminTest < ActionDispatch::IntegrationTest
setup do setup do
admin = User.with_role(:admin).first admin = User.with_role(:admin).first
login_as(admin, scope: :user) login_as(admin, scope: :user)
@ -12,7 +13,7 @@ module Prices
printer_training = availability.trainings.first printer_training = availability.trainings.first
post '/api/prices/compute', post '/api/prices/compute',
{ params: {
reservation: { reservation: {
user_id: user.id, user_id: user.id,
reservable_id: printer_training.id, reservable_id: printer_training.id,
@ -27,11 +28,11 @@ module Prices
] ]
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the price was computed correctly # Check the price was computed correctly
price = json_response(response.body) price = json_response(response.body)
@ -40,7 +41,6 @@ module Prices
'Computed price did not match training price' 'Computed price did not match training price'
end end
test 'compute price for a machine reservation with an offered slot and a subscription' do test 'compute price for a machine reservation with an offered slot and a subscription' do
user = User.find_by(username: 'jdupond') user = User.find_by(username: 'jdupond')
availability = Availability.find(3) availability = Availability.find(3)
@ -48,7 +48,7 @@ module Prices
plan = Plan.where(group_id: user.group_id, interval: 'month').first plan = Plan.where(group_id: user.group_id, interval: 'month').first
post '/api/prices/compute', post '/api/prices/compute',
{ params: {
reservation: { reservation: {
user_id: user.id, user_id: user.id,
reservable_id: laser.id, reservable_id: laser.id,
@ -70,11 +70,11 @@ module Prices
] ]
} }
}.to_json, }.to_json,
default_headers headers: default_headers
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the event was created correctly # Check the event was created correctly
price = json_response(response.body) price = json_response(response.body)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Reservations module Reservations
class CreateAsAdminTest < ActionDispatch::IntegrationTest class CreateAsAdminTest < ActionDispatch::IntegrationTest
setup do setup do
@ -16,7 +18,7 @@ module Reservations
invoice_items_count = InvoiceItem.count invoice_items_count = InvoiceItem.count
users_credit_count = UsersCredit.count users_credit_count = UsersCredit.count
post reservations_path, { reservation: { post reservations_path, params: { reservation: {
user_id: @user_without_subscription.id, user_id: @user_without_subscription.id,
reservable_id: machine.id, reservable_id: machine.id,
reservable_type: machine.class.name, reservable_type: machine.class.name,
@ -27,7 +29,7 @@ module Reservations
availability_id: availability.id availability_id: availability.id
} }
] ]
} }.to_json, default_headers } }.to_json, headers: default_headers
# general assertions # general assertions
assert_equal 201, response.status assert_equal 201, response.status
@ -73,7 +75,7 @@ module Reservations
invoice_count = Invoice.count invoice_count = Invoice.count
invoice_items_count = InvoiceItem.count invoice_items_count = InvoiceItem.count
post reservations_path, { reservation: { post reservations_path, params: { reservation: {
user_id: @user_without_subscription.id, user_id: @user_without_subscription.id,
reservable_id: training.id, reservable_id: training.id,
reservable_type: training.class.name, reservable_type: training.class.name,
@ -84,7 +86,7 @@ module Reservations
availability_id: availability.id availability_id: availability.id
} }
] ]
} }.to_json, default_headers } }.to_json, headers: default_headers
# general assertions # general assertions
assert_equal 201, response.status assert_equal 201, response.status
@ -130,7 +132,7 @@ module Reservations
invoice_items_count = InvoiceItem.count invoice_items_count = InvoiceItem.count
users_credit_count = UsersCredit.count users_credit_count = UsersCredit.count
post reservations_path, { reservation: { post reservations_path, params: { reservation: {
user_id: @user_with_subscription.id, user_id: @user_with_subscription.id,
reservable_id: machine.id, reservable_id: machine.id,
reservable_type: machine.class.name, reservable_type: machine.class.name,
@ -146,7 +148,7 @@ module Reservations
availability_id: availability.id availability_id: availability.id
} }
] ]
} }.to_json, default_headers } }.to_json, headers: default_headers
# general assertions # general assertions
assert_equal 201, response.status assert_equal 201, response.status
@ -203,7 +205,7 @@ module Reservations
invoice_items_count = InvoiceItem.count invoice_items_count = InvoiceItem.count
users_credit_count = UsersCredit.count users_credit_count = UsersCredit.count
post reservations_path, { reservation: { post reservations_path, params: { reservation: {
user_id: @vlonchamp.id, user_id: @vlonchamp.id,
reservable_id: machine.id, reservable_id: machine.id,
reservable_type: machine.class.name, reservable_type: machine.class.name,
@ -214,7 +216,7 @@ module Reservations
availability_id: availability.id availability_id: availability.id
} }
] ]
} }.to_json, default_headers } }.to_json, headers: default_headers
# general assertions # general assertions
assert_equal 201, response.status assert_equal 201, response.status
@ -273,7 +275,7 @@ module Reservations
users_credit_count = UsersCredit.count users_credit_count = UsersCredit.count
wallet_transactions_count = WalletTransaction.count wallet_transactions_count = WalletTransaction.count
post reservations_path, { reservation: { post reservations_path, params: { reservation: {
user_id: @vlonchamp.id, user_id: @vlonchamp.id,
reservable_id: machine.id, reservable_id: machine.id,
reservable_type: machine.class.name, reservable_type: machine.class.name,
@ -285,7 +287,7 @@ module Reservations
availability_id: availability.id availability_id: availability.id
} }
] ]
} }.to_json, default_headers } }.to_json, headers: default_headers
# general assertions # general assertions
assert_equal 201, response.status assert_equal 201, response.status
@ -340,7 +342,7 @@ module Reservations
invoice_items_count = InvoiceItem.count invoice_items_count = InvoiceItem.count
users_credit_count = UsersCredit.count users_credit_count = UsersCredit.count
post reservations_path, { reservation: { post reservations_path, params: { reservation: {
user_id: @vlonchamp.id, user_id: @vlonchamp.id,
reservable_id: machine.id, reservable_id: machine.id,
reservable_type: machine.class.name, reservable_type: machine.class.name,
@ -351,7 +353,7 @@ module Reservations
availability_id: availability.id availability_id: availability.id
} }
] ]
} }.to_json, default_headers } }.to_json, headers: default_headers
# general assertions # general assertions
assert_equal 201, response.status assert_equal 201, response.status
@ -383,7 +385,7 @@ module Reservations
invoice_items_count = InvoiceItem.count invoice_items_count = InvoiceItem.count
users_credit_count = UsersCredit.count users_credit_count = UsersCredit.count
post reservations_path, { reservation: { post reservations_path, params: { reservation: {
user_id: @user_without_subscription.id, user_id: @user_without_subscription.id,
plan_id: plan.id, plan_id: plan.id,
reservable_id: training.id, reservable_id: training.id,
@ -396,11 +398,11 @@ module Reservations
availability_id: availability.id availability_id: availability.id
} }
] ]
} }.to_json, default_headers } }.to_json, headers: default_headers
# general assertions # general assertions
assert_equal 201, response.status assert_equal 201, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
result = json_response(response.body) result = json_response(response.body)
# Check the DB objects have been created as they should # Check the DB objects have been created as they should

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Reservations module Reservations
class CreateTest < ActionDispatch::IntegrationTest class CreateTest < ActionDispatch::IntegrationTest
setup do setup do
@ -19,7 +21,7 @@ module Reservations
VCR.use_cassette('reservations_create_for_machine_without_subscription_success') do VCR.use_cassette('reservations_create_for_machine_without_subscription_success') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
reservation: { reservation: {
@ -34,7 +36,7 @@ module Reservations
] ]
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# general assertions # general assertions
@ -89,7 +91,7 @@ module Reservations
VCR.use_cassette('reservations_create_for_machine_without_subscription_error') do VCR.use_cassette('reservations_create_for_machine_without_subscription_error') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method(error: :card_declined), payment_method_id: stripe_payment_method(error: :card_declined),
cart_items: { cart_items: {
reservation: { reservation: {
@ -104,12 +106,12 @@ module Reservations
] ]
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 200, response.status, "API does not return the expected status. #{response.body}" assert_equal 200, response.status, "API does not return the expected status. #{response.body}"
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the error was handled # Check the error was handled
assert_match /Your card was declined/, response.body assert_match /Your card was declined/, response.body
@ -137,7 +139,7 @@ module Reservations
VCR.use_cassette('reservations_create_for_training_without_subscription_success') do VCR.use_cassette('reservations_create_for_training_without_subscription_success') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
reservation: { reservation: {
@ -152,7 +154,7 @@ module Reservations
] ]
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# general assertions # general assertions
@ -206,7 +208,7 @@ module Reservations
VCR.use_cassette('reservations_create_for_machine_with_subscription_success') do VCR.use_cassette('reservations_create_for_machine_with_subscription_success') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
reservation: { reservation: {
@ -226,7 +228,7 @@ module Reservations
] ]
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# general assertions # general assertions
@ -290,7 +292,7 @@ module Reservations
VCR.use_cassette('reservations_create_for_training_with_subscription_success') do VCR.use_cassette('reservations_create_for_training_with_subscription_success') do
post '/api/reservations', post '/api/reservations',
{ params: {
reservation: { reservation: {
reservable_id: training.id, reservable_id: training.id,
reservable_type: training.class.name, reservable_type: training.class.name,
@ -302,7 +304,7 @@ module Reservations
} }
] ]
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# general assertions # general assertions
@ -361,7 +363,7 @@ module Reservations
VCR.use_cassette('reservations_create_for_machine_and_pay_wallet_success') do VCR.use_cassette('reservations_create_for_machine_and_pay_wallet_success') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
reservation: { reservation: {
@ -378,7 +380,7 @@ module Reservations
] ]
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
@vlonchamp.wallet.reload @vlonchamp.wallet.reload
@ -445,7 +447,7 @@ module Reservations
VCR.use_cassette('reservations_create_for_training_and_plan_by_pay_wallet_success') do VCR.use_cassette('reservations_create_for_training_and_plan_by_pay_wallet_success') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
reservation: { reservation: {
@ -461,7 +463,7 @@ module Reservations
] ]
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
@vlonchamp.wallet.reload @vlonchamp.wallet.reload
@ -523,7 +525,7 @@ module Reservations
VCR.use_cassette('reservations_machine_and_plan_using_coupon_success') do VCR.use_cassette('reservations_machine_and_plan_using_coupon_success') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
reservation: { reservation: {
@ -540,7 +542,7 @@ module Reservations
}, },
coupon_code: 'SUNNYFABLAB' coupon_code: 'SUNNYFABLAB'
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# general assertions # general assertions
@ -614,7 +616,7 @@ module Reservations
VCR.use_cassette('reservations_training_with_expired_coupon_error') do VCR.use_cassette('reservations_training_with_expired_coupon_error') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
reservation: { reservation: {
@ -624,15 +626,15 @@ module Reservations
card_token: stripe_payment_method, card_token: stripe_payment_method,
slots_attributes: [ slots_attributes: [
{ {
start_at: availability.start_at.to_s(:iso8601), start_at: availability.start_at.to_s(:iso8601),
end_at: (availability.start_at + 1.hour).to_s(:iso8601), end_at: (availability.start_at + 1.hour).to_s(:iso8601),
availability_id: availability.id availability_id: availability.id
} }
] ]
}, },
coupon_code: 'XMAS10' coupon_code: 'XMAS10'
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# general assertions # general assertions

View File

@ -1,5 +1,6 @@
class SettingsTest < ActionDispatch::IntegrationTest # frozen_string_literal: true
class SettingsTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used # Called before every test method runs. Can be used
# to set up fixture information. # to set up fixture information.
def setup def setup
@ -9,11 +10,13 @@ class SettingsTest < ActionDispatch::IntegrationTest
test 'update setting value' do test 'update setting value' do
put '/api/settings/fablab_name', put '/api/settings/fablab_name',
setting: { params: {
value: 'Test Fablab' setting: {
value: 'Test Fablab'
}
} }
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
resp = json_response(response.body) resp = json_response(response.body)
assert_equal 'fablab_name', resp[:setting][:name] assert_equal 'fablab_name', resp[:setting][:name]
assert_equal 'Test Fablab', resp[:setting][:value] assert_equal 'Test Fablab', resp[:setting][:value]
@ -26,11 +29,12 @@ class SettingsTest < ActionDispatch::IntegrationTest
assert_includes setting.history_values.map(&:value), 'Test Fablab', 'current parameter was not saved' assert_includes setting.history_values.map(&:value), 'Test Fablab', 'current parameter was not saved'
end end
test 'update setting with wrong name' do test 'update setting with wrong name' do
put '/api/settings/does_not_exists', put '/api/settings/does_not_exists',
setting: { params: {
value: 'ERROR EXPECTED' setting: {
value: 'ERROR EXPECTED'
}
} }
assert_equal 422, response.status assert_equal 422, response.status
assert_match /Name is not included in the list/, response.body assert_match /Name is not included in the list/, response.body
@ -40,10 +44,9 @@ class SettingsTest < ActionDispatch::IntegrationTest
get '/api/settings/fablab_name' get '/api/settings/fablab_name'
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
resp = json_response(response.body) resp = json_response(response.body)
assert_equal 'fablab_name', resp[:setting][:name], 'wrong parameter name' assert_equal 'fablab_name', resp[:setting][:name], 'wrong parameter name'
assert_equal 'Fab Lab de La Casemate', resp[:setting][:value], 'wrong parameter value' assert_equal 'Fab Lab de La Casemate', resp[:setting][:value], 'wrong parameter value'
end end
end end

View File

@ -2,8 +2,6 @@
module Subscriptions module Subscriptions
class CreateAsAdminTest < ActionDispatch::IntegrationTest class CreateAsAdminTest < ActionDispatch::IntegrationTest
setup do setup do
@admin = User.find_by(username: 'admin') @admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user) login_as(@admin, scope: :user)
@ -15,18 +13,17 @@ module Subscriptions
VCR.use_cassette('subscriptions_admin_create_success') do VCR.use_cassette('subscriptions_admin_create_success') do
post '/api/subscriptions', post '/api/subscriptions',
{ params: {
subscription: { subscription: {
plan_id: plan.id, plan_id: plan.id,
user_id: user.id user_id: user.id
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct plan was subscribed # Check the correct plan was subscribed
subscription = json_response(response.body) subscription = json_response(response.body)
@ -58,6 +55,5 @@ module Subscriptions
assert_invoice_pdf invoice assert_invoice_pdf invoice
assert_equal plan.amount, invoice.total, 'Invoice total price does not match the bought subscription' assert_equal plan.amount, invoice.total, 'Invoice total price does not match the bought subscription'
end end
end end
end end

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
setup do setup do
@user = User.find_by(username: 'jdupond') @user = User.find_by(username: 'jdupond')
login_as(@user, scope: :user) login_as(@user, scope: :user)
@ -11,19 +11,19 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
VCR.use_cassette('subscriptions_user_create_success') do VCR.use_cassette('subscriptions_user_create_success') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
subscription: { subscription: {
plan_id: plan.id plan_id: plan.id
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct plan was subscribed # Check the correct plan was subscribed
subscription = json_response(response.body) subscription = json_response(response.body)
@ -65,27 +65,25 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
assert_equal plan.amount, invoice.total, 'Invoice total price does not match the bought subscription' assert_equal plan.amount, invoice.total, 'Invoice total price does not match the bought subscription'
end end
test 'user fails to take a subscription' do test 'user fails to take a subscription' do
# get plan for wrong group # get plan for wrong group
plan = Plan.where.not(group_id: @user.group.id).first plan = Plan.where.not(group_id: @user.group.id).first
VCR.use_cassette('subscriptions_user_create_failed') do VCR.use_cassette('subscriptions_user_create_failed') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
subscription: { subscription: {
plan_id: plan.id plan_id: plan.id
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 422, response.status, response.body assert_equal 422, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the error was handled # Check the error was handled
assert_match /plan is not compatible/, response.body assert_match /plan is not compatible/, response.body
@ -94,7 +92,6 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
assert_nil @user.subscription, "user's subscription was found" assert_nil @user.subscription, "user's subscription was found"
end end
test 'user successfully takes a subscription with wallet' do test 'user successfully takes a subscription with wallet' do
@vlonchamp = User.find_by(username: 'vlonchamp') @vlonchamp = User.find_by(username: 'vlonchamp')
login_as(@vlonchamp, scope: :user) login_as(@vlonchamp, scope: :user)
@ -102,21 +99,21 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
VCR.use_cassette('subscriptions_user_create_success_with_wallet') do VCR.use_cassette('subscriptions_user_create_success_with_wallet') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
subscription: { subscription: {
plan_id: plan.id plan_id: plan.id
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
@vlonchamp.wallet.reload @vlonchamp.wallet.reload
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct plan was subscribed # Check the correct plan was subscribed
subscription = json_response(response.body) subscription = json_response(response.body)
@ -138,7 +135,8 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
assert_equal 10, assert_equal 10,
(printer.prices.find_by( (printer.prices.find_by(
group_id: @vlonchamp.group_id, group_id: @vlonchamp.group_id,
plan_id: @vlonchamp.subscription.plan_id).amount / 100.00 plan_id: @vlonchamp.subscription.plan_id
).amount / 100.00
), ),
'machine hourly price does not match' 'machine hourly price does not match'

View File

@ -1,28 +1,28 @@
class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest # frozen_string_literal: true
class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
setup do setup do
@admin = User.find_by(username: 'admin') @admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user) login_as(@admin, scope: :user)
end end
test 'admin successfully renew a subscription before it has ended' do test 'admin successfully renew a subscription before it has ended' do
user = User.find_by(username: 'kdumas') user = User.find_by(username: 'kdumas')
plan = Plan.find_by(base_name: 'Mensuel tarif réduit') plan = Plan.find_by(base_name: 'Mensuel tarif réduit')
VCR.use_cassette('subscriptions_admin_renew_success') do VCR.use_cassette('subscriptions_admin_renew_success') do
post '/api/subscriptions', post '/api/subscriptions',
{ params: {
subscription: { subscription: {
plan_id: plan.id, plan_id: plan.id,
user_id: user.id user_id: user.id
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct plan was subscribed # Check the correct plan was subscribed
subscription = json_response(response.body) subscription = json_response(response.body)
@ -74,17 +74,17 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
VCR.use_cassette('subscriptions_admin_offer_free_days') do VCR.use_cassette('subscriptions_admin_offer_free_days') do
put "/api/subscriptions/#{subscription.id}", put "/api/subscriptions/#{subscription.id}",
{ params: {
subscription: { subscription: {
expired_at: new_date.strftime('%Y-%m-%d %H:%M:%S.%9N Z'), expired_at: new_date.strftime('%Y-%m-%d %H:%M:%S.%9N Z'),
free: true free: true
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 200, response.status, response.body assert_equal 200, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check that the subscribed plan was not altered # Check that the subscribed plan was not altered
res_subscription = json_response(response.body) res_subscription = json_response(response.body)
@ -114,16 +114,16 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
VCR.use_cassette('subscriptions_admin_extends_subscription') do VCR.use_cassette('subscriptions_admin_extends_subscription') do
put "/api/subscriptions/#{subscription.id}", put "/api/subscriptions/#{subscription.id}",
{ params: {
subscription: { subscription: {
expired_at: new_date.strftime('%Y-%m-%d %H:%M:%S.%9N Z') expired_at: new_date.strftime('%Y-%m-%d %H:%M:%S.%9N Z')
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 201, response.status, response.body assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check that the subscribed plan is still the same # Check that the subscribed plan is still the same
res_subscription = json_response(response.body) res_subscription = json_response(response.body)
@ -145,5 +145,4 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
assert_not_nil notification, 'user notification was not created' assert_not_nil notification, 'user notification was not created'
assert_equal user.id, notification.receiver_id, 'wrong user notified' assert_equal user.id, notification.receiver_id, 'wrong user notified'
end end
end end

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest
setup do setup do
@user = User.find_by(username: 'lseguin') @user = User.find_by(username: 'lseguin')
login_as(@user, scope: :user) login_as(@user, scope: :user)
@ -12,19 +12,19 @@ class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest
VCR.use_cassette('subscriptions_user_renew_success', erb: true) do VCR.use_cassette('subscriptions_user_renew_success', erb: true) do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
cart_items: { cart_items: {
subscription: { subscription: {
plan_id: plan.id plan_id: plan.id
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 201, response.status, "API does not return the expected status. #{response.body}" assert_equal 201, response.status, "API does not return the expected status. #{response.body}"
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the correct plan was subscribed # Check the correct plan was subscribed
subscription = json_response(response.body) subscription = json_response(response.body)
@ -69,8 +69,6 @@ class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest
assert_equal plan.amount, invoice.total, 'Invoice total price does not match the bought subscription' assert_equal plan.amount, invoice.total, 'Invoice total price does not match the bought subscription'
end end
test 'user fails to renew a subscription' do test 'user fails to renew a subscription' do
plan = Plan.find_by(group_id: @user.group.id, type: 'Plan', base_name: 'Mensuel') plan = Plan.find_by(group_id: @user.group.id, type: 'Plan', base_name: 'Mensuel')
@ -78,19 +76,19 @@ class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest
VCR.use_cassette('subscriptions_user_renew_failed') do VCR.use_cassette('subscriptions_user_renew_failed') do
post '/api/payments/confirm_payment', post '/api/payments/confirm_payment',
{ params: {
payment_method_id: stripe_payment_method(error: :card_declined), payment_method_id: stripe_payment_method(error: :card_declined),
cart_items: { cart_items: {
subscription: { subscription: {
plan_id: plan.id plan_id: plan.id
} }
} }
}.to_json, default_headers }.to_json, headers: default_headers
end end
# Check response format & status # Check response format & status
assert_equal 200, response.status, "API does not return the expected status. #{response.body}" assert_equal 200, response.status, "API does not return the expected status. #{response.body}"
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
# Check the error was handled # Check the error was handled
assert_match /Your card was declined/, response.body assert_match /Your card was declined/, response.body
@ -100,7 +98,5 @@ class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest
# Check the subscription was not saved # Check the subscription was not saved
assert_equal 1, @user.subscriptions.count assert_equal 1, @user.subscriptions.count
end end
end end

View File

@ -1,5 +1,6 @@
class WalletsTest < ActionDispatch::IntegrationTest # frozen_string_literal: true
class WalletsTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used # Called before every test method runs. Can be used
# to set up fixture information. # to set up fixture information.
def setup def setup
@ -17,7 +18,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
test 'get my wallet' do test 'get my wallet' do
get "/api/wallet/by_user/#{@vlonchamp.id}" get "/api/wallet/by_user/#{@vlonchamp.id}"
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
wallet = json_response(response.body) wallet = json_response(response.body)
assert_equal @vlonchamp.wallet.invoicing_profile_id, wallet[:invoicing_profile_id] assert_equal @vlonchamp.wallet.invoicing_profile_id, wallet[:invoicing_profile_id]
assert_equal @vlonchamp.wallet.amount, wallet[:amount] assert_equal @vlonchamp.wallet.amount, wallet[:amount]
@ -29,7 +30,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
@user1 = User.first @user1 = User.first
get "/api/wallet/by_user/#{@user1.id}" get "/api/wallet/by_user/#{@user1.id}"
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
wallet = json_response(response.body) wallet = json_response(response.body)
assert_equal @user1.wallet.invoicing_profile_id, wallet[:invoicing_profile_id] assert_equal @user1.wallet.invoicing_profile_id, wallet[:invoicing_profile_id]
assert_equal @user1.wallet.amount, wallet[:amount] assert_equal @user1.wallet.amount, wallet[:amount]
@ -45,7 +46,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
w = @vlonchamp.wallet w = @vlonchamp.wallet
get "/api/wallet/#{w.id}/transactions" get "/api/wallet/#{w.id}/transactions"
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
transactions = json_response(response.body) transactions = json_response(response.body)
assert_equal w.wallet_transactions.count, transactions.size assert_equal w.wallet_transactions.count, transactions.size
assert_equal wallet_transactions(:transaction1).id, transactions.first[:id] assert_equal wallet_transactions(:transaction1).id, transactions.first[:id]
@ -64,10 +65,10 @@ class WalletsTest < ActionDispatch::IntegrationTest
amount = 10.5 amount = 10.5
expected_amount = w.amount + amount expected_amount = w.amount + amount
put "/api/wallet/#{w.id}/credit", put "/api/wallet/#{w.id}/credit",
amount: amount params: { amount: amount }
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
wallet = json_response(response.body) wallet = json_response(response.body)
w.reload w.reload
assert_equal w.amount, expected_amount assert_equal w.amount, expected_amount
@ -77,7 +78,6 @@ class WalletsTest < ActionDispatch::IntegrationTest
assert_empty Invoice.where(invoiced: w.wallet_transactions.last) assert_empty Invoice.where(invoiced: w.wallet_transactions.last)
end end
test 'admin credit wallet with refund invoice generation' do test 'admin credit wallet with refund invoice generation' do
admin = users(:user_1) admin = users(:user_1)
login_as(admin, scope: :user) login_as(admin, scope: :user)
@ -86,13 +86,15 @@ class WalletsTest < ActionDispatch::IntegrationTest
avoir_date = DateTime.current.end_of_day avoir_date = DateTime.current.end_of_day
expected_amount = w.amount + amount expected_amount = w.amount + amount
put "/api/wallet/#{w.id}/credit", put "/api/wallet/#{w.id}/credit",
amount: amount, params: {
avoir: true, amount: amount,
avoir_date: avoir_date, avoir: true,
avoir_description: 'Some text' avoir_date: avoir_date,
avoir_description: 'Some text'
}
assert_equal 200, response.status assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type assert_equal Mime[:json], response.content_type
wallet = json_response(response.body) wallet = json_response(response.body)
w.reload w.reload
assert_equal w.amount, expected_amount assert_equal w.amount, expected_amount