hq-graphql 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,173 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe ::HQ::GraphQL::InputObject do
4
-
5
- describe ".with_model" do
6
- let(:hq_input_object) do
7
- Class.new(described_class) do
8
- graphql_name "TestQuery"
9
- end
10
- end
11
-
12
- let(:organization_type) do
13
- Class.new do
14
- include ::HQ::GraphQL::Resource
15
-
16
- self.model_name = "Organization"
17
- end
18
- end
19
-
20
- before(:each) do
21
- organization_type
22
- end
23
-
24
- it "adds everything by default" do
25
- hq_input_object.class_eval do
26
- with_model "Advisor"
27
- end
28
-
29
- expect(hq_input_object.arguments.keys).to be_empty
30
- hq_input_object.graphql_definition
31
- expected = ["createdAt", "id", "name", "organizationId", "updatedAt"]
32
- expect(hq_input_object.arguments.keys).to contain_exactly(*expected)
33
- end
34
-
35
- describe ".remove_attributes" do
36
- it "removes an attribute" do
37
- hq_input_object.class_eval do
38
- remove_attributes :created_at, :id, :organization_id
39
- with_model "Advisor"
40
- end
41
-
42
- expect(hq_input_object.arguments.keys).to be_empty
43
- hq_input_object.graphql_definition
44
- expected = ["name", "updatedAt"]
45
- expect(hq_input_object.arguments.keys).to contain_exactly(*expected)
46
- end
47
-
48
- it "raises an error when trying to remove a column that doesn't exist" do
49
- hq_input_object.class_eval do
50
- remove_attributes :doesnt_exist
51
- with_model "Advisor"
52
- end
53
-
54
- expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
55
- end
56
-
57
- it "raises an error when not connected to a model" do
58
- hq_input_object.class_eval do
59
- remove_attributes :created_at
60
- end
61
-
62
- expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
63
- end
64
- end
65
-
66
- describe ".remove_associations" do
67
- it "removes an association" do
68
- hq_input_object.class_eval do
69
- remove_associations :organization
70
- with_model "Advisor"
71
- end
72
-
73
- expect(hq_input_object.arguments.keys).to be_empty
74
- hq_input_object.graphql_definition
75
- expected = ["createdAt", "id", "name", "organizationId", "updatedAt"]
76
- expect(hq_input_object.arguments.keys).to contain_exactly(*expected)
77
- end
78
-
79
- it "raises an error when trying to remove a column that doesn't exist" do
80
- hq_input_object.class_eval do
81
- remove_associations :doesnt_exist
82
- with_model "Advisor"
83
- end
84
-
85
- expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
86
- end
87
-
88
- it "raises an error when not connected to a model" do
89
- hq_input_object.class_eval do
90
- remove_associations :organization
91
- end
92
-
93
- expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
94
- end
95
- end
96
-
97
- context "with attributes and associations turned off" do
98
- it "doesn't have any arguments by default" do
99
- hq_input_object.graphql_definition
100
- expect(hq_input_object.arguments.keys).to be_empty
101
- end
102
-
103
- it "doesn't have any arguments when disabling model attrs/associations" do
104
- hq_input_object.class_eval do
105
- with_model "Advisor", attributes: false, associations: false
106
- end
107
- hq_input_object.graphql_definition
108
- expect(hq_input_object.arguments.keys).to be_empty
109
- end
110
-
111
- describe ".add_attributes" do
112
- it "adds attributes" do
113
- hq_input_object.class_eval do
114
- add_attributes :name
115
- with_model "Advisor", attributes: false, associations: false
116
- end
117
-
118
- expect(hq_input_object.arguments.keys).to be_empty
119
- hq_input_object.graphql_definition
120
- expect(hq_input_object.arguments.keys).to contain_exactly("name")
121
- end
122
-
123
- it "raises an error when adding an attribute that doesn't exist" do
124
- hq_input_object.class_eval do
125
- add_attributes :doesnt_exist
126
- with_model "Advisor", attributes: false, associations: false
127
- end
128
-
129
- expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
130
- end
131
-
132
- it "raises an error when not connected to a model" do
133
- hq_input_object.class_eval do
134
- add_attributes :name
135
- end
136
-
137
- expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
138
- end
139
- end
140
-
141
- describe ".add_associations" do
142
- it "adds associations" do
143
- hq_input_object.class_eval do
144
- add_associations :organization
145
- with_model "Advisor", attributes: false, associations: false
146
- end
147
-
148
- expect(hq_input_object.arguments.keys).to be_empty
149
- hq_input_object.graphql_definition
150
- expect(hq_input_object.arguments.keys).to contain_exactly("organization")
151
- end
152
-
153
- it "raises an error when adding an association that doesn't exist" do
154
- hq_input_object.class_eval do
155
- add_associations :doesnt_exist
156
- with_model "Advisor", attributes: false, associations: false
157
- end
158
-
159
- expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
160
- end
161
-
162
- it "raises an error when not connected to a model" do
163
- hq_input_object.class_eval do
164
- add_associations :organization
165
- end
166
-
167
- expect { hq_input_object.graphql_definition }.to raise_error(described_class::Error)
168
- end
169
- end
170
- end
171
- end
172
-
173
- end
@@ -1,40 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe ::HQ::GraphQL::Inputs do
4
-
5
- describe ".[]" do
6
- let(:graphql_klass) do
7
- Class.new do
8
- include ::HQ::GraphQL::Resource
9
-
10
- self.model_name = "Advisor"
11
-
12
- input(attributes: false, associations: false) do
13
- argument :customField, String, "Header for the post", required: true
14
- end
15
- end
16
- end
17
-
18
- it "finds the type" do
19
- input_object = graphql_klass.input_klass
20
-
21
- aggregate_failures do
22
- expect(input_object.superclass).to eql(::HQ::GraphQL::InputObject)
23
- expect(input_object).to eql(described_class[Advisor])
24
- expect(input_object.arguments.keys).to contain_exactly("customField")
25
- input_object.to_graphql
26
- expect(input_object.arguments.keys).to contain_exactly("customField")
27
- end
28
- end
29
-
30
- it "finds the type when lookup is a string" do
31
- input_object = graphql_klass.input_klass
32
- expect(input_object).to eql(described_class["Advisor"])
33
- end
34
-
35
- it "raises an exception for unknown types" do
36
- expect { described_class[Advisor] }.to raise_error(described_class::Error)
37
- end
38
- end
39
-
40
- end
@@ -1,173 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe ::HQ::GraphQL::Object do
4
-
5
- describe ".with_model" do
6
- let(:hq_object) do
7
- Class.new(described_class) do
8
- graphql_name "TestQuery"
9
- end
10
- end
11
-
12
- let(:organization_type) do
13
- Class.new do
14
- include ::HQ::GraphQL::Resource
15
-
16
- self.model_name = "Organization"
17
- end
18
- end
19
-
20
- before(:each) do
21
- organization_type
22
- end
23
-
24
- it "adds everything by default" do
25
- hq_object.class_eval do
26
- with_model "Advisor"
27
- end
28
-
29
- expect(hq_object.fields.keys).to be_empty
30
- hq_object.graphql_definition
31
- expected = ["createdAt", "id", "name", "organization", "organizationId", "updatedAt"]
32
- expect(hq_object.fields.keys).to contain_exactly(*expected)
33
- end
34
-
35
- describe ".remove_attributes" do
36
- it "removes an attribute" do
37
- hq_object.class_eval do
38
- remove_attributes :created_at, :id, :organization_id
39
- with_model "Advisor"
40
- end
41
-
42
- expect(hq_object.fields.keys).to be_empty
43
- hq_object.graphql_definition
44
- expected = ["name", "organization", "updatedAt"]
45
- expect(hq_object.fields.keys).to contain_exactly(*expected)
46
- end
47
-
48
- it "raises an error when trying to remove a column that doesn't exist" do
49
- hq_object.class_eval do
50
- remove_attributes :doesnt_exist
51
- with_model "Advisor"
52
- end
53
-
54
- expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
55
- end
56
-
57
- it "raises an error when not connected to a model" do
58
- hq_object.class_eval do
59
- remove_attributes :created_at
60
- end
61
-
62
- expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
63
- end
64
- end
65
-
66
- describe ".remove_associations" do
67
- it "removes an association" do
68
- hq_object.class_eval do
69
- remove_associations :organization
70
- with_model "Advisor"
71
- end
72
-
73
- expect(hq_object.fields.keys).to be_empty
74
- hq_object.graphql_definition
75
- expected = ["createdAt", "id", "name", "organizationId", "updatedAt"]
76
- expect(hq_object.fields.keys).to contain_exactly(*expected)
77
- end
78
-
79
- it "raises an error when trying to remove a column that doesn't exist" do
80
- hq_object.class_eval do
81
- remove_associations :doesnt_exist
82
- with_model "Advisor"
83
- end
84
-
85
- expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
86
- end
87
-
88
- it "raises an error when not connected to a model" do
89
- hq_object.class_eval do
90
- remove_associations :organization
91
- end
92
-
93
- expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
94
- end
95
- end
96
-
97
- context "with attributes and associations turned off" do
98
- it "doesn't have any fields by default" do
99
- hq_object.graphql_definition
100
- expect(hq_object.fields.keys).to be_empty
101
- end
102
-
103
- it "doesn't have any fields when disabling model attrs/associations" do
104
- hq_object.class_eval do
105
- with_model "Advisor", attributes: false, associations: false
106
- end
107
- hq_object.graphql_definition
108
- expect(hq_object.fields.keys).to be_empty
109
- end
110
-
111
- describe ".add_attributes" do
112
- it "adds attributes" do
113
- hq_object.class_eval do
114
- add_attributes :name
115
- with_model "Advisor", attributes: false, associations: false
116
- end
117
-
118
- expect(hq_object.fields.keys).to be_empty
119
- hq_object.graphql_definition
120
- expect(hq_object.fields.keys).to contain_exactly("name")
121
- end
122
-
123
- it "raises an error when adding an attribute that doesn't exist" do
124
- hq_object.class_eval do
125
- add_attributes :doesnt_exist
126
- with_model "Advisor", attributes: false, associations: false
127
- end
128
-
129
- expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
130
- end
131
-
132
- it "raises an error when not connected to a model" do
133
- hq_object.class_eval do
134
- add_attributes :name
135
- end
136
-
137
- expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
138
- end
139
- end
140
-
141
- describe ".add_associations" do
142
- it "adds associations" do
143
- hq_object.class_eval do
144
- add_associations :organization
145
- with_model "Advisor", attributes: false, associations: false
146
- end
147
-
148
- expect(hq_object.fields.keys).to be_empty
149
- hq_object.graphql_definition
150
- expect(hq_object.fields.keys).to contain_exactly("organization")
151
- end
152
-
153
- it "raises an error when adding an association that doesn't exist" do
154
- hq_object.class_eval do
155
- add_associations :doesnt_exist
156
- with_model "Advisor", attributes: false, associations: false
157
- end
158
-
159
- expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
160
- end
161
-
162
- it "raises an error when not connected to a model" do
163
- hq_object.class_eval do
164
- add_associations :organization
165
- end
166
-
167
- expect { hq_object.graphql_definition }.to raise_error(described_class::Error)
168
- end
169
- end
170
- end
171
- end
172
-
173
- end