forest_liana 5.3.3 → 6.0.0.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52b354dcc7c4a05c8303bffa7c1deca674900d7b693f37e816d2bafe665c4b12
4
- data.tar.gz: 358a702306af12e805a6fe954c2e0fbb1d1ccc3ebe8fe8d8b73d6ebd8f101bb5
3
+ metadata.gz: 8a534b6abdb1a47d2690f785ef13dff74d97117fa7e1871b82659644ac9c1a53
4
+ data.tar.gz: 9d7c3281edc36a9aabf47f74851c3ba191d1e31c7bd29a0a4c7d9e8b6f3522f7
5
5
  SHA512:
6
- metadata.gz: 68dac9b8f4e7f427d1c9f4bf885d2412cf740b8e6038a6e83e919c967e9fbe9369fddc753992b7d80a191a04688366c06cc028a2afe309a476686e993603e8a6
7
- data.tar.gz: fcdb37f174ec29d416bfe1ce668608baa9e1924ec6ea2b51e61dcc74f1976e11fdf6eb41eb5503a22ed352d4e0ad772bc1498f2f31f958a467ac54dcf6e56a75
6
+ metadata.gz: c18f213548f7584a4dc7aabe121442d0e50270f29860c54164348bd45fca77810d5402284147b9a114d04f17b5314ee8d7f64daae1887e6f258cfd7663ba6c1f
7
+ data.tar.gz: 6edfe33f160b65de926013b45ef0ba4b7ae374a4446faf64ca6ffbd3a5e606845c89c9e30756fe8e26d4d420786ab09a36b38b0077d0c975a4d695b0aaa0c5ef
@@ -1,102 +1,7 @@
1
1
  module ForestLiana
2
2
  class ActionsController < ForestLiana::BaseController
3
-
4
3
  def values
5
4
  render serializer: nil, json: {}, status: :ok
6
5
  end
7
-
8
- def get_collection(collection_name)
9
- ForestLiana.apimap.find { |collection| collection.name.to_s == collection_name }
10
- end
11
-
12
- def get_action(collection_name)
13
- collection = get_collection(collection_name)
14
- begin
15
- collection.actions.find {|action| ActiveSupport::Inflector.parameterize(action.name) == params[:action_name]}
16
- rescue => error
17
- FOREST_LOGGER.error "Smart Action get action retrieval error: #{error}"
18
- nil
19
- end
20
- end
21
-
22
- def get_record
23
- model = ForestLiana::SchemaUtils.find_model_from_collection_name(params[:collectionName])
24
- redord_getter = ForestLiana::ResourceGetter.new(model, {:id => params[:recordIds][0]})
25
- redord_getter.perform
26
- redord_getter.record
27
- end
28
-
29
- def get_smart_action_load_ctx(fields)
30
- fields = fields.reduce({}) do |p, c|
31
- ForestLiana::WidgetsHelper.set_field_widget(c)
32
- p.update(c[:field] => c.merge!(value: nil))
33
- end
34
- {:record => get_record, :fields => fields}
35
- end
36
-
37
- def get_smart_action_change_ctx(fields)
38
- fields = fields.reduce({}) do |p, c|
39
- field = c.permit!.to_h.symbolize_keys
40
- ForestLiana::WidgetsHelper.set_field_widget(field)
41
- p.update(c[:field] => field)
42
- end
43
- {:record => get_record, :fields => fields}
44
- end
45
-
46
- def handle_result(result, formatted_fields, action)
47
- if result.nil? || !result.is_a?(Hash)
48
- return render status: 500, json: { error: 'Error in smart action load hook: hook must return an object' }
49
- end
50
- is_same_data_structure = ForestLiana::IsSameDataStructureHelper::Analyser.new(formatted_fields, result, 1)
51
- unless is_same_data_structure.perform
52
- return render status: 500, json: { error: 'Error in smart action hook: fields must be unchanged (no addition nor deletion allowed)' }
53
- end
54
-
55
- # Apply result on fields (transform the object back to an array), preserve order.
56
- fields = action.fields.map do |field|
57
- updated_field = result[field[:field]]
58
- # Reset `value` when not present in `enums` (which means `enums` has changed).
59
- if updated_field[:enums].is_a?(Array) && !updated_field[:enums].include?(updated_field[:value])
60
- updated_field[:value] = nil
61
- end
62
- updated_field
63
- end
64
-
65
- render serializer: nil, json: { fields: fields}, status: :ok
66
- end
67
-
68
- def load
69
- action = get_action(params[:collectionName])
70
-
71
- if !action
72
- render status: 500, json: {error: 'Error in smart action load hook: cannot retrieve action from collection'}
73
- else
74
- # Transform fields from array to an object to ease usage in hook, adds null value.
75
- context = get_smart_action_load_ctx(action.fields)
76
- formatted_fields = context[:fields].clone # clone for following test on is_same_data_structure
77
-
78
- # Call the user-defined load hook.
79
- result = action.hooks[:load].(context)
80
-
81
- handle_result(result, formatted_fields, action)
82
- end
83
- end
84
-
85
- def change
86
- action = get_action(params[:collectionName])
87
-
88
- if !action
89
- render status: 500, json: {error: 'Error in smart action change hook: cannot retrieve action from collection'}
90
- else
91
- # Transform fields from array to an object to ease usage in hook.
92
- context = get_smart_action_change_ctx(params[:fields])
93
- formatted_fields = context[:fields].clone # clone for following test on is_same_data_structure
94
-
95
- # Call the user-defined change hook.
96
- result = action.hooks[:change][params[:changedField]].(context)
97
-
98
- handle_result(result, formatted_fields, action)
99
- end
100
- end
101
6
  end
