Skip to content

Commit

Permalink
Merge branch 'master' into feature_project_setup_i3
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinKato committed Nov 21, 2023
2 parents d8244a9 + 847d8fe commit 48ef21c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
10 changes: 10 additions & 0 deletions back/app/services/form_logic_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def valid?
end
end

def remove_select_logic_option_from_custom_fields(frozen_custom_field_option)
custom_field = frozen_custom_field_option.custom_field

return unless custom_field&.logic.present? &&
custom_field.logic['rules'].pluck('if').include?(frozen_custom_field_option.id)

custom_field.logic['rules'].reject! { |rule| rule['if'] == frozen_custom_field_option.id }
custom_field.save!
end

private

attr_reader :fields, :field_index, :option_index
Expand Down
6 changes: 6 additions & 0 deletions back/app/services/side_fx_custom_field_option_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def before_destroy(custom_field_option, _current_user)
end

def after_destroy(frozen_custom_field_option, current_user)
custom_field = frozen_custom_field_option.custom_field
if custom_field&.resource_type == 'CustomForm' && custom_field&.input_type == 'select'
FormLogicService.new([frozen_custom_field_option.custom_field])
.remove_select_logic_option_from_custom_fields(frozen_custom_field_option)
end

serialized_custom_field_option = clean_time_attributes(frozen_custom_field_option.attributes)
LogActivityJob.perform_later(
encode_frozen_resource(frozen_custom_field_option),
Expand Down
29 changes: 28 additions & 1 deletion back/spec/services/side_fx_custom_field_option_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:service) { described_class.new }
let(:user) { create(:user) }

describe 'before_delete' do
describe 'before_destroy' do
let(:custom_field) { create(:custom_field, :for_custom_form, input_type: 'select') }
let(:option1) { create(:custom_field_option, custom_field: custom_field, key: 'option_1') }
let!(:user1) { create(:user, custom_field_values: { custom_field.key => 'option_1' }) }
Expand All @@ -19,4 +19,31 @@
end
end
end

describe 'after_destroy' do
let(:custom_field1) { create(:custom_field, :for_custom_form, input_type: 'select') }
let(:custom_field2) { create(:custom_field, :for_custom_form, input_type: 'page') }
let(:custom_field3) { create(:custom_field, :for_custom_form, input_type: 'page') }
let(:option1) { create(:custom_field_option, custom_field: custom_field1, key: 'option_1') }
let(:option2) { create(:custom_field_option, custom_field: custom_field1, key: 'option_2') }
let(:logic) do
{ rules: [
{ if: option1.id, goto_page_id: custom_field2.id },
{ if: option2.id, goto_page_id: custom_field3.id }
] }
end

before do
custom_field1.update!(logic: logic)
end

context 'when custom field option that is a survey logic option is destroyed' do
it 'removes the logic option from custom fields that contain it' do
service.after_destroy(option1, user)

expect(custom_field1.reload.logic['rules'].count).to eq 1
expect(custom_field1.reload.logic['rules'].pluck('if')).to eq [option2.id]
end
end
end
end
2 changes: 1 addition & 1 deletion cl2-component-library/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.11.23",
"version": "0.11.24",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion front/cypress/e2e/sign_up_custom_fields.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomString, randomEmail, logout } from '../support/commands';

describe('Sign up - custom fields step', () => {
describe('No custom fields', () => {
describe.skip('No custom fields', () => {
before(() => {
const firstName = randomString();
const lastName = randomString();
Expand Down

0 comments on commit 48ef21c

Please sign in to comment.