contentstack 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +68 -68
- data/.github/workflows/jira.yml +28 -0
- data/.github/workflows/release-gem.yml +31 -0
- data/.github/workflows/sast-scan.yml +10 -10
- data/.github/workflows/sca-scan.yml +15 -13
- data/.github/workflows/secrets-scan.yml +10 -10
- data/.gitignore +11 -11
- data/.yardopts +6 -6
- data/CHANGELOG.md +108 -78
- data/CODEOWNERS +1 -1
- data/CODE_OF_CONDUCT.md +73 -73
- data/Gemfile +2 -2
- data/Gemfile.lock +28 -23
- data/LICENSE.txt +21 -21
- data/README.md +197 -197
- data/SECURITY.md +27 -27
- data/contentstack.gemspec +29 -29
- data/lib/contentstack/api.rb +191 -188
- data/lib/contentstack/asset.rb +68 -68
- data/lib/contentstack/asset_collection.rb +27 -27
- data/lib/contentstack/client.rb +91 -91
- data/lib/contentstack/content_type.rb +53 -53
- data/lib/contentstack/entry.rb +221 -221
- data/lib/contentstack/entry_collection.rb +44 -44
- data/lib/contentstack/error.rb +6 -6
- data/lib/contentstack/query.rb +653 -653
- data/lib/contentstack/region.rb +5 -5
- data/lib/contentstack/sync_result.rb +29 -29
- data/lib/contentstack/version.rb +2 -2
- data/lib/contentstack.rb +31 -31
- data/lib/util.rb +110 -110
- data/rakefile.rb +3 -3
- data/spec/asset_collection_spec.rb +15 -15
- data/spec/asset_spec.rb +47 -47
- data/spec/content_type_spec.rb +80 -80
- data/spec/contentstack_spec.rb +38 -38
- data/spec/entry_collection_spec.rb +41 -41
- data/spec/entry_spec.rb +101 -101
- data/spec/fixtures/asset.json +1 -1
- data/spec/fixtures/asset_collection.json +1 -1
- data/spec/fixtures/category_content_type.json +1 -1
- data/spec/fixtures/category_entry.json +1 -1
- data/spec/fixtures/category_entry_collection.json +1 -1
- data/spec/fixtures/category_entry_collection_without_count.json +1 -1
- data/spec/fixtures/content_types.json +1 -1
- data/spec/fixtures/product_entry.json +1 -1
- data/spec/fixtures/product_entry_collection.json +1 -1
- data/spec/fixtures/sync_init.json +2974 -2974
- data/spec/query_spec.rb +205 -205
- data/spec/spec_helper.rb +180 -180
- data/spec/sync_spec.rb +26 -26
- metadata +9 -7
data/spec/query_spec.rb
CHANGED
@@ -1,206 +1,206 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative '../lib/contentstack.rb'
|
3
|
-
|
4
|
-
describe Contentstack::Query do
|
5
|
-
let(:client) { create_client }
|
6
|
-
let(:preview_client) { create_preview_client }
|
7
|
-
let(:category_query) {client.content_type("category").query}
|
8
|
-
let(:preview_category) {preview_client.content_type("category").query}
|
9
|
-
let(:product_query) {client.content_type("product").query}
|
10
|
-
|
11
|
-
it "should get data using `where` method" do
|
12
|
-
data = category_query.where({title: "Electronics"}).fetch
|
13
|
-
expect(data.length).to eq 5
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should get data using `regex` method" do
|
17
|
-
data = category_query.regex("title", "App.*").fetch
|
18
|
-
expect(data.length).to eq 5
|
19
|
-
end
|
20
|
-
|
21
|
-
it "is preview entry featch" do
|
22
|
-
preview_client.live_preview_query({hash: 'hash', content_type_uid: 'category'})
|
23
|
-
data = preview_category.fetch
|
24
|
-
expect(data.length).to eq 5
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should get data using `less_than` method" do
|
28
|
-
data = product_query.less_than("price", 150).fetch
|
29
|
-
expect(data.length).to eq 3
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should get data using `less_than_or_equal` method" do
|
33
|
-
data = product_query.less_than_or_equal("price", 166).fetch
|
34
|
-
expect(data.length).to eq 3
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should get data using `greater_than` method" do
|
38
|
-
data = product_query.greater_than("price", 120).fetch
|
39
|
-
expect(data.length).to eq 3
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should get data using `greater_than_or_equal` method" do
|
43
|
-
data = product_query.greater_than_or_equal("price", 166).fetch
|
44
|
-
expect(data.length).to eq 3
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should get data using `not_equal_to` method" do
|
48
|
-
data = product_query.not_equal_to("price", 166).fetch
|
49
|
-
expect(data.length).to eq 3
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should get data using `limit` method" do
|
53
|
-
data = category_query.limit(2).fetch
|
54
|
-
expect(data.length).to eq 5
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should get data using `skip` method" do
|
58
|
-
data = category_query.skip(5).fetch
|
59
|
-
expect(data.length).to eq 5
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should get data using `include_count` method" do
|
63
|
-
data = category_query.include_count.fetch
|
64
|
-
expect(data.count).not_to be nil
|
65
|
-
expect(data.count).to eq 5
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should get data using `only` method with string parameter" do
|
69
|
-
data = category_query.only("title").fetch
|
70
|
-
expect(data.first.fields[:title]).not_to be nil
|
71
|
-
expect(data.first.fields[:uid]).not_to be nil
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should get data using `only` method with array parameter" do
|
75
|
-
data = category_query.only(["title"]).fetch
|
76
|
-
expect(data.first.fields[:title]).not_to be nil
|
77
|
-
expect(data.first.fields[:uid]).not_to be nil
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should get data using `except` method with string parameter" do
|
81
|
-
data = category_query.except("category_tags").fetch
|
82
|
-
expect(data.first.fields[:category_tags]).to be nil
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should get data using `except` method with array parameter" do
|
86
|
-
data = category_query.except(["description"]).fetch
|
87
|
-
expect(data.first.fields[:description]).to be nil
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should get data using `tags` method" do
|
91
|
-
data = category_query.tags(["tag1"]).fetch
|
92
|
-
expect(data.length).to eq 5
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should get data using `contained_in` method" do
|
96
|
-
data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
|
97
|
-
expect(data.length).to eq 5
|
98
|
-
expect(data.first.fields[:title]).to eq "Home & Appliances"
|
99
|
-
expect(data.last.fields[:title]).to eq "Headphones"
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should get data using `not_contained_in` method" do
|
103
|
-
data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
|
104
|
-
expect(data.length).to eq 5
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should get data using `in` method" do
|
108
|
-
data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
|
109
|
-
expect(data.length).to eq 5
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should get data using `not_in` method" do
|
113
|
-
data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
|
114
|
-
expect(data.length).to eq 5
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should get data using `ascending` method" do
|
118
|
-
data = product_query.ascending("price").fetch
|
119
|
-
expect(data.first.fields[:title]).to eq "Motorola Moto X4"
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should get data using `descending` method" do
|
123
|
-
data = product_query.descending("price").fetch
|
124
|
-
expect(data.first.fields[:title]).to eq "Motorola Moto X4"
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should get data using `only` method for reference fields" do
|
128
|
-
data = product_query.include_reference('categories').only("categories", ["title", "description"]).fetch
|
129
|
-
expect(data.first.fields[:categories][0][:title]).to eq "Smartphones"
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should get data using `except` method for reference fields" do
|
133
|
-
data = product_query.include_reference('categories').except("categories", "title").fetch
|
134
|
-
expect(data.first.fields[:categories][0][:title]).to eq 'Smartphones'
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should get data using `include_schema` method" do
|
138
|
-
data = category_query.include_schema.fetch
|
139
|
-
expect(data.schema).not_to be nil
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should get data using `include_content_type` method" do
|
143
|
-
data = category_query.include_content_type.fetch
|
144
|
-
expect(data.content_type).not_to be nil
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should get data using `include_reference` method" do
|
148
|
-
data = product_query.include_reference('categories').fetch
|
149
|
-
puts data.first.get("categories.title")
|
150
|
-
expect(data.first.fields[:categories][0][:title]).not_to be nil
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should get data using `include_owner` method" do
|
154
|
-
data = product_query.include_owner.fetch
|
155
|
-
expect(data.first.fields[:_owner]).not_to be nil
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should get data using `include_owner` method" do
|
159
|
-
data = product_query.include_fallback.fetch
|
160
|
-
expect(data.first.fields[:locale]).not_to be nil
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should get data using `include_draft` method" do
|
164
|
-
data = category_query.include_draft.fetch
|
165
|
-
expect(data.length).to eq 5
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should get data using `search` method" do
|
169
|
-
data = category_query.search("App").fetch
|
170
|
-
expect(data.length).to eq 5
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should get data using `count` method" do
|
174
|
-
data = category_query.count
|
175
|
-
expect(data).to eq 5
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should get data using `exists` method" do
|
179
|
-
data = category_query.exists?('description').fetch
|
180
|
-
expect(data.length).to eq 5
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should get data using `not_exists` method" do
|
184
|
-
data = product_query.not_exists?('banner_image').fetch
|
185
|
-
expect(data.length).to eq 3
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should get data using `and` method" do
|
189
|
-
q1 = client.content_type("category").query.regex("title", "App.*")
|
190
|
-
q2 = client.content_type("category").query.where({"description"=>"Appliances Category"})
|
191
|
-
data = category_query.and([q1,q2]).fetch
|
192
|
-
expect(data.length).to eq 5
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should get data using `or` method" do
|
196
|
-
q1 = client.content_type("category").query.regex("title", "App.*")
|
197
|
-
q2 = client.content_type("category").query.regex("description", "App*")
|
198
|
-
data = category_query.or([q1,q2]).fetch
|
199
|
-
expect(data.length).to eq 5
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should set locale the in the request query" do
|
203
|
-
data = product_query.locale('en-us')
|
204
|
-
expect(data.query[:locale]).to eq 'en-us'
|
205
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
|
4
|
+
describe Contentstack::Query do
|
5
|
+
let(:client) { create_client }
|
6
|
+
let(:preview_client) { create_preview_client }
|
7
|
+
let(:category_query) {client.content_type("category").query}
|
8
|
+
let(:preview_category) {preview_client.content_type("category").query}
|
9
|
+
let(:product_query) {client.content_type("product").query}
|
10
|
+
|
11
|
+
it "should get data using `where` method" do
|
12
|
+
data = category_query.where({title: "Electronics"}).fetch
|
13
|
+
expect(data.length).to eq 5
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should get data using `regex` method" do
|
17
|
+
data = category_query.regex("title", "App.*").fetch
|
18
|
+
expect(data.length).to eq 5
|
19
|
+
end
|
20
|
+
|
21
|
+
it "is preview entry featch" do
|
22
|
+
preview_client.live_preview_query({hash: 'hash', content_type_uid: 'category'})
|
23
|
+
data = preview_category.fetch
|
24
|
+
expect(data.length).to eq 5
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should get data using `less_than` method" do
|
28
|
+
data = product_query.less_than("price", 150).fetch
|
29
|
+
expect(data.length).to eq 3
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should get data using `less_than_or_equal` method" do
|
33
|
+
data = product_query.less_than_or_equal("price", 166).fetch
|
34
|
+
expect(data.length).to eq 3
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should get data using `greater_than` method" do
|
38
|
+
data = product_query.greater_than("price", 120).fetch
|
39
|
+
expect(data.length).to eq 3
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should get data using `greater_than_or_equal` method" do
|
43
|
+
data = product_query.greater_than_or_equal("price", 166).fetch
|
44
|
+
expect(data.length).to eq 3
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should get data using `not_equal_to` method" do
|
48
|
+
data = product_query.not_equal_to("price", 166).fetch
|
49
|
+
expect(data.length).to eq 3
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should get data using `limit` method" do
|
53
|
+
data = category_query.limit(2).fetch
|
54
|
+
expect(data.length).to eq 5
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should get data using `skip` method" do
|
58
|
+
data = category_query.skip(5).fetch
|
59
|
+
expect(data.length).to eq 5
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should get data using `include_count` method" do
|
63
|
+
data = category_query.include_count.fetch
|
64
|
+
expect(data.count).not_to be nil
|
65
|
+
expect(data.count).to eq 5
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should get data using `only` method with string parameter" do
|
69
|
+
data = category_query.only("title").fetch
|
70
|
+
expect(data.first.fields[:title]).not_to be nil
|
71
|
+
expect(data.first.fields[:uid]).not_to be nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should get data using `only` method with array parameter" do
|
75
|
+
data = category_query.only(["title"]).fetch
|
76
|
+
expect(data.first.fields[:title]).not_to be nil
|
77
|
+
expect(data.first.fields[:uid]).not_to be nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should get data using `except` method with string parameter" do
|
81
|
+
data = category_query.except("category_tags").fetch
|
82
|
+
expect(data.first.fields[:category_tags]).to be nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should get data using `except` method with array parameter" do
|
86
|
+
data = category_query.except(["description"]).fetch
|
87
|
+
expect(data.first.fields[:description]).to be nil
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should get data using `tags` method" do
|
91
|
+
data = category_query.tags(["tag1"]).fetch
|
92
|
+
expect(data.length).to eq 5
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should get data using `contained_in` method" do
|
96
|
+
data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
|
97
|
+
expect(data.length).to eq 5
|
98
|
+
expect(data.first.fields[:title]).to eq "Home & Appliances"
|
99
|
+
expect(data.last.fields[:title]).to eq "Headphones"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should get data using `not_contained_in` method" do
|
103
|
+
data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
|
104
|
+
expect(data.length).to eq 5
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should get data using `in` method" do
|
108
|
+
data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
|
109
|
+
expect(data.length).to eq 5
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should get data using `not_in` method" do
|
113
|
+
data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
|
114
|
+
expect(data.length).to eq 5
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should get data using `ascending` method" do
|
118
|
+
data = product_query.ascending("price").fetch
|
119
|
+
expect(data.first.fields[:title]).to eq "Motorola Moto X4"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should get data using `descending` method" do
|
123
|
+
data = product_query.descending("price").fetch
|
124
|
+
expect(data.first.fields[:title]).to eq "Motorola Moto X4"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should get data using `only` method for reference fields" do
|
128
|
+
data = product_query.include_reference('categories').only("categories", ["title", "description"]).fetch
|
129
|
+
expect(data.first.fields[:categories][0][:title]).to eq "Smartphones"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should get data using `except` method for reference fields" do
|
133
|
+
data = product_query.include_reference('categories').except("categories", "title").fetch
|
134
|
+
expect(data.first.fields[:categories][0][:title]).to eq 'Smartphones'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should get data using `include_schema` method" do
|
138
|
+
data = category_query.include_schema.fetch
|
139
|
+
expect(data.schema).not_to be nil
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should get data using `include_content_type` method" do
|
143
|
+
data = category_query.include_content_type.fetch
|
144
|
+
expect(data.content_type).not_to be nil
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should get data using `include_reference` method" do
|
148
|
+
data = product_query.include_reference('categories').fetch
|
149
|
+
puts data.first.get("categories.title")
|
150
|
+
expect(data.first.fields[:categories][0][:title]).not_to be nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should get data using `include_owner` method" do
|
154
|
+
data = product_query.include_owner.fetch
|
155
|
+
expect(data.first.fields[:_owner]).not_to be nil
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should get data using `include_owner` method" do
|
159
|
+
data = product_query.include_fallback.fetch
|
160
|
+
expect(data.first.fields[:locale]).not_to be nil
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should get data using `include_draft` method" do
|
164
|
+
data = category_query.include_draft.fetch
|
165
|
+
expect(data.length).to eq 5
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should get data using `search` method" do
|
169
|
+
data = category_query.search("App").fetch
|
170
|
+
expect(data.length).to eq 5
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should get data using `count` method" do
|
174
|
+
data = category_query.count
|
175
|
+
expect(data).to eq 5
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should get data using `exists` method" do
|
179
|
+
data = category_query.exists?('description').fetch
|
180
|
+
expect(data.length).to eq 5
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should get data using `not_exists` method" do
|
184
|
+
data = product_query.not_exists?('banner_image').fetch
|
185
|
+
expect(data.length).to eq 3
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should get data using `and` method" do
|
189
|
+
q1 = client.content_type("category").query.regex("title", "App.*")
|
190
|
+
q2 = client.content_type("category").query.where({"description"=>"Appliances Category"})
|
191
|
+
data = category_query.and([q1,q2]).fetch
|
192
|
+
expect(data.length).to eq 5
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should get data using `or` method" do
|
196
|
+
q1 = client.content_type("category").query.regex("title", "App.*")
|
197
|
+
q2 = client.content_type("category").query.regex("description", "App*")
|
198
|
+
data = category_query.or([q1,q2]).fetch
|
199
|
+
expect(data.length).to eq 5
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should set locale the in the request query" do
|
203
|
+
data = product_query.locale('en-us')
|
204
|
+
expect(data.query[:locale]).to eq 'en-us'
|
205
|
+
end
|
206
206
|
end
|