102
7
  end
@@ -5,7 +5,7 @@ class ForestLiana::Model::Action
5
5
  extend ActiveModel::Naming
6
6
 
7
7
  attr_accessor :id, :name, :base_url, :endpoint, :http_method, :fields, :redirect,
8
- :type, :download, :hooks
8
+ :type, :download
9
9
 
10
10
  def initialize(attributes = {})
11
11
  if attributes.key?(:global)
@@ -66,7 +66,6 @@ class ForestLiana::Model::Action
66
66
  @base_url ||= nil
67
67
  @type ||= "bulk"
68
68
  @download ||= false
69
- @hooks = !@hooks.nil? ? @hooks.symbolize_keys : nil
70
69
  end
71
70
 
72
71
  def persisted?
@@ -39,7 +39,6 @@ module ForestLiana
39
39
  'redirect',
40
40
  'download',
41
41
  'fields',
42
- 'hooks',
43
42
  ]
44
43
  KEYS_ACTION_FIELD = [
45
44
  'field',
@@ -12,11 +12,11 @@ module ForestLiana
12
12
  @collection = get_collection(@collection_name)
13
13
  @fields_to_serialize = get_fields_to_serialize
14
14
  @field_names_requested = field_names_requested
15
- get_segment
16
- compute_includes
15
+ get_segment()
16
+ compute_includes()
17
17
  @search_query_builder = SearchQueryBuilder.new(@params, @includes, @collection)
18
18
 
19
- prepare_query
19
+ prepare_query()
20
20
  end
21
21
 
22
22
  def self.get_ids_from_request(params)
@@ -57,6 +57,4 @@ ForestLiana::Engine.routes.draw do
57
57
 
58
58
  # Smart Actions forms value
59
59
  post 'actions/:action_name/values' => 'actions#values'
60
- post 'actions/:action_name/hooks/load' => 'actions#load'
61
- post 'actions/:action_name/hooks/change' => 'actions#change'
62
60
  end
@@ -38,14 +38,6 @@ module ForestLiana
38
38
 
39
39
  private
40
40
 
41
- def get_collection(collection_name)
42
- ForestLiana.apimap.find { |collection| collection.name.to_s == collection_name }
43
- end
44
-
45
- def get_action(collection, action_name)
46
- collection.actions.find {|action| action.name == action_name}
47
- end
48
-
49
41
  def generate_apimap
50
42
  create_apimap
51
43
  require_lib_forest_liana
@@ -53,17 +45,6 @@ module ForestLiana
53
45
 
54
46
  if Rails.env.development?
55
47
  @collections_sent = ForestLiana.apimap.as_json
56
-
57
- @collections_sent.each do |collection|
58
- collection['actions'].each do |action|
59
- c = get_collection(collection['name'])
60
- a = get_action(c, action['name'])
61
- load = !a.hooks.nil? && a.hooks.key?(:load) && a.hooks[:load].is_a?(Proc)
62
- change = !a.hooks.nil? && a.hooks.key?(:change) && a.hooks[:change].is_a?(Hash) ? a.hooks[:change].keys : []
63
- action['hooks'] = {:load => load, :change => change}
64
- end
65
- end
66
-
67
48
  @meta_sent = ForestLiana.meta
68
49
  SchemaFileUpdater.new(SCHEMA_FILENAME, @collections_sent, @meta_sent).perform()
69
50
  else
@@ -50,7 +50,6 @@ module ForestLiana
50
50
  'redirect',
51
51
  'download',
52
52
  'fields',
53
- 'hooks',
54
53
  ]
