search-kit 0.0.3 → 0.0.4
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/Gemfile.lock +88 -0
- data/coverage/assets/0.10.0/application.css +799 -0
- data/coverage/assets/0.10.0/application.js +1707 -0
- data/coverage/assets/0.10.0/colorbox/border.png +0 -0
- data/coverage/assets/0.10.0/colorbox/controls.png +0 -0
- data/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
- data/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.10.0/favicon_green.png +0 -0
- data/coverage/assets/0.10.0/favicon_red.png +0 -0
- data/coverage/assets/0.10.0/favicon_yellow.png +0 -0
- data/coverage/assets/0.10.0/loading.gif +0 -0
- data/coverage/assets/0.10.0/magnify.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +446 -0
- data/demo/videos +112 -0
- data/demo/videos.json +14292 -0
- data/lib/search_kit/configuration.rb +8 -3
- data/lib/search_kit/logger.rb +1 -2
- data/lib/search_kit/version.rb +1 -1
- data/log/service-layer-development.log +282 -0
- data/log/service-layer-test.log +2874 -0
- data/pkg/search-kit-0.0.3.gem +0 -0
- data/search-kit.gemspec +5 -11
- data/spec/integrations/subscriber_model_spec.rb +91 -0
- data/spec/search_kit/cli/documents_spec.rb +234 -0
- data/spec/search_kit/cli/events_spec.rb +243 -0
- data/spec/search_kit/cli/indices_spec.rb +273 -0
- data/spec/search_kit/cli/search_spec.rb +77 -0
- data/spec/search_kit/cli/subscribers_spec.rb +108 -0
- data/spec/search_kit/clients/documents_spec.rb +210 -0
- data/spec/search_kit/clients/events_spec.rb +202 -0
- data/spec/search_kit/clients/indices_spec.rb +193 -0
- data/spec/search_kit/clients/keys_spec.rb +216 -0
- data/spec/search_kit/clients/populate_spec.rb +195 -0
- data/spec/search_kit/clients/scaffold_spec.rb +70 -0
- data/spec/search_kit/clients/search_spec.rb +87 -0
- data/spec/search_kit/clients/subscribers_spec.rb +166 -0
- data/spec/search_kit/configuration_spec.rb +25 -0
- data/spec/search_kit/messages_spec.rb +45 -0
- data/spec/search_kit/models/document_spec.rb +34 -0
- data/spec/search_kit/models/documents_spec.rb +12 -0
- data/spec/search_kit/models/event_spec.rb +14 -0
- data/spec/search_kit/models/events_spec.rb +12 -0
- data/spec/search_kit/models/key_spec.rb +26 -0
- data/spec/search_kit/models/keys_spec.rb +39 -0
- data/spec/search_kit/models/subscriber_spec.rb +22 -0
- data/spec/search_kit/polling/process_spec.rb +65 -0
- data/spec/search_kit/polling_spec.rb +24 -0
- data/spec/search_kit_spec.rb +7 -0
- data/spec/spec_helper.rb +29 -0
- data/tmp/modeling.rb +22 -0
- data/tmp/vidya.json +1 -0
- metadata +101 -19
- data/.gitignore +0 -16
- data/.rspec +0 -2
- data/.rubocop.yml +0 -39
- data/.ruby-version +0 -1
- data/.travis.yml +0 -4
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SearchKit::Clients::Documents do
|
5
|
+
let(:body) { { data: [] } }
|
6
|
+
let(:client) { described_class.new }
|
7
|
+
let(:id) { 1 }
|
8
|
+
let(:json) { body.to_json }
|
9
|
+
let(:response) { OpenStruct.new(body: json, status: status) }
|
10
|
+
let(:slug) { "index-slug" }
|
11
|
+
let(:status) { 200 }
|
12
|
+
let(:token) { SearchKit.config.app_token }
|
13
|
+
|
14
|
+
before do
|
15
|
+
allow(client.connection).to receive(:delete).and_return(response)
|
16
|
+
allow(client.connection).to receive(:get).and_return(response)
|
17
|
+
allow(client.connection).to receive(:patch).and_return(response)
|
18
|
+
allow(client.connection).to receive(:post).and_return(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { client }
|
22
|
+
|
23
|
+
it { is_expected.to respond_to :token }
|
24
|
+
|
25
|
+
describe '#connection' do
|
26
|
+
subject { client.connection }
|
27
|
+
it { is_expected.to be_instance_of Faraday::Connection }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#create' do
|
31
|
+
let(:document) { { id: id, title: "The first document" } }
|
32
|
+
|
33
|
+
let(:params) do
|
34
|
+
{ token: token, data: { type: "documents", attributes: document } }
|
35
|
+
end
|
36
|
+
|
37
|
+
subject { client.create(slug, document) }
|
38
|
+
|
39
|
+
it "calls #connection.post with the base path and a document" do
|
40
|
+
expect(client.connection).to receive(:post).with(slug, params)
|
41
|
+
subject
|
42
|
+
end
|
43
|
+
|
44
|
+
it "parses the json response" do
|
45
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
46
|
+
subject
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when the response status is 400' do
|
50
|
+
let(:status) { 400 }
|
51
|
+
|
52
|
+
it "raises a bad request error" do
|
53
|
+
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the response status is 401' do
|
58
|
+
let(:status) { 401 }
|
59
|
+
|
60
|
+
it "raises a not authorized error" do
|
61
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when the response status is 404' do
|
66
|
+
let(:status) { 404 }
|
67
|
+
|
68
|
+
it "raises an index not found error" do
|
69
|
+
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when the response status is 422' do
|
74
|
+
let(:status) { 422 }
|
75
|
+
|
76
|
+
it "raises an unprocessable error" do
|
77
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#delete' do
|
84
|
+
subject { client.delete(slug, id) }
|
85
|
+
|
86
|
+
it "calls #connection.get with the base events path" do
|
87
|
+
expect(client.connection)
|
88
|
+
.to receive(:delete)
|
89
|
+
.with("#{slug}/#{id}", token: token)
|
90
|
+
|
91
|
+
subject
|
92
|
+
end
|
93
|
+
|
94
|
+
it "parses the json response" do
|
95
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
96
|
+
subject
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when the response status is 401' do
|
100
|
+
let(:status) { 401 }
|
101
|
+
|
102
|
+
it "raises a not authorized error" do
|
103
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when the response status is 404' do
|
108
|
+
let(:status) { 404 }
|
109
|
+
|
110
|
+
it "raises an index not found error" do
|
111
|
+
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#show' do
|
118
|
+
subject { client.show(slug, id) }
|
119
|
+
|
120
|
+
it "calls #connection.get with the given id" do
|
121
|
+
expect(client.connection)
|
122
|
+
.to receive(:get)
|
123
|
+
.with("#{slug}/#{id}", token: token)
|
124
|
+
|
125
|
+
subject
|
126
|
+
end
|
127
|
+
|
128
|
+
it "parses the json response" do
|
129
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
130
|
+
subject
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when the response status is 401' do
|
134
|
+
let(:status) { 401 }
|
135
|
+
|
136
|
+
it "raises a not authorized error" do
|
137
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when the response status is 404' do
|
142
|
+
let(:status) { 404 }
|
143
|
+
|
144
|
+
it "raises an index not found error" do
|
145
|
+
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '#update' do
|
152
|
+
let(:document) { { id: id, title: "The first document" } }
|
153
|
+
|
154
|
+
let(:params) do
|
155
|
+
{
|
156
|
+
token: token,
|
157
|
+
data: { type: "documents", id: id, attributes: document }
|
158
|
+
}
|
159
|
+
end
|
160
|
+
|
161
|
+
subject { client.update(slug, id, document) }
|
162
|
+
|
163
|
+
it "calls #connection.patch with the slug, id and document" do
|
164
|
+
expect(client.connection)
|
165
|
+
.to receive(:patch)
|
166
|
+
.with("#{slug}/#{id}", params)
|
167
|
+
|
168
|
+
subject
|
169
|
+
end
|
170
|
+
|
171
|
+
it "parses the json response" do
|
172
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
173
|
+
subject
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when the response status is 400' do
|
177
|
+
let(:status) { 400 }
|
178
|
+
|
179
|
+
it "raises a bad request error" do
|
180
|
+
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when the response status is 401' do
|
185
|
+
let(:status) { 401 }
|
186
|
+
|
187
|
+
it "raises a not authorized error" do
|
188
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when the response status is 422' do
|
193
|
+
let(:status) { 422 }
|
194
|
+
|
195
|
+
it "raises an unprocessable error" do
|
196
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'when the response status is 404' do
|
201
|
+
let(:status) { 404 }
|
202
|
+
|
203
|
+
it "raises an index not found error" do
|
204
|
+
expect { subject }.to raise_exception(SearchKit::Errors::IndexNotFound)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SearchKit::Clients::Events do
|
5
|
+
let(:client) { described_class.new }
|
6
|
+
let(:id) { 1 }
|
7
|
+
let(:hash) { {} }
|
8
|
+
let(:json) { hash.to_json }
|
9
|
+
let(:response) { OpenStruct.new(status: status, body: json) }
|
10
|
+
let(:status) { 200 }
|
11
|
+
let(:token) { SearchKit.config.app_token }
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(client.connection).to receive(:delete).and_return(response)
|
15
|
+
allow(client.connection).to receive(:get).and_return(response)
|
16
|
+
allow(client.connection).to receive(:post).and_return(response)
|
17
|
+
allow(JSON).to receive(:parse).and_return(hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { client }
|
21
|
+
|
22
|
+
it { is_expected.to respond_to :token }
|
23
|
+
|
24
|
+
describe '#connection' do
|
25
|
+
subject { client.connection }
|
26
|
+
it { is_expected.to be_instance_of Faraday::Connection }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#complete' do
|
30
|
+
subject { client.complete(id) }
|
31
|
+
|
32
|
+
it { is_expected.to be_instance_of SearchKit::Models::Event }
|
33
|
+
|
34
|
+
it "calls #connection.get with the base events path" do
|
35
|
+
expect(client.connection).to receive(:delete).with(id, token: token)
|
36
|
+
subject
|
37
|
+
end
|
38
|
+
|
39
|
+
it "parses the json response" do
|
40
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
41
|
+
subject
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when given status 401' do
|
45
|
+
let(:status) { 401 }
|
46
|
+
|
47
|
+
it do
|
48
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when given status 404' do
|
53
|
+
let(:status) { 404 }
|
54
|
+
|
55
|
+
it do
|
56
|
+
expect { subject }.to raise_exception(SearchKit::Errors::EventNotFound)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#index' do
|
62
|
+
subject { client.index }
|
63
|
+
|
64
|
+
it { is_expected.to be_instance_of SearchKit::Models::Events }
|
65
|
+
|
66
|
+
it "calls #connection.get with the base events path" do
|
67
|
+
expect(client.connection).to receive(:get).with(token: token)
|
68
|
+
subject
|
69
|
+
end
|
70
|
+
|
71
|
+
it "parses the json response" do
|
72
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
73
|
+
subject
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when given status 401' do
|
77
|
+
let(:status) { 401 }
|
78
|
+
|
79
|
+
it do
|
80
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#pending' do
|
86
|
+
let(:channel) { "colon:separated:string" }
|
87
|
+
|
88
|
+
subject { client.pending(channel) }
|
89
|
+
|
90
|
+
it { is_expected.to be_instance_of SearchKit::Models::Events }
|
91
|
+
|
92
|
+
it "calls #connection.get with the base events path" do
|
93
|
+
expect(client.connection)
|
94
|
+
.to receive(:get)
|
95
|
+
.with('', "filter[channel]" => channel, token: token)
|
96
|
+
|
97
|
+
subject
|
98
|
+
end
|
99
|
+
|
100
|
+
it "parses the json response" do
|
101
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
102
|
+
subject
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'when given status 401' do
|
106
|
+
let(:status) { 401 }
|
107
|
+
|
108
|
+
it do
|
109
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#publish' do
|
116
|
+
let(:channel) { "colon:separated:string" }
|
117
|
+
let(:options) { { channel: channel, payload: payload } }
|
118
|
+
|
119
|
+
let(:payload) do
|
120
|
+
{ one_key: true, two_key: true, red_key: true, blue_key: true }
|
121
|
+
end
|
122
|
+
|
123
|
+
let(:params) do
|
124
|
+
{
|
125
|
+
token: token,
|
126
|
+
data: {
|
127
|
+
type: 'events',
|
128
|
+
attributes: { channel: channel, payload: payload }
|
129
|
+
}
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
subject { client.publish(channel, payload) }
|
134
|
+
|
135
|
+
it { is_expected.to be_instance_of SearchKit::Models::Event }
|
136
|
+
|
137
|
+
it "calls #connection.get with the base events path" do
|
138
|
+
expect(client.connection).to receive(:post).with('', params)
|
139
|
+
subject
|
140
|
+
end
|
141
|
+
|
142
|
+
it "parses the json response" do
|
143
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
144
|
+
subject
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when given status 400' do
|
148
|
+
let(:status) { 400 }
|
149
|
+
|
150
|
+
it do
|
151
|
+
expect { subject }.to raise_exception(SearchKit::Errors::BadRequest)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when given status 401' do
|
156
|
+
let(:status) { 401 }
|
157
|
+
|
158
|
+
it do
|
159
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when given status 404' do
|
164
|
+
let(:status) { 422 }
|
165
|
+
|
166
|
+
it do
|
167
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unprocessable)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe '#show' do
|
173
|
+
subject { client.show(id) }
|
174
|
+
|
175
|
+
it "calls #connection.get with the base events path / id" do
|
176
|
+
expect(client.connection).to receive(:get).with(id, token: token)
|
177
|
+
subject
|
178
|
+
end
|
179
|
+
|
180
|
+
it "parses the json response" do
|
181
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
182
|
+
subject
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when given status 401' do
|
186
|
+
let(:status) { 401 }
|
187
|
+
|
188
|
+
it do
|
189
|
+
expect { subject }.to raise_exception(SearchKit::Errors::Unauthorized)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'when given status 404' do
|
194
|
+
let(:status) { 404 }
|
195
|
+
|
196
|
+
it do
|
197
|
+
expect { subject }.to raise_exception(SearchKit::Errors::EventNotFound)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe SearchKit::Clients::Indices do
|
5
|
+
let(:json) { response_body.to_json }
|
6
|
+
let(:response) { OpenStruct.new(status: status, body: json) }
|
7
|
+
let(:status) { 200 }
|
8
|
+
let(:client) { described_class.new }
|
9
|
+
let(:response_body) { { data: [] } }
|
10
|
+
let(:token) { SearchKit.config.app_token }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(client.connection).to receive(:delete).and_return(response)
|
14
|
+
allow(client.connection).to receive(:get).and_return(response)
|
15
|
+
allow(client.connection).to receive(:patch).and_return(response)
|
16
|
+
allow(client.connection).to receive(:post).and_return(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { client }
|
20
|
+
|
21
|
+
it { is_expected.to respond_to :token }
|
22
|
+
|
23
|
+
describe '#connection' do
|
24
|
+
subject { client.connection }
|
25
|
+
it { is_expected.to be_instance_of Faraday::Connection }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#archive' do
|
29
|
+
let(:slug) { "slug" }
|
30
|
+
|
31
|
+
subject { client.archive(slug) }
|
32
|
+
|
33
|
+
it "calls #connection.delete with given slug" do
|
34
|
+
expect(client.connection).to receive(:delete).with(slug, token: token)
|
35
|
+
subject
|
36
|
+
end
|
37
|
+
|
38
|
+
it "parses the json response" do
|
39
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
40
|
+
subject
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when given status 401' do
|
44
|
+
let(:status) { 401 }
|
45
|
+
|
46
|
+
it "throws an unauthorized error" do
|
47
|
+
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when given status 404' do
|
52
|
+
let(:status) { 404 }
|
53
|
+
|
54
|
+
it "throws a not found error" do
|
55
|
+
expect { subject }.to raise_exception SearchKit::Errors::IndexNotFound
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#create' do
|
61
|
+
let(:name) { "name" }
|
62
|
+
|
63
|
+
let(:params) do
|
64
|
+
{ token: token, data: { type: 'indices', attributes: { name: name } } }
|
65
|
+
end
|
66
|
+
|
67
|
+
subject { client.create(name) }
|
68
|
+
|
69
|
+
it "calls #connection.post with given name" do
|
70
|
+
expect(client.connection).to receive(:post).with('', params)
|
71
|
+
subject
|
72
|
+
end
|
73
|
+
|
74
|
+
it "parses the json response" do
|
75
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
76
|
+
subject
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when given status 400' do
|
80
|
+
let(:status) { 400 }
|
81
|
+
|
82
|
+
it "throws a Bad Request error" do
|
83
|
+
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
|
84
|
+
end
|
85
|
+
end
|
86
|
+
context 'when given status 401' do
|
87
|
+
let(:status) { 401 }
|
88
|
+
|
89
|
+
it "throws an unauthorized error" do
|
90
|
+
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when given status 422' do
|
95
|
+
let(:status) { 422 }
|
96
|
+
|
97
|
+
it "throws an Unprocessable error" do
|
98
|
+
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#show' do
|
105
|
+
let(:slug) { "slug" }
|
106
|
+
|
107
|
+
subject { client.show(slug) }
|
108
|
+
|
109
|
+
it "calls #connection.get with given slug" do
|
110
|
+
expect(client.connection).to receive(:get).with(slug, token: token)
|
111
|
+
subject
|
112
|
+
end
|
113
|
+
|
114
|
+
it "parses the json response" do
|
115
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
116
|
+
subject
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when given status 401' do
|
120
|
+
let(:status) { 401 }
|
121
|
+
|
122
|
+
it "throws an unauthorized error" do
|
123
|
+
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when given status 404' do
|
128
|
+
let(:status) { 404 }
|
129
|
+
|
130
|
+
it "throws a not found error" do
|
131
|
+
expect { subject }.to raise_exception SearchKit::Errors::IndexNotFound
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#update' do
|
138
|
+
let(:new_name) { "New name" }
|
139
|
+
let(:slug) { "name" }
|
140
|
+
|
141
|
+
let(:params) do
|
142
|
+
{
|
143
|
+
token: token,
|
144
|
+
data: { type: 'indices', attributes: { name: new_name } }
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
subject { client.update(slug, name: new_name) }
|
149
|
+
|
150
|
+
it "calls #connection.patch with given slug and attributes" do
|
151
|
+
expect(client.connection).to receive(:patch).with(slug, params)
|
152
|
+
subject
|
153
|
+
end
|
154
|
+
|
155
|
+
it "parses the json response" do
|
156
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
157
|
+
subject
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when given status 400' do
|
161
|
+
let(:status) { 400 }
|
162
|
+
|
163
|
+
it "throws a bad request error" do
|
164
|
+
expect { subject }.to raise_exception SearchKit::Errors::BadRequest
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'when given status 401' do
|
169
|
+
let(:status) { 401 }
|
170
|
+
|
171
|
+
it "throws an unauthorized error" do
|
172
|
+
expect { subject }.to raise_exception SearchKit::Errors::Unauthorized
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when given status 404' do
|
177
|
+
let(:status) { 404 }
|
178
|
+
|
179
|
+
it "throws a not found error" do
|
180
|
+
expect { subject }.to raise_exception SearchKit::Errors::IndexNotFound
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when given status 422' do
|
185
|
+
let(:status) { 422 }
|
186
|
+
|
187
|
+
it "throws an unprocessable error" do
|
188
|
+
expect { subject }.to raise_exception SearchKit::Errors::Unprocessable
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|