1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(bug) unable to create a non-rolling plan

This commit is contained in:
Sylvain 2023-01-31 12:18:42 +01:00
parent 98d6363525
commit 001d024948
5 changed files with 63 additions and 13 deletions

View File

@ -2,8 +2,10 @@
- Updated shakapaker to 6.5.5
- Fix a bug: unable to create a recurrent event
- Fix a bug: unable to create a non-rolling plan
- Fix a bug: invalid month in date format
- Fix a bug: do not show theme and age-range fields in event form if no options were set
- Fix a bug: do not show catgory select in plan form if no options were set
- Fix a bug: new setups doesn't log
## v5.6.8 2023 January 26

View File

@ -156,7 +156,7 @@ export const PlanForm: React.FC<PlanFormProps> = ({ action, plan, onError, onSuc
disabled={action === 'update'}
label={t('app.admin.plan_form.group')}
id="group_id" />}
{categories && <FormSelect options={categories}
{categories?.length > 0 && <FormSelect options={categories}
formState={formState}
control={control}
id="plan_category_id"

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
# From this migration we remove is_rolling:true as the default value, because this introduced a bug:
# if the user leaves the form empty, the plan is considered as rolling which is not the desired behavior
class ChangeDefaultForPlanIsRolling < ActiveRecord::Migration[5.2]
def change
change_column_default :plans, :is_rolling, from: true, to: nil
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_01_19_143245) do
ActiveRecord::Schema.define(version: 2023_01_31_104958) do
# These are extensions that must be enabled in order to support this database
enable_extension "fuzzystrmatch"
@ -621,7 +621,7 @@ ActiveRecord::Schema.define(version: 2023_01_19_143245) do
t.datetime "created_at"
t.datetime "updated_at"
t.integer "training_credit_nb", default: 0
t.boolean "is_rolling", default: true
t.boolean "is_rolling"
t.text "description"
t.string "type"
t.string "base_name"

View File

@ -8,28 +8,26 @@ class CreatePlanTest < ActionDispatch::IntegrationTest
login_as(admin, scope: :user)
end
test 'create a plan' do
test 'create a transversal partner plan' do
plans_count = Plan.count
post '/api/plans',
params: {
plan: {
base_name: 'Abonnement test',
type: 'Plan',
group_id: 1,
type: 'PartnerPlan',
group_id: 'all',
plan_category_id: nil,
interval: 'week',
interval_count: 2,
amount: 10,
ui_weight: 0,
is_rolling: true,
monthly_payment: false,
monthly_payment: true,
description: 'lorem ipsum dolor sit amet',
partner_id: '',
partner_id: 6,
plan_file_attributes: {
id: nil,
_destroy: nil,
attachment: nil
attachment: fixture_file_upload('/files/document.pdf')
}
}
}.to_json,
@ -39,9 +37,50 @@ class CreatePlanTest < ActionDispatch::IntegrationTest
assert_equal 201, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the created plans
res = json_response(response.body)
assert_equal 2, res[:plan_ids].count
assert_equal plans_count + 2, Plan.count
plans = Plan.where(name: 'Abonnement test')
assert(plans.all? { |plan| !plan.plan_file.attachment.nil? })
assert(plans.all? { |plan| plan.type == 'PartnerPlan' })
assert(plans.all? { |plan| plan.partner_id == 6 })
assert(plans.all?(&:is_rolling))
end
test 'create a simple plan' do
plans_count = Plan.count
post '/api/plans',
params: {
plan: {
base_name: 'Abonnement simple',
type: 'Plan',
group_id: 1,
plan_category_id: nil,
interval: 'month',
interval_count: 1,
amount: 40
}
}.to_json,
headers: default_headers
# Check response format & status
assert_equal 201, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the created plan
plan = json_response(response.body)
assert_equal Plan.last.id, plan[:plan_ids][0]
res = json_response(response.body)
assert_equal plans_count + 1, Plan.count
plan = Plan.find(res[:plan_ids][0])
assert_not_nil plan
assert_equal 'Abonnement simple', plan.base_name
assert_not plan.is_rolling
assert_equal 1, plan.group_id
assert_equal 'month', plan.interval
assert_equal 1, plan.interval_count
assert_equal 4000, plan.amount
end
end