55
54
  KEYS_ACTION_FIELD = [
56
55
  'field',
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "5.3.3"
2
+ VERSION = "6.0.0-beta.1"
3
3
  end
@@ -75,8 +75,7 @@ module ForestLiana
75
75
  type: 'File',
76
76
  field: 'File'
77
77
  }],
78
- http_method: nil,
79
- hooks: nil,
78
+ http_method: nil
80
79
  }
81
80
  }, {
82
81
  attributes: {
@@ -96,8 +95,7 @@ module ForestLiana
96
95
  download: nil,
97
96
  endpoint: nil,
98
97
  redirect: nil,
99
- 'http_method': nil,
100
- hooks: nil,
98
+ 'http_method': nil
101
99
  }
102
100
  }]
103
101
  }
@@ -150,8 +148,8 @@ module ForestLiana
150
148
  end
151
149
 
152
150
  it 'should sort the included actions and segments objects attributes values' do
153
- expect(apimap_sorted['included'][0]['attributes'].keys).to eq(['name', 'endpoint', 'http_method', 'redirect', 'download', 'hooks'])
154
- expect(apimap_sorted['included'][1]['attributes'].keys).to eq(['name', 'http_method', 'fields', 'hooks'])
151
+ expect(apimap_sorted['included'][0]['attributes'].keys).to eq(['name', 'endpoint', 'http_method', 'redirect', 'download'])
152
+ expect(apimap_sorted['included'][1]['attributes'].keys).to eq(['name', 'http_method', 'fields'])
155
153
  expect(apimap_sorted['included'][2]['attributes'].keys).to eq(['name'])
156
154
  expect(apimap_sorted['included'][3]['attributes'].keys).to eq(['name'])
157
155
  end
@@ -9,7 +9,7 @@ module ForestLiana
9
9
 
10
10
  expect(collection.fields.map { |field| field[:field] }).to eq(
11
11
  ["id", "name", "created_at", "updated_at", "trees"]
12
- )
12
+ );
13
13
  end
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.3
4
+ version: 6.0.0.pre.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-08 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -211,10 +211,8 @@ files:
211
211
  - app/helpers/forest_liana/adapter_helper.rb
212
212
  - app/helpers/forest_liana/application_helper.rb
213
213
  - app/helpers/forest_liana/decoration_helper.rb
214
- - app/helpers/forest_liana/is_same_data_structure_helper.rb
215
214
  - app/helpers/forest_liana/query_helper.rb
