Skip to content

Commit 92a0da4

Browse files
fix(apimap): fix generate schema with unknown action (#555)
1 parent cef86bb commit 92a0da4

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

lib/forest_liana/bootstrapper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def generate_action_hooks()
5959
c = get_collection(collection['name'])
6060
unless c.nil?
6161
a = get_action(c, action['name'])
62-
load = !a.hooks.nil? && a.hooks.key?(:load) && a.hooks[:load].is_a?(Proc)
63-
change = !a.hooks.nil? && a.hooks.key?(:change) && a.hooks[:change].is_a?(Hash) ? a.hooks[:change].keys : []
62+
load = !a.nil? && !a.hooks.nil? && a.hooks.key?(:load) && a.hooks[:load].is_a?(Proc)
63+
change = !a.nil? && !a.hooks.nil? && a.hooks.key?(:change) && a.hooks[:change].is_a?(Hash) ? a.hooks[:change].keys : []
6464
action['hooks'] = {'load' => load, 'change' => change}
6565
end
6666
end

spec/lib/forest_liana/bootstrapper_spec.rb

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,109 @@ module ForestLiana
88
.to include(:database_type)
99
end
1010
end
11+
12+
describe 'generate_action_hooks' do
13+
schema = '{
14+
"collections": [
15+
{
16+
"name": "Island",
17+
"name_old": "Island",
18+
"icon": null,
19+
"is_read_only": false,
20+
"is_searchable": true,
21+
"is_virtual": false,
22+
"only_for_relationships": false,
23+
"pagination_type": "page",
24+
"fields": [
25+
{
26+
"field": "id",
27+
"type": "Number",
28+
"default_value": null,
29+
"enums": null,
30+
"integration": null,
31+
"is_filterable": true,
32+
"is_read_only": false,
33+
"is_required": false,
34+
"is_sortable": true,
35+
"is_virtual": false,
36+
"reference": null,
37+
"inverse_of": null,
38+
"widget": null,
39+
"validations": []
40+
},
41+
{
42+
"field": "first_name",
43+
"type": "String",
44+
"default_value": null,
45+
"enums": null,
46+
"integration": null,
47+
"is_filterable": true,
48+
"is_read_only": false,
49+
"is_required": false,
50+
"is_sortable": true,
51+
"is_virtual": false,
52+
"reference": null,
53+
"inverse_of": null,
54+
"widget": null,
55+
"validations": []
56+
},
57+
{
58+
"field": "last_name",
59+
"type": "String",
60+
"default_value": null,
61+
"enums": null,
62+
"integration": null,
63+
"is_filterable": true,
64+
"is_read_only": false,
65+
"is_required": false,
66+
"is_sortable": true,
67+
"is_virtual": false,
68+
"reference": null,
69+
"inverse_of": null,
70+
"widget": null,
71+
"validations": []
72+
}
73+
],
74+
"segments": [],
75+
"actions": [
76+
{
77+
"name": "foo",
78+
"type": "bulk",
79+
"base_url": null,
80+
"endpoint": "forest/actions/mark-as-live",
81+
"http_method": "POST",
82+
"redirect": null,
83+
"download": false,
84+
"fields": [],
85+
"hooks": {
86+
"load": false,
87+
"change": []
88+
}
89+
}
90+
]
91+
}
92+
],
93+
"meta": {
94+
"liana": "forest-rails",
95+
"liana_version": "7.6.0",
96+
"stack": {
97+
"database_type": "postgresql",
98+
"orm_version": "7.0.2.4"
99+
}
100+
}
101+
}'
102+
103+
104+
it "Should return actions hooks empty for the island collection" do
105+
allow(ForestLiana).to receive(:env_secret).and_return(nil)
106+
bootstrapper = Bootstrapper.new
107+
content = JSON.parse(schema)
108+
bootstrapper.instance_variable_set(:@collections_sent, content['collections'])
109+
bootstrapper.instance_variable_set(:@meta_sent, content['meta'])
110+
bootstrapper.send(:generate_action_hooks)
111+
112+
expect(bootstrapper.instance_variable_get("@collections_sent").first['actions'].first['hooks']).to eq({"load"=>false, "change"=>[]})
113+
end
114+
end
11115
end
12116
end

0 commit comments

Comments
 (0)