contentstack 0.6.3.1 → 0.8.0

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