216
215
  - app/helpers/forest_liana/schema_helper.rb
217
- - app/helpers/forest_liana/widgets_helper.rb
218
216
  - app/models/forest_liana/model/action.rb
219
217
  - app/models/forest_liana/model/collection.rb
220
218
  - app/models/forest_liana/model/segment.rb
@@ -338,11 +336,9 @@ files:
338
336
  - spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb
339
337
  - spec/dummy/db/migrate/20190716135241_add_type_to_user.rb
340
338
  - spec/dummy/db/schema.rb
341
- - spec/helpers/forest_liana/is_same_data_structure_helper_spec.rb
342
339
  - spec/helpers/forest_liana/query_helper_spec.rb
343
340
  - spec/helpers/forest_liana/schema_helper_spec.rb
344
341
  - spec/rails_helper.rb
345
- - spec/requests/actions_controller_spec.rb
346
342
  - spec/requests/resources_spec.rb
347
343
  - spec/services/forest_liana/apimap_sorter_spec.rb
348
344
  - spec/services/forest_liana/filters_parser_spec.rb
@@ -455,9 +451,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
455
451
  version: '0'
456
452
  required_rubygems_version: !ruby/object:Gem::Requirement
457
453
  requirements:
458
- - - ">="
454
+ - - ">"
459
455
  - !ruby/object:Gem::Version
460
- version: '0'
456
+ version: 1.3.1
461
457
  requirements: []
462
458
  rubygems_version: 3.0.8
463
459
  signing_key:
@@ -560,7 +556,6 @@ test_files:
560
556
  - spec/services/forest_liana/apimap_sorter_spec.rb
561
557
  - spec/services/forest_liana/filters_parser_spec.rb
562
558
  - spec/spec_helper.rb
563
- - spec/requests/actions_controller_spec.rb
564
559
  - spec/requests/resources_spec.rb
565
560
  - spec/dummy/README.rdoc
566
561
  - spec/dummy/app/views/layouts/application.html.erb
@@ -603,6 +598,5 @@ test_files:
603
598
  - spec/dummy/config/initializers/backtrace_silencers.rb
604
599
  - spec/dummy/config/database.yml
605
600
  - spec/helpers/forest_liana/schema_helper_spec.rb
606
- - spec/helpers/forest_liana/is_same_data_structure_helper_spec.rb
607
601
  - spec/helpers/forest_liana/query_helper_spec.rb
608
602
  - spec/rails_helper.rb
