swiftype 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/README.md +95 -22
- data/lib/swiftype/client.rb +53 -1
- data/lib/swiftype/request.rb +24 -0
- data/lib/swiftype/version.rb +1 -1
- data/spec/client_spec.rb +181 -91
- data/spec/configuration_spec.rb +9 -8
- data/spec/deprecated_spec.rb +3 -3
- data/spec/fixtures/vcr/async_create_or_update_document_failure.yml +48 -0
- data/spec/fixtures/vcr/async_create_or_update_document_success.yml +51 -0
- data/spec/fixtures/vcr/document_receipts_multiple.yml +48 -0
- data/spec/fixtures/vcr/document_receipts_multiple_complete.yml +48 -0
- data/spec/platform_spec.rb +6 -6
- data/spec/sso_spec.rb +3 -3
- data/swiftype.gemspec +2 -2
- metadata +28 -19
data/spec/client_spec.rb
CHANGED
@@ -13,27 +13,27 @@ describe Swiftype::Client do
|
|
13
13
|
it 'searches all DocumentTypes in the engine' do
|
14
14
|
VCR.use_cassette(:engine_search) do
|
15
15
|
results = client.search(engine_slug, 'cat')
|
16
|
-
results.document_types.size.
|
17
|
-
results['videos'].size.
|
18
|
-
results['channels'].size.
|
16
|
+
expect(results.document_types.size).to eq(2)
|
17
|
+
expect(results['videos'].size).to eq(2)
|
18
|
+
expect(results['channels'].size).to eq(1)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'searches the engine with options' do
|
23
23
|
VCR.use_cassette(:engine_search_pagination) do
|
24
24
|
results = client.search(engine_slug, 'cat', {:page => 2})
|
25
|
-
results.document_types.size.
|
26
|
-
results['videos'].size.
|
27
|
-
results['channels'].size.
|
25
|
+
expect(results.document_types.size).to eq(2)
|
26
|
+
expect(results['videos'].size).to eq(0)
|
27
|
+
expect(results['channels'].size).to eq(0)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'includes facets when requested' do
|
32
32
|
VCR.use_cassette(:engine_search_facets) do
|
33
33
|
results = client.search(engine_slug, nil, {:facets => {:videos => ['category_id']}})
|
34
|
-
results.document_types.size.
|
35
|
-
results.facets('channels').
|
36
|
-
results.facets('videos')['category_id'].
|
34
|
+
expect(results.document_types.size).to eq(2)
|
35
|
+
expect(results.facets('channels')).to be_empty
|
36
|
+
expect(results.facets('videos')['category_id']).to eq({
|
37
37
|
"23" => 4,
|
38
38
|
"28" => 2,
|
39
39
|
"15" => 2,
|
@@ -41,7 +41,7 @@ describe Swiftype::Client do
|
|
41
41
|
"22" => 1,
|
42
42
|
"2" => 1,
|
43
43
|
"10" => 1
|
44
|
-
}
|
44
|
+
})
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -52,38 +52,49 @@ describe Swiftype::Client do
|
|
52
52
|
it 'searches only the provided DocumentType' do
|
53
53
|
VCR.use_cassette(:document_type_search) do
|
54
54
|
results = client.search_document_type(engine_slug, document_type_slug, 'cat')
|
55
|
-
results.document_types.
|
56
|
-
results['videos'].size.
|
55
|
+
expect(results.document_types).to eq(['videos'])
|
56
|
+
expect(results['videos'].size).to eq(2)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'searches the DocumentType with options' do
|
61
61
|
VCR.use_cassette(:document_type_search_pagination) do
|
62
62
|
results = client.search_document_type(engine_slug, document_type_slug, 'cat', {:page => 2})
|
63
|
-
results.document_types.
|
64
|
-
results[document_type_slug].size.
|
63
|
+
expect(results.document_types).to eq(['videos'])
|
64
|
+
expect(results[document_type_slug].size).to eq(0)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
context 'Options' do
|
71
|
+
let(:options_client) { Swiftype::Client.new(options) }
|
72
|
+
|
73
|
+
context '#request' do
|
74
|
+
let(:options) { { :open_timeout => 3 } }
|
75
|
+
it 'respects the Net::HTTP open_timeout option' do
|
76
|
+
expect(options_client.open_timeout).to eq(3)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
70
81
|
context 'Suggest' do
|
71
82
|
context '#suggest' do
|
72
83
|
it 'does prefix searches for all DocumentTypes in the engine' do
|
73
84
|
VCR.use_cassette(:engine_suggest) do
|
74
85
|
results = client.suggest(engine_slug, 'goo')
|
75
|
-
results.document_types.size.
|
76
|
-
results['videos'].size.
|
77
|
-
results['channels'].size.
|
86
|
+
expect(results.document_types.size).to eq(2)
|
87
|
+
expect(results['videos'].size).to eq(1)
|
88
|
+
expect(results['channels'].size).to eq(1)
|
78
89
|
end
|
79
90
|
end
|
80
91
|
|
81
92
|
it 'suggests for an engine with options' do
|
82
93
|
VCR.use_cassette(:engine_suggest_pagination) do
|
83
94
|
results = client.suggest(engine_slug, 'goo', {:page => 2})
|
84
|
-
results.document_types.size.
|
85
|
-
results['videos'].size.
|
86
|
-
results['channels'].size.
|
95
|
+
expect(results.document_types.size).to eq(2)
|
96
|
+
expect(results['videos'].size).to eq(0)
|
97
|
+
expect(results['channels'].size).to eq(0)
|
87
98
|
end
|
88
99
|
end
|
89
100
|
end
|
@@ -94,16 +105,16 @@ describe Swiftype::Client do
|
|
94
105
|
it 'does a prefix search on the provided DocumentType' do
|
95
106
|
VCR.use_cassette(:document_type_suggest) do
|
96
107
|
results = client.suggest_document_type(engine_slug, document_type_slug, 'goo')
|
97
|
-
results.document_types.
|
98
|
-
results['videos'].size.
|
108
|
+
expect(results.document_types).to eq(['videos'])
|
109
|
+
expect(results['videos'].size).to eq(1)
|
99
110
|
end
|
100
111
|
end
|
101
112
|
|
102
113
|
it 'suggests for a document types with options' do
|
103
114
|
VCR.use_cassette(:document_type_suggest_pagination) do
|
104
115
|
results = client.suggest_document_type(engine_slug, document_type_slug, 'goo', {:page => 2})
|
105
|
-
results.document_types.
|
106
|
-
results[document_type_slug].size.
|
116
|
+
expect(results.document_types).to eq(['videos'])
|
117
|
+
expect(results[document_type_slug].size).to eq(0)
|
107
118
|
end
|
108
119
|
end
|
109
120
|
end
|
@@ -114,28 +125,28 @@ describe Swiftype::Client do
|
|
114
125
|
it 'gets all engines' do
|
115
126
|
VCR.use_cassette(:list_engines) do
|
116
127
|
engines = client.engines
|
117
|
-
engines.size.
|
128
|
+
expect(engines.size).to eq(6)
|
118
129
|
end
|
119
130
|
end
|
120
131
|
|
121
132
|
it 'gets an engine' do
|
122
133
|
VCR.use_cassette(:find_engine) do
|
123
134
|
engine = client.engine(engine_slug)
|
124
|
-
engine['slug'].
|
135
|
+
expect(engine['slug']).to eq(engine_slug)
|
125
136
|
end
|
126
137
|
end
|
127
138
|
|
128
139
|
it 'creates engines' do
|
129
140
|
VCR.use_cassette(:create_engine) do
|
130
141
|
engine = client.create_engine('new engine from spec')
|
131
|
-
engine['slug'].
|
142
|
+
expect(engine['slug']).to eq('new-engine-from-spec')
|
132
143
|
end
|
133
144
|
end
|
134
145
|
|
135
146
|
it 'destroys engines' do
|
136
147
|
VCR.use_cassette(:destroy_engine) do
|
137
148
|
response = client.destroy_engine('new-engine-from-spec')
|
138
|
-
response.
|
149
|
+
expect(response).to be_nil
|
139
150
|
end
|
140
151
|
end
|
141
152
|
end
|
@@ -146,15 +157,15 @@ describe Swiftype::Client do
|
|
146
157
|
it 'gets all document types' do
|
147
158
|
VCR.use_cassette(:list_document_type) do
|
148
159
|
document_types = client.document_types(engine_slug)
|
149
|
-
document_types.size.
|
150
|
-
document_types.map { |dt| dt['name'] }.sort.
|
160
|
+
expect(document_types.size).to eq(2)
|
161
|
+
expect(document_types.map { |dt| dt['name'] }.sort).to eq(['channels', 'videos'])
|
151
162
|
end
|
152
163
|
end
|
153
164
|
|
154
165
|
it 'gets a document type' do
|
155
166
|
VCR.use_cassette(:find_document_type) do
|
156
167
|
document_type = client.document_type(engine_slug, document_type_slug)
|
157
|
-
document_type['slug'].
|
168
|
+
expect(document_type['slug']).to eq(document_type_slug)
|
158
169
|
end
|
159
170
|
end
|
160
171
|
|
@@ -162,15 +173,15 @@ describe Swiftype::Client do
|
|
162
173
|
VCR.use_cassette(:create_document_type) do
|
163
174
|
name = document_type_slug
|
164
175
|
document_type = client.create_document_type(engine_slug, 'new_doc_type')
|
165
|
-
document_type['name'].
|
166
|
-
document_type['slug'].
|
176
|
+
expect(document_type['name']).to eq('new_doc_type')
|
177
|
+
expect(document_type['slug']).to eq('new-doc-type')
|
167
178
|
end
|
168
179
|
end
|
169
180
|
|
170
181
|
it 'destroys document types' do
|
171
182
|
VCR.use_cassette(:destroy_document_type) do
|
172
183
|
response = client.destroy_document_type(engine_slug, 'new-doc-type')
|
173
|
-
response.
|
184
|
+
expect(response).to be_nil
|
174
185
|
end
|
175
186
|
end
|
176
187
|
|
@@ -184,6 +195,16 @@ describe Swiftype::Client do
|
|
184
195
|
end
|
185
196
|
|
186
197
|
context 'Document' do
|
198
|
+
|
199
|
+
def check_async_response_format(response, options = {})
|
200
|
+
expect(response.keys).to match_array(["document_receipts", "batch_link"])
|
201
|
+
expect(response["document_receipts"]).to be_a_kind_of(Array)
|
202
|
+
expect(response["document_receipts"].first.keys).to match_array(["id", "external_id", "link", "status", "errors"])
|
203
|
+
expect(response["document_receipts"].first["external_id"]).to eq(options[:external_id]) if options[:external_id]
|
204
|
+
expect(response["document_receipts"].first["status"]).to eq(options[:status]) if options[:status]
|
205
|
+
expect(response["document_receipts"].first["errors"]).to eq(options[:errors]) if options[:errors]
|
206
|
+
end
|
207
|
+
|
187
208
|
let(:document_type_slug) { 'videos' }
|
188
209
|
let(:document_id) { 'FtX8nswnUKU'}
|
189
210
|
let(:documents) do
|
@@ -204,49 +225,49 @@ describe Swiftype::Client do
|
|
204
225
|
it 'lists documents in a document type' do
|
205
226
|
VCR.use_cassette(:list_documents) do
|
206
227
|
documents = client.documents(engine_slug, document_type_slug)
|
207
|
-
documents.size.
|
228
|
+
expect(documents.size).to eq(2)
|
208
229
|
end
|
209
230
|
end
|
210
231
|
|
211
232
|
it 'lists documents with pagination' do
|
212
233
|
VCR.use_cassette(:list_documents_with_pagination) do
|
213
234
|
documents = client.documents(engine_slug, document_type_slug, 2, 2)
|
214
|
-
documents.size.
|
235
|
+
expect(documents.size).to eq(2)
|
215
236
|
end
|
216
237
|
end
|
217
238
|
|
218
239
|
it 'find a document' do
|
219
240
|
VCR.use_cassette(:find_document) do
|
220
241
|
document = client.document(engine_slug, document_type_slug, document_id)
|
221
|
-
document['external_id'].
|
242
|
+
expect(document['external_id']).to eq(document_id)
|
222
243
|
end
|
223
244
|
end
|
224
245
|
|
225
246
|
it 'creates a document' do
|
226
247
|
VCR.use_cassette(:create_document) do
|
227
248
|
document = client.create_document(engine_slug, document_type_slug, documents.first)
|
228
|
-
document['external_id'].
|
249
|
+
expect(document['external_id']).to eq('INscMGmhmX4')
|
229
250
|
end
|
230
251
|
end
|
231
252
|
|
232
253
|
it 'bulk create multiple documents' do
|
233
254
|
VCR.use_cassette(:bulk_create_documents) do
|
234
255
|
response = client.create_documents(engine_slug, document_type_slug, documents)
|
235
|
-
response.
|
256
|
+
expect(response).to eq([true, true])
|
236
257
|
end
|
237
258
|
end
|
238
259
|
|
239
260
|
it 'destroys a document' do
|
240
261
|
VCR.use_cassette(:destroy_document) do
|
241
262
|
response = client.destroy_document(engine_slug, document_type_slug, 'INscMGmhmX4')
|
242
|
-
response.
|
263
|
+
expect(response).to be_nil
|
243
264
|
end
|
244
265
|
end
|
245
266
|
|
246
267
|
it 'destroys multiple documents' do
|
247
268
|
VCR.use_cassette(:bulk_destroy_documents) do
|
248
269
|
response = client.destroy_documents(engine_slug, document_type_slug, ['INscMGmhmX4', 'XfY9Dsg_DZk'])
|
249
|
-
response.
|
270
|
+
expect(response).to eq([true, true])
|
250
271
|
end
|
251
272
|
end
|
252
273
|
|
@@ -254,16 +275,16 @@ describe Swiftype::Client do
|
|
254
275
|
it 'creates a document' do
|
255
276
|
VCR.use_cassette(:create_or_update_document_create) do
|
256
277
|
response = client.create_or_update_document(engine_slug, document_type_slug, {:external_id => 'foobar', :fields => [{:type => :string, :name => 'title', :value => 'new document'}]})
|
257
|
-
response['external_id'].
|
258
|
-
response['title'].
|
278
|
+
expect(response['external_id']).to eq('foobar')
|
279
|
+
expect(response['title']).to eq('new document')
|
259
280
|
end
|
260
281
|
end
|
261
282
|
|
262
283
|
it 'updates an existing document' do
|
263
284
|
VCR.use_cassette(:create_or_update_document_update) do
|
264
285
|
response = client.create_or_update_document(engine_slug, document_type_slug, {:external_id => document_id, :fields => [{:type => :string, :name => 'title', :value => 'new title'}]})
|
265
|
-
response['external_id'].
|
266
|
-
response['title'].
|
286
|
+
expect(response['external_id']).to eq(document_id)
|
287
|
+
expect(response['title']).to eq('new title')
|
267
288
|
end
|
268
289
|
end
|
269
290
|
end
|
@@ -272,7 +293,7 @@ describe Swiftype::Client do
|
|
272
293
|
it 'returns true for all documents successfully created or updated' do
|
273
294
|
VCR.use_cassette(:bulk_create_or_update_documents_success) do
|
274
295
|
response = client.create_or_update_documents(engine_slug, document_type_slug, documents)
|
275
|
-
response.
|
296
|
+
expect(response).to eq([true, true])
|
276
297
|
end
|
277
298
|
end
|
278
299
|
|
@@ -281,7 +302,76 @@ describe Swiftype::Client do
|
|
281
302
|
|
282
303
|
VCR.use_cassette(:bulk_create_or_update_documents_failure) do
|
283
304
|
response = client.create_or_update_documents(engine_slug, document_type_slug, documents)
|
284
|
-
response.
|
305
|
+
expect(response).to eq([false])
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
context '#async_create_or_update_documents' do
|
311
|
+
it 'returns true for all documents successfully created or updated' do
|
312
|
+
VCR.use_cassette(:async_create_or_update_document_success) do
|
313
|
+
response = client.async_create_or_update_documents(engine_slug, document_type_slug, documents)
|
314
|
+
check_async_response_format(response, :external_id => documents.first["external_id"], :status => "pending")
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'returns false if a document cannot be created or updated due to an error' do
|
319
|
+
documents = [{:external_id => 'failed_doc', :fields => [{:type => :string, :name => :title}]}] # missing value
|
320
|
+
|
321
|
+
VCR.use_cassette(:async_create_or_update_document_failure) do
|
322
|
+
response = client.async_create_or_update_documents(engine_slug, document_type_slug, documents)
|
323
|
+
check_async_response_format(response, :external_id => documents.first["external_id"], :status => "failed", :errors => ["Missing required parameter: value"])
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
context '#document_receipts' do
|
329
|
+
before :each do
|
330
|
+
def get_receipt_ids
|
331
|
+
receipt_ids = nil
|
332
|
+
VCR.use_cassette(:async_create_or_update_document_success) do
|
333
|
+
response = client.async_create_or_update_documents(engine_slug, document_type_slug, documents)
|
334
|
+
receipt_ids = response["document_receipts"].map { |r| r["id"] }
|
335
|
+
end
|
336
|
+
receipt_ids
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'returns array of hashes one for each receipt' do
|
341
|
+
VCR.use_cassette(:document_receipts_multiple) do
|
342
|
+
receipt_ids = get_receipt_ids
|
343
|
+
response = client.document_receipts(receipt_ids)
|
344
|
+
expect(response).to eq([{"id" => receipt_ids[0], "status" => "pending"}, {"id" => receipt_ids[1], "status" => "pending"}])
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
context '#index_documents' do
|
350
|
+
it 'returns #async_create_or_update_documents format return when async has been passed as true' do
|
351
|
+
VCR.use_cassette(:async_create_or_update_document_success) do
|
352
|
+
response = client.index_documents(engine_slug, document_type_slug, documents, :async => true)
|
353
|
+
check_async_response_format(response, :external_id => documents.first["external_id"], :status => "pending")
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'returns document_receipts when successfull' do
|
358
|
+
VCR.use_cassette(:async_create_or_update_document_success) do
|
359
|
+
VCR.use_cassette(:document_receipts_multiple_complete) do
|
360
|
+
response = client.index_documents(engine_slug, document_type_slug, documents)
|
361
|
+
# Sort keys for Ruby 1.8.7 compatibility
|
362
|
+
expect(response.map(&:keys).map(&:sort)).to eq([["id", "link", "status"], ["id", "link", "status"]])
|
363
|
+
expect(response.map { |a| a["status"] }).to eq(["complete", "complete"])
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
it 'should timeout if the process takes longer than the timeout option passed' do
|
369
|
+
allow(client).to receive(:document_receipts) { sleep 0.05 }
|
370
|
+
|
371
|
+
VCR.use_cassette(:async_create_or_update_document_success) do
|
372
|
+
expect do
|
373
|
+
client.index_documents(engine_slug, document_type_slug, documents, :timeout => 0.01)
|
374
|
+
end.to raise_error(Timeout::Error)
|
285
375
|
end
|
286
376
|
end
|
287
377
|
end
|
@@ -290,7 +380,7 @@ describe Swiftype::Client do
|
|
290
380
|
it 'returns true for all documents successfully created or updated' do
|
291
381
|
VCR.use_cassette(:bulk_create_or_update_documents_verbose_success) do
|
292
382
|
response = client.create_or_update_documents_verbose(engine_slug, document_type_slug, documents)
|
293
|
-
response.
|
383
|
+
expect(response).to eq([true, true])
|
294
384
|
end
|
295
385
|
end
|
296
386
|
|
@@ -299,8 +389,8 @@ describe Swiftype::Client do
|
|
299
389
|
|
300
390
|
VCR.use_cassette(:bulk_create_or_update_documents_verbose_failure) do
|
301
391
|
response = client.create_or_update_documents_verbose(engine_slug, document_type_slug, documents)
|
302
|
-
response.size.
|
303
|
-
response.first.
|
392
|
+
expect(response.size).to eq(1)
|
393
|
+
expect(response.first).to match /^Invalid field definition/
|
304
394
|
end
|
305
395
|
end
|
306
396
|
end
|
@@ -310,9 +400,9 @@ describe Swiftype::Client do
|
|
310
400
|
fields = {:title => 'awesome new title', :channel_id => 'UC5VA5j05FjETg-iLekcyiBw'}
|
311
401
|
VCR.use_cassette(:update_document) do
|
312
402
|
response = client.update_document(engine_slug, document_type_slug, document_id, fields)
|
313
|
-
response['external_id'].
|
314
|
-
response['title'].
|
315
|
-
response['channel_id'].
|
403
|
+
expect(response['external_id']).to eq(document_id)
|
404
|
+
expect(response['title']).to eq('awesome new title')
|
405
|
+
expect(response['channel_id']).to eq('UC5VA5j05FjETg-iLekcyiBw')
|
316
406
|
end
|
317
407
|
end
|
318
408
|
|
@@ -333,7 +423,7 @@ describe Swiftype::Client do
|
|
333
423
|
|
334
424
|
VCR.use_cassette(:update_documents_success) do
|
335
425
|
response = client.update_documents(engine_slug, document_type_slug, documents)
|
336
|
-
response.
|
426
|
+
expect(response).to eq([true, true])
|
337
427
|
end
|
338
428
|
end
|
339
429
|
|
@@ -342,7 +432,7 @@ describe Swiftype::Client do
|
|
342
432
|
|
343
433
|
VCR.use_cassette(:update_documents_failure_non_existent_document) do
|
344
434
|
response = client.update_documents(engine_slug, document_type_slug, documents)
|
345
|
-
response.
|
435
|
+
expect(response).to eq([false])
|
346
436
|
end
|
347
437
|
end
|
348
438
|
end
|
@@ -355,32 +445,32 @@ describe Swiftype::Client do
|
|
355
445
|
it 'returns search counts for the default time frame' do
|
356
446
|
VCR.use_cassette(:analytics_searches) do
|
357
447
|
searches = client.analytics_searches(engine_slug)
|
358
|
-
searches.size.
|
359
|
-
searches.first.
|
448
|
+
expect(searches.size).to eq(15) # FIXME: is this a bug in the API?
|
449
|
+
expect(searches.first).to eq(['2013-09-13', 0])
|
360
450
|
end
|
361
451
|
end
|
362
452
|
|
363
453
|
it 'returns search counts for a specified time range' do
|
364
454
|
VCR.use_cassette(:analytics_searches_with_time_range) do
|
365
455
|
searches = client.analytics_searches(engine_slug, :start_date => '2013-01-01', :end_date => '2013-01-07')
|
366
|
-
searches.size.
|
367
|
-
searches.first.
|
456
|
+
expect(searches.size).to eq(7)
|
457
|
+
expect(searches.first).to eq(['2013-01-07', 0])
|
368
458
|
end
|
369
459
|
end
|
370
460
|
|
371
461
|
it 'returns search counts for a specified DocumentType' do
|
372
462
|
VCR.use_cassette(:analytics_searchs_with_document_type) do
|
373
463
|
searches = client.analytics_searches(engine_slug, :document_type_id => 'page')
|
374
|
-
searches.size.
|
375
|
-
searches.first.
|
464
|
+
expect(searches.size).to eq(15)
|
465
|
+
expect(searches.first).to eq(['2013-09-16', 0])
|
376
466
|
end
|
377
467
|
end
|
378
468
|
|
379
469
|
it 'returns search counts for a specified DocumentType and time range' do
|
380
470
|
VCR.use_cassette(:analytics_searches_with_document_type_and_time_range) do
|
381
471
|
searches = client.analytics_autoselects(engine_slug, :document_type_id => 'page', :start_date => '2013-07-01', :end_date => '2013-07-07')
|
382
|
-
searches.size.
|
383
|
-
searches.first.
|
472
|
+
expect(searches.size).to eq(7)
|
473
|
+
expect(searches.first).to eq(['2013-07-07', 0])
|
384
474
|
end
|
385
475
|
end
|
386
476
|
end
|
@@ -389,29 +479,29 @@ describe Swiftype::Client do
|
|
389
479
|
it 'returns autoselect counts for the default time frame' do
|
390
480
|
VCR.use_cassette(:analytics_autoselects) do
|
391
481
|
autoselects = client.analytics_autoselects(engine_slug)
|
392
|
-
autoselects.size.
|
393
|
-
autoselects.first.
|
482
|
+
expect(autoselects.size).to eq(15)
|
483
|
+
expect(autoselects.first).to eq(['2013-09-13', 0])
|
394
484
|
end
|
395
485
|
end
|
396
486
|
|
397
487
|
it 'returns autoselects counts for a specified time range' do
|
398
488
|
VCR.use_cassette(:analytics_autoselects_with_time_range) do
|
399
489
|
autoselects = client.analytics_autoselects(engine_slug, :start_date => '2013-07-01', :end_date => '2013-07-07')
|
400
|
-
autoselects.size.
|
490
|
+
expect(autoselects.size).to eq(7)
|
401
491
|
end
|
402
492
|
end
|
403
493
|
|
404
494
|
it 'returns autoselect counts for a specified DocumentType' do
|
405
495
|
VCR.use_cassette(:analytics_autoselects_with_document_type) do
|
406
496
|
autoselects = client.analytics_autoselects(engine_slug, :document_type_id => 'page')
|
407
|
-
autoselects.size.
|
497
|
+
expect(autoselects.size).to eq(15)
|
408
498
|
end
|
409
499
|
end
|
410
500
|
|
411
501
|
it 'returns autoselect counts for a specified DocumentType and time range' do
|
412
502
|
VCR.use_cassette(:analytics_autoselects_with_document_type_and_time_range) do
|
413
503
|
autoselects = client.analytics_autoselects(engine_slug, :document_type_id => 'page', :start_date => '2013-07-01', :end_date => '2013-07-07')
|
414
|
-
autoselects.size.
|
504
|
+
expect(autoselects.size).to eq(7)
|
415
505
|
end
|
416
506
|
end
|
417
507
|
end
|
@@ -420,31 +510,31 @@ describe Swiftype::Client do
|
|
420
510
|
it 'returns click counts for the default time frame' do
|
421
511
|
VCR.use_cassette(:analytics_clicks) do
|
422
512
|
clicks = client.analytics_clicks(engine_slug)
|
423
|
-
clicks.size.
|
424
|
-
clicks.first.
|
513
|
+
expect(clicks.size).to eq(15)
|
514
|
+
expect(clicks.first).to eq(['2013-09-17', 0])
|
425
515
|
end
|
426
516
|
end
|
427
517
|
|
428
518
|
it 'returns clicks counts for a specified time range' do
|
429
519
|
VCR.use_cassette(:analytics_clicks_with_time_range) do
|
430
520
|
clicks = client.analytics_clicks(engine_slug, :start_date => '2013-07-01', :end_date => '2013-07-07')
|
431
|
-
clicks.size.
|
432
|
-
clicks.first.
|
521
|
+
expect(clicks.size).to eq(7)
|
522
|
+
expect(clicks.first).to eq(['2013-07-07', 0])
|
433
523
|
end
|
434
524
|
end
|
435
525
|
|
436
526
|
it 'returns click counts for a specified DocumentType' do
|
437
527
|
VCR.use_cassette(:analytics_clicks_with_document_type) do
|
438
528
|
clicks = client.analytics_clicks(engine_slug, :document_type_id => 'page')
|
439
|
-
clicks.size.
|
529
|
+
expect(clicks.size).to eq(15)
|
440
530
|
end
|
441
531
|
end
|
442
532
|
|
443
533
|
it 'returns click counts for a specified DocumentType and time range' do
|
444
534
|
VCR.use_cassette(:analytics_clicks_with_document_type_and_time_range) do
|
445
535
|
clicks = client.analytics_clicks(engine_slug, :document_type_id => 'page', :start_date => '2013-07-01', :end_date => '2013-07-07')
|
446
|
-
clicks.size.
|
447
|
-
clicks.first.
|
536
|
+
expect(clicks.size).to eq(7)
|
537
|
+
expect(clicks.first).to eq(['2013-07-07', 0])
|
448
538
|
end
|
449
539
|
end
|
450
540
|
end
|
@@ -453,16 +543,16 @@ describe Swiftype::Client do
|
|
453
543
|
it 'returns top queries' do
|
454
544
|
VCR.use_cassette(:analytics_top_queries) do
|
455
545
|
top_queries = client.analytics_top_queries(engine_slug)
|
456
|
-
top_queries.size.
|
457
|
-
top_queries.first.
|
546
|
+
expect(top_queries.size).to eq(3)
|
547
|
+
expect(top_queries.first).to eq(['"fire watch"', 1])
|
458
548
|
end
|
459
549
|
end
|
460
550
|
|
461
551
|
it 'returns top queries with pagination' do
|
462
552
|
VCR.use_cassette(:analytics_top_queries_paginated) do
|
463
553
|
top_queries = client.analytics_top_queries(engine_slug, :start_date => '2013-08-01', :end_date => '2013-08-30', :per_page => 5, :page => 2)
|
464
|
-
top_queries.size.
|
465
|
-
top_queries.first.
|
554
|
+
expect(top_queries.size).to eq(5)
|
555
|
+
expect(top_queries.first).to eq(['no simple victory', 1])
|
466
556
|
end
|
467
557
|
end
|
468
558
|
|
@@ -479,16 +569,16 @@ describe Swiftype::Client do
|
|
479
569
|
it 'returns top queries with no results for the default time range' do
|
480
570
|
VCR.use_cassette(:analytics_top_no_result_queries) do
|
481
571
|
top_no_result_queries = client.analytics_top_no_result_queries(engine_slug)
|
482
|
-
top_no_result_queries.size.
|
483
|
-
top_no_result_queries.first.
|
572
|
+
expect(top_no_result_queries.size).to eq(2)
|
573
|
+
expect(top_no_result_queries.first).to eq(['no results', 10])
|
484
574
|
end
|
485
575
|
end
|
486
576
|
|
487
577
|
it 'has top no result queries in date ranges' do
|
488
578
|
VCR.use_cassette(:analytics_top_no_result_queries_paginated) do
|
489
579
|
top_no_result_queries = client.analytics_top_no_result_queries(engine_slug, :start_date => '2013-08-01', :end_date => '2013-08-30', :per_page => 5, :page => 2)
|
490
|
-
top_no_result_queries.size.
|
491
|
-
top_no_result_queries.first.
|
580
|
+
expect(top_no_result_queries.size).to eq(1)
|
581
|
+
expect(top_no_result_queries.first).to eq(['no result again', 2])
|
492
582
|
end
|
493
583
|
end
|
494
584
|
end
|
@@ -501,8 +591,8 @@ describe Swiftype::Client do
|
|
501
591
|
it 'gets all domains' do
|
502
592
|
VCR.use_cassette(:list_domains) do
|
503
593
|
domains = client.domains(engine_slug)
|
504
|
-
domains.size.
|
505
|
-
domains.first['id'].
|
594
|
+
expect(domains.size).to eq(1)
|
595
|
+
expect(domains.first['id']).to eq(domain_id)
|
506
596
|
end
|
507
597
|
end
|
508
598
|
|
@@ -510,7 +600,7 @@ describe Swiftype::Client do
|
|
510
600
|
it 'shows a domain if it exists' do
|
511
601
|
VCR.use_cassette(:find_domain) do
|
512
602
|
domain = client.domain(engine_slug, domain_id)
|
513
|
-
domain['id'].
|
603
|
+
expect(domain['id']).to eq(domain_id)
|
514
604
|
end
|
515
605
|
end
|
516
606
|
|
@@ -528,7 +618,7 @@ describe Swiftype::Client do
|
|
528
618
|
VCR.use_cassette(:create_domain) do
|
529
619
|
url = 'http://www.zombo.com/'
|
530
620
|
domain = client.create_domain(engine_slug, url)
|
531
|
-
domain['submitted_url'].
|
621
|
+
expect(domain['submitted_url']).to eq(url)
|
532
622
|
end
|
533
623
|
end
|
534
624
|
end
|
@@ -536,7 +626,7 @@ describe Swiftype::Client do
|
|
536
626
|
it 'destroys a domain' do
|
537
627
|
VCR.use_cassette(:destroy_domain) do
|
538
628
|
response = client.destroy_domain(engine_slug, '52324b132ed960589800004a')
|
539
|
-
response.
|
629
|
+
expect(response).to be_nil
|
540
630
|
end
|
541
631
|
end
|
542
632
|
|
@@ -544,7 +634,7 @@ describe Swiftype::Client do
|
|
544
634
|
it 'enqueues a request to recrawl a domain' do
|
545
635
|
VCR.use_cassette(:recrawl_domain_success) do
|
546
636
|
domain = client.recrawl_domain(engine_slug, domain_id)
|
547
|
-
domain['id'].
|
637
|
+
expect(domain['id']).to eq(domain_id)
|
548
638
|
end
|
549
639
|
end
|
550
640
|
|
@@ -562,7 +652,7 @@ describe Swiftype::Client do
|
|
562
652
|
VCR.use_cassette(:crawl_url) do
|
563
653
|
url = 'http://crawler-demo-site.herokuapp.com/2012/01/01/first-post.html'
|
564
654
|
crawled_url = client.crawl_url(engine_slug, domain_id, url)
|
565
|
-
crawled_url['url'].
|
655
|
+
expect(crawled_url['url']).to eq(url)
|
566
656
|
end
|
567
657
|
end
|
568
658
|
end
|
@@ -579,7 +669,7 @@ describe Swiftype::Client do
|
|
579
669
|
it 'returns nil' do
|
580
670
|
VCR.use_cassette(:log_clickthrough_success) do
|
581
671
|
response = client.log_clickthrough(engine_slug, document_type_slug, query, external_id)
|
582
|
-
response.
|
672
|
+
expect(response).to eq(nil)
|
583
673
|
end
|
584
674
|
end
|
585
675
|
|