@@ -1,44 +0,0 @@
1
- require 'set'
2
-
3
- module ForestLiana
4
- module IsSameDataStructureHelper
5
- class Analyser
6
- def initialize(object, other, deep = 0)
7
- @object = object
8
- @other = other
9
- @deep = deep
10
- end
11
-
12
- def are_objects(object, other)
13
- object && other && object.is_a?(Hash) && other.is_a?(Hash)
14
- end
15
-
16
- def check_keys(object, other, step = 0)
17
- unless are_objects(object, other)
18
- return false
19
- end
20
-
21
- object_keys = object.keys
22
- other_keys = other.keys
23
-
24
- if object_keys.length != other_keys.length
25
- return false
26
- end
27
-
28
- object_keys_set = object_keys.to_set
29
- other_keys.each { |key|
30
- if !object_keys_set.member?(key) || (step + 1 <= @deep && !check_keys(object[key], other[key], step + 1))
31
- return false
32
- end
33
- }
34
-
35
- return true
36
- end
37
-
38
- def perform
39
- check_keys(@object, @other)
40
- end
41
- end
42
- end
43
- end
44
-
@@ -1,59 +0,0 @@
1
- require 'set'
2
-
3
- module ForestLiana
4
- module WidgetsHelper
5
-
6
- @widget_edit_list = [
7
- 'address editor',
8
- 'belongsto typeahead',
9
- 'belongsto dropdown',
10
- 'boolean editor',
11
- 'checkboxes',
12
- 'color editor',
13
- 'date editor',
14
- 'dropdown',
15
- 'embedded document editor',
16
- 'file picker',
17
- 'json code editor',
18
- 'input array',
19
- 'multiple select',
20
- 'number input',
21
- 'point editor',
22
- 'price editor',
23
- 'radio button',
24
- 'rich text',
25
- 'text area editor',
26
- 'text editor',
27
- 'time input',
28
- ]
29
-
30
- @v1_to_v2_edit_widgets_mapping = {
31
- address: 'address editor',
32
- 'belongsto select': 'belongsto dropdown',
33
- 'color picker': 'color editor',
34
- 'date picker': 'date editor',
35
- price: 'price editor',
36
- 'JSON editor': 'json code editor',
37
- 'rich text editor': 'rich text',
38
- 'text area': 'text area editor',
39
- 'text input': 'text editor',
40
- }
41
-
42
- def self.set_field_widget(field)
43
-
44
- if field[:widget]
45
- if @v1_to_v2_edit_widgets_mapping[field[:widget].to_sym]
46
- field[:widgetEdit] = {name: @v1_to_v2_edit_widgets_mapping[field[:widget].to_sym], parameters: {}}
47
- elsif @widget_edit_list.include?(field[:widget])
48
- field[:widgetEdit] = {name: field[:widget], parameters: {}}
49
- end
50
- end
51
-
52
- if !field.key?(:widgetEdit)
53
- field[:widgetEdit] = nil
54
- end
55
-
56
- field.delete(:widget)
57
- end
58
- end
59
- end
@@ -1,87 +0,0 @@
1
- module ForestLiana
2
- context 'IsSameDataStructure class' do
3
- it 'should: be valid with simple data' do
4
- object = {:a => 'a', :b => 'b'}
5
- other = {:a => 'a', :b => 'b'}
6
- result = IsSameDataStructureHelper::Analyser.new(object, other).perform
7
- expect(result).to be true
8
- end
9
-
10
- it 'should: be invalid with simple data' do
11
- object = {:a => 'a', :b => 'b'}
12
- other = {:a => 'a', :c => 'c'}
13
- result = IsSameDataStructureHelper::Analyser.new(object, other).perform
14
- expect(result).to be false
15
- end
16
-
17
- it 'should: be invalid with not same hash' do
18
- object = {:a => 'a', :b => 'b'}
19
- other = {:a => 'a', :b => 'b', :c => 'c'}
20
- result = IsSameDataStructureHelper::Analyser.new(object, other).perform
21
- expect(result).to be false
22
- end
23
-
24
- it 'should: be invalid with nil' do
25
- object = nil
26
- other = {:a => 'a', :b => 'b', :c => 'c'}
27
- result = IsSameDataStructureHelper::Analyser.new(object, other).perform
28
- expect(result).to be false
29
- end
30
-
31
- it 'should: be invalid with not hash' do
32
- object = nil
33
- other = {:a => 'a', :b => 'b', :c => 'c'}
34
- result = IsSameDataStructureHelper::Analyser.new(object, other).perform
35
- expect(result).to be false
36
- end
37
-
38
- it 'should: be invalid with integer' do
39
- object = 1
40
- other = {:a => 'a', :b => 'b', :c => 'c'}
41
- result = IsSameDataStructureHelper::Analyser.new(object, other).perform
42
- expect(result).to be false
43
- end
44
-
45
- it 'should: be invalid with string' do
46
- object = 'a'
47
- other = {:a => 'a', :b => 'b', :c => 'c'}
48
- result = IsSameDataStructureHelper::Analyser.new(object, other).perform
49
- expect(result).to be false
50
- end
51
-
52
- it 'should: be valid with depth 1' do
53
- object = {:a => {:c => 'c'}, :b => {:d => 'd'}}
54
- other = {:a => {:c => 'c'}, :b => {:d => 'd'}}
55
- result = IsSameDataStructureHelper::Analyser.new(object, other, 1).perform
56
- expect(result).to be true
57
- end
58
-
59
- it 'should: be invalid with depth 1' do
60
- object = {:a => {:c => 'c'}, :b => {:d => 'd'}}
61
- other = {:a => {:c => 'c'}, :b => {:e => 'e'}}
62
- result = IsSameDataStructureHelper::Analyser.new(object, other, 1).perform
63
- expect(result).to be false
64
- end
65
-
66
- it 'should: be invalid with depth 1 and nil' do
67
- object = {:a => {:c => 'c'}, :b => {:d => 'd'}}
68
- other = {:a => {:c => 'c'}, :b => nil}
69
- result = IsSameDataStructureHelper::Analyser.new(object, other, 1).perform
70
- expect(result).to be false
71
- end
72
-
73
- it 'should: be invalid with depth 1 and integer' do
74
- object = {:a => {:c => 'c'}, :b => {:d => 'd'}}
75
- other = {:a => {:c => 'c'}, :b => 1}
76
- result = IsSameDataStructureHelper::Analyser.new(object, other, 1).perform
77
- expect(result).to be false
78
- end
79
-
80
- it 'should: be invalid with depth 1 and string' do
81
- object = {:a => {:c => 'c'}, :b => {:d => 'd'}}
82
- other = {:a => {:c => 'c'}, :b => 'b'}
83
- result = IsSameDataStructureHelper::Analyser.new(object, other, 1).perform
84
- expect(result).to be false
85
- end
86
- end
87
- end
@@ -1,174 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe 'Requesting Actions routes', :type => :request do
4
- before(:each) do
5
- allow(ForestLiana::IpWhitelist).to receive(:is_ip_whitelist_retrieved) { true }
6
- allow(ForestLiana::IpWhitelist).to receive(:is_ip_valid) { true }
7
- Island.create(name: 'Corsica')
8
- end
9
-
10
- after(:each) do
11
- Island.destroy_all
12
- end
13
-
14
- describe 'call /values' do
15
- it 'should respond 200' do
16
- post '/forest/actions/foo/values', {}
17
- expect(response.status).to eq(200)
18
- expect(response.body).to be {}
19
- end
20
- end
21
-
22
- describe 'hooks' do
23
- foo = {
24
- field: 'foo',
25
- type: 'String',
26
- default_value: nil,
27
- enums: nil,
28
- is_required: false,
29
- reference: nil,
30
- description: nil,
31
- widget: nil,
32
- }
33
- enum = {
34
- field: 'enum',
35
- type: 'Enum',
36
- enums: %w[a b c],
37
- }
38
-
39
- action_definition = {
40
- name: 'my_action',
41
- fields: [foo],
42
- hooks: {
43
- :load => -> (context) {
44
- context[:fields]
45
- },
46
- :change => {
47
- 'foo' => -> (context) {
48
- fields = context[:fields]
49
- fields['foo'][:value] = 'baz'
50
- return fields
51
- }
52
- }
53
- }
54
- }
55
- fail_action_definition = {
56
- name: 'fail_action',
57
- fields: [foo],
58
- hooks: {
59
- :load => -> (context) {
60
- 1
61
- },
62
- :change => {
63
- 'foo' => -> (context) {
64
- 1
65
- }
66
- }
67
- }
68
- }
69
- cheat_action_definition = {
70
- name: 'cheat_action',
71
- fields: [foo],
72
- hooks: {
73
- :load => -> (context) {
74
- context[:fields]['baz'] = foo.clone.update({field: 'baz'})
75
- context[:fields]
76
- },
77
- :change => {
78
- 'foo' => -> (context) {
79
- context[:fields]['baz'] = foo.clone.update({field: 'baz'})
80
- context[:fields]
81
- }
82
- }
83
- }
84
- }
85
- enums_action_definition = {
86
- name: 'enums_action',
87
- fields: [foo, enum],
88
- hooks: {
89
- :change => {
90
- 'foo' => -> (context) {
91
- fields = context[:fields]
92
- fields['enum'][:enums] = %w[c d e]
93
- return fields
94
- }
95
- }
96
- }
97
- }
98
- action = ForestLiana::Model::Action.new(action_definition)
99
- fail_action = ForestLiana::Model::Action.new(fail_action_definition)
100
- cheat_action = ForestLiana::Model::Action.new(cheat_action_definition)
101
- enums_action = ForestLiana::Model::Action.new(enums_action_definition)
102
- island = ForestLiana.apimap.find {|collection| collection.name.to_s == ForestLiana.name_for(Island)}
103
- island.actions = [action, fail_action, cheat_action, enums_action]
104
-
105
- describe 'call /load' do
106
- params = {recordIds: [1], collectionName: 'Island'}
107
-
108
- it 'should respond 200' do
109
- post '/forest/actions/my_action/hooks/load', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
110
- expect(response.status).to eq(200)
111
- expect(JSON.parse(response.body)).to eq({'fields' => [foo.merge({:value => nil}).stringify_keys]})
112
- end
113
-
114
- it 'should respond 500 with bad params' do
115
- post '/forest/actions/my_action/hooks/load', {}
116
- expect(response.status).to eq(500)
117
- end
118
-
119
- it 'should respond 500 with bad hook result type' do
120
- post '/forest/actions/fail_action/hooks/load', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
121
- expect(response.status).to eq(500)
122
- end
123
-
124
- it 'should respond 500 with bad hook result data structure' do
125
- post '/forest/actions/cheat_action/hooks/load', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
126
- expect(response.status).to eq(500)
127
- end
128
- end
129
-
130
- describe 'call /change' do
131
- updated_foo = foo.clone.merge({:previousValue => nil, :value => 'bar'})
132
- params = {recordIds: [1], fields: [updated_foo], collectionName: 'Island', changedField: 'foo'}
133
-
134
- it 'should respond 200' do
135
- post '/forest/actions/my_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
136
- expect(response.status).to eq(200)
137
- expected = updated_foo.clone.merge({:value => 'baz'})
138
- expected[:widgetEdit] = nil
139
- expected.delete(:widget)
140
- expect(JSON.parse(response.body)).to eq({'fields' => [expected.stringify_keys]})
141
- end
142
-
143
- it 'should respond 500 with bad params' do
144
- post '/forest/actions/my_action/hooks/change', {}
145
- expect(response.status).to eq(500)
146
- end
147
-
148
- it 'should respond 500 with bad hook result type' do
149
- post '/forest/actions/fail_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
150
- expect(response.status).to eq(500)
151
- end
152
-
153
- it 'should respond 500 with bad hook result data structure' do
154
- post '/forest/actions/cheat_action/hooks/change', JSON.dump(params), 'CONTENT_TYPE' => 'application/json'
155
- expect(response.status).to eq(500)
156
- end
157
-
158
- it 'should reset value when enums has changed' do
159
- updated_enum = enum.clone.merge({:previousValue => nil, :value => 'a'}) # set value to a
160
- p = {recordIds: [1], fields: [updated_foo, updated_enum], collectionName: 'Island', changedField: 'foo'}
161
- post '/forest/actions/enums_action/hooks/change', JSON.dump(p), 'CONTENT_TYPE' => 'application/json'
162
- expect(response.status).to eq(200)
163
-
164
- expected_enum = updated_enum.clone.merge({ :enums => %w[c d e], :value => nil, :widgetEdit => nil})
165
- expected_enum.delete(:widget)
166
- expected_foo = updated_foo.clone.merge({ :widgetEdit => nil})
167
- expected_foo.delete(:widget)
168
-
169
- expect(JSON.parse(response.body)).to eq({'fields' => [expected_foo.stringify_keys, expected_enum.stringify_keys]})
170
- end
171
-
172
- end
173
- end
174
- end