search-kit 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- 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
Binary file
|
data/search-kit.gemspec
CHANGED
@@ -14,23 +14,18 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/qbox-io/search-kit"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
spec.
|
17
|
+
spec.files = Dir.glob('**/*')
|
18
|
+
spec.test_files = Dir.glob('spec/**/*')
|
18
19
|
spec.require_paths = ["lib"]
|
19
20
|
|
20
|
-
spec.
|
21
|
-
file.match(%r{^(test|spec|features)/})
|
22
|
-
end
|
23
|
-
|
24
|
-
spec.executables = spec.files.grep(%r{^bin/}) do |file|
|
25
|
-
File.basename(file)
|
26
|
-
end
|
21
|
+
spec.executables << 'search-kit'
|
27
22
|
|
28
23
|
spec.add_dependency "ansi", "~> 1.5"
|
29
24
|
spec.add_dependency "faraday", "~> 0.9"
|
30
|
-
spec.add_dependency "thor", "~> 0.19"
|
31
|
-
spec.add_dependency "user_config", "~> 0.0"
|
32
25
|
spec.add_dependency "highline", "~> 1.7"
|
33
26
|
spec.add_dependency "i18n", "~> 0.7"
|
27
|
+
spec.add_dependency "thor", "~> 0.19"
|
28
|
+
spec.add_dependency "user_config", "~> 0.0"
|
34
29
|
spec.add_dependency "virtus", "~> 1.0"
|
35
30
|
|
36
31
|
spec.add_development_dependency "bundler", "~> 1.8"
|
@@ -40,5 +35,4 @@ Gem::Specification.new do |spec|
|
|
40
35
|
spec.add_development_dependency "rack-test", "~> 0.6"
|
41
36
|
spec.add_development_dependency "simplecov", "~> 0.10"
|
42
37
|
spec.add_development_dependency "ruby-prof", "~> 0.15"
|
43
|
-
|
44
38
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Modeling incoming subscriber data" do
|
4
|
+
let(:subscriber_id) { "5659f64d21de3bfe6c000004" }
|
5
|
+
let(:subscriber_email) { "joseph@qbox.io" }
|
6
|
+
let(:subscriber_uri) { "/api/subscribers" }
|
7
|
+
|
8
|
+
let(:key_token) { "2bad61a9ea4f5adf1d36952e59ddda2b" }
|
9
|
+
let(:key_name) { "Universal access key" }
|
10
|
+
let(:key_id) { "5659f64d21de3bfe6c000005" }
|
11
|
+
let(:key_uri) { "/api/keys/5659f64d21de3bfe6c000005" }
|
12
|
+
|
13
|
+
let(:response) do
|
14
|
+
{
|
15
|
+
data: {
|
16
|
+
type: "subscribers",
|
17
|
+
id: subscriber_id,
|
18
|
+
attributes: { id: subscriber_id, email: subscriber_email },
|
19
|
+
links: { self: subscriber_uri },
|
20
|
+
relationships: {
|
21
|
+
keys: [
|
22
|
+
{
|
23
|
+
type: "keys",
|
24
|
+
id: key_id,
|
25
|
+
attributes: {
|
26
|
+
id: key_id,
|
27
|
+
name: key_name,
|
28
|
+
token: key_token,
|
29
|
+
privilege: "creator"
|
30
|
+
},
|
31
|
+
links: { self: key_uri }
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:subscriber) do
|
40
|
+
SearchKit::Models::Subscriber.new(response.fetch(:data))
|
41
|
+
end
|
42
|
+
|
43
|
+
subject { subscriber }
|
44
|
+
|
45
|
+
describe '#creator_tokens' do
|
46
|
+
subject { subscriber.creator_tokens.first }
|
47
|
+
it { is_expected.to eq key_token }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#email' do
|
51
|
+
subject { subscriber.email }
|
52
|
+
it { is_expected.to eq subscriber_email }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#id' do
|
56
|
+
subject { subscriber.id }
|
57
|
+
it { is_expected.to eq subscriber_id }
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#keys' do
|
61
|
+
let(:key) { subscriber.keys.first }
|
62
|
+
|
63
|
+
subject { key }
|
64
|
+
|
65
|
+
describe '#id' do
|
66
|
+
subject { key.id }
|
67
|
+
it { is_expected.to eq key_id }
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#name' do
|
71
|
+
subject { key.name }
|
72
|
+
it { is_expected.to eq key_name }
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#token' do
|
76
|
+
subject { key.token }
|
77
|
+
it { is_expected.to eq key_token }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#uri' do
|
81
|
+
subject { key.uri }
|
82
|
+
it { is_expected.to eq key_uri }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#uri' do
|
87
|
+
subject { subscriber.uri }
|
88
|
+
it { is_expected.to eq subscriber_uri }
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::CLI::Documents do
|
4
|
+
let(:cli) { described_class.new }
|
5
|
+
let(:json) { response.to_json }
|
6
|
+
let(:response) { {} }
|
7
|
+
let(:slug) { "an-index-slug" }
|
8
|
+
|
9
|
+
subject { cli }
|
10
|
+
|
11
|
+
describe '#create' do
|
12
|
+
before { allow(cli.client).to receive(:create).and_return(response) }
|
13
|
+
|
14
|
+
subject { cli.create(slug, json) }
|
15
|
+
|
16
|
+
it "parses the given document json" do
|
17
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
18
|
+
subject
|
19
|
+
end
|
20
|
+
|
21
|
+
it "calls client.create with the slug and document" do
|
22
|
+
expect(cli.client).to receive(:create).with(slug, {})
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
|
26
|
+
it "reports on its results" do
|
27
|
+
expect(cli.messages).to receive(:info).with(response.to_json)
|
28
|
+
subject
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when given bad json' do
|
32
|
+
let(:json) { "Arglebargle" }
|
33
|
+
it "reports an error" do
|
34
|
+
expect(cli.messages).to receive(:json_parse_error)
|
35
|
+
subject
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'error handling' do
|
40
|
+
before { allow(cli.client).to receive(:create).and_raise(*error) }
|
41
|
+
|
42
|
+
context 'not found error' do
|
43
|
+
let(:error) { SearchKit::Errors::IndexNotFound }
|
44
|
+
|
45
|
+
it do
|
46
|
+
expect(cli.messages).to receive(:not_found)
|
47
|
+
subject
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'bad request error' do
|
52
|
+
let(:error) { SearchKit::Errors::BadRequest }
|
53
|
+
|
54
|
+
it do
|
55
|
+
expect(cli.messages).to receive(:bad_request)
|
56
|
+
subject
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'unprocessable error' do
|
61
|
+
let(:error) { SearchKit::Errors::Unprocessable }
|
62
|
+
|
63
|
+
it do
|
64
|
+
expect(cli.messages).to receive(:unprocessable)
|
65
|
+
subject
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'not found error' do
|
70
|
+
let(:error) { [Faraday::ConnectionFailed, "Message"] }
|
71
|
+
|
72
|
+
it do
|
73
|
+
expect(cli.messages).to receive(:no_service)
|
74
|
+
subject
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#delete' do
|
82
|
+
let(:id) { 1 }
|
83
|
+
|
84
|
+
before { allow(cli.client).to receive(:delete).and_return(response) }
|
85
|
+
|
86
|
+
subject { cli.delete(slug, id) }
|
87
|
+
|
88
|
+
it "calls client.create with the slug and document" do
|
89
|
+
expect(cli.client).to receive(:delete).with(slug, id)
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
|
93
|
+
it "reports on its results" do
|
94
|
+
expect(cli.messages).to receive(:info).with(response.to_json)
|
95
|
+
subject
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'error handling' do
|
99
|
+
before { allow(cli.client).to receive(:delete).and_raise(*error) }
|
100
|
+
|
101
|
+
context 'not found error' do
|
102
|
+
let(:error) { SearchKit::Errors::IndexNotFound }
|
103
|
+
|
104
|
+
it do
|
105
|
+
expect(cli.messages).to receive(:not_found)
|
106
|
+
subject
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'not found error' do
|
111
|
+
let(:error) { [Faraday::ConnectionFailed, "Message"] }
|
112
|
+
|
113
|
+
it do
|
114
|
+
expect(cli.messages).to receive(:no_service)
|
115
|
+
subject
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#show' do
|
123
|
+
let(:id) { 1 }
|
124
|
+
|
125
|
+
before { allow(cli.client).to receive(:show).and_return(response) }
|
126
|
+
|
127
|
+
subject { cli.show(slug, id) }
|
128
|
+
|
129
|
+
it "calls client.create with the slug and document" do
|
130
|
+
expect(cli.client).to receive(:show).with(slug, id)
|
131
|
+
subject
|
132
|
+
end
|
133
|
+
|
134
|
+
it "reports on its results" do
|
135
|
+
expect(cli.messages).to receive(:info).with(response.to_json)
|
136
|
+
subject
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'error handling' do
|
140
|
+
before { allow(cli.client).to receive(:show).and_raise(*error) }
|
141
|
+
|
142
|
+
context 'not found error' do
|
143
|
+
let(:error) { SearchKit::Errors::IndexNotFound }
|
144
|
+
|
145
|
+
it do
|
146
|
+
expect(cli.messages).to receive(:not_found)
|
147
|
+
subject
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'not found error' do
|
152
|
+
let(:error) { [Faraday::ConnectionFailed, "Message"] }
|
153
|
+
|
154
|
+
it do
|
155
|
+
expect(cli.messages).to receive(:no_service)
|
156
|
+
subject
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#update' do
|
164
|
+
let(:id) { 1 }
|
165
|
+
|
166
|
+
before { allow(cli.client).to receive(:update).and_return(response) }
|
167
|
+
|
168
|
+
subject { cli.update(slug, id, json) }
|
169
|
+
|
170
|
+
it "parses the given document json" do
|
171
|
+
expect(JSON).to receive(:parse).with(json, symbolize_names: true)
|
172
|
+
subject
|
173
|
+
end
|
174
|
+
|
175
|
+
it "calls client.create with the slug and document" do
|
176
|
+
expect(cli.client).to receive(:update).with(slug, id, {})
|
177
|
+
subject
|
178
|
+
end
|
179
|
+
|
180
|
+
it "reports on its results" do
|
181
|
+
expect(cli.messages).to receive(:info).with(response.to_json)
|
182
|
+
subject
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when given bad json' do
|
186
|
+
let(:json) { "Arglebargle" }
|
187
|
+
it "reports an error" do
|
188
|
+
expect(cli.messages).to receive(:json_parse_error)
|
189
|
+
subject
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'error handling' do
|
194
|
+
before { allow(cli.client).to receive(:update).and_raise(*error) }
|
195
|
+
|
196
|
+
context 'not found error' do
|
197
|
+
let(:error) { SearchKit::Errors::IndexNotFound }
|
198
|
+
|
199
|
+
it do
|
200
|
+
expect(cli.messages).to receive(:not_found)
|
201
|
+
subject
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'bad request error' do
|
206
|
+
let(:error) { SearchKit::Errors::BadRequest }
|
207
|
+
|
208
|
+
it do
|
209
|
+
expect(cli.messages).to receive(:bad_request)
|
210
|
+
subject
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'unprocessable error' do
|
215
|
+
let(:error) { SearchKit::Errors::Unprocessable }
|
216
|
+
|
217
|
+
it do
|
218
|
+
expect(cli.messages).to receive(:unprocessable)
|
219
|
+
subject
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'not found error' do
|
224
|
+
let(:error) { [Faraday::ConnectionFailed, "Message"] }
|
225
|
+
|
226
|
+
it do
|
227
|
+
expect(cli.messages).to receive(:no_service)
|
228
|
+
subject
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,243 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SearchKit::CLI::Events do
|
4
|
+
let(:channel) { "colon:separated:values" }
|
5
|
+
let(:cli) { described_class.new }
|
6
|
+
let(:json) { response.to_json }
|
7
|
+
let(:response) { {} }
|
8
|
+
let(:event) { SearchKit::Models::Event.new }
|
9
|
+
let(:events) { SearchKit::Models::Events.new }
|
10
|
+
let(:slug) { "an-index-slug" }
|
11
|
+
|
12
|
+
subject { cli }
|
13
|
+
|
14
|
+
describe '#complete' do
|
15
|
+
let(:id) { 1 }
|
16
|
+
|
17
|
+
before { allow(cli.client).to receive(:complete).and_return(event) }
|
18
|
+
|
19
|
+
subject { cli.complete(id) }
|
20
|
+
|
21
|
+
it "calls client.complete with the event id" do
|
22
|
+
expect(cli.client).to receive(:complete).with(id)
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
|
26
|
+
it "reports on its results" do
|
27
|
+
expect(cli.messages).to receive(:info).with(an_instance_of(String))
|
28
|
+
subject
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'error handling' do
|
32
|
+
before { allow(cli.client).to receive(:complete).and_raise(*error) }
|
33
|
+
|
34
|
+
context 'not found error' do
|
35
|
+
let(:error) { SearchKit::Errors::EventNotFound }
|
36
|
+
|
37
|
+
it do
|
38
|
+
expect(cli.messages).to receive(:not_found)
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'not found error' do
|
44
|
+
let(:error) { [Faraday::ConnectionFailed, "Message"] }
|
45
|
+
|
46
|
+
it do
|
47
|
+
expect(cli.messages).to receive(:no_service)
|
48
|
+
subject
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#pending' do
|
55
|
+
before do
|
56
|
+
allow(cli.client).to receive(:index).and_return(events)
|
57
|
+
allow(cli.client).to receive(:pending).and_return(events)
|
58
|
+
end
|
59
|
+
|
60
|
+
subject { cli.pending(channel) }
|
61
|
+
|
62
|
+
context 'when given a channel' do
|
63
|
+
it "calls client.pending with the channel" do
|
64
|
+
expect(cli.client).to receive(:pending).with(channel)
|
65
|
+
subject
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'otherwise' do
|
70
|
+
let(:channel) { nil }
|
71
|
+
|
72
|
+
it "calls client.index" do
|
73
|
+
expect(cli.client).to receive(:index)
|
74
|
+
subject
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "reports on its results" do
|
79
|
+
expect(cli.messages).to receive(:info).with(an_instance_of(String))
|
80
|
+
subject
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'error handling' do
|
84
|
+
before do
|
85
|
+
allow(cli.client).to receive(:index).and_raise(*error)
|
86
|
+
allow(cli.client).to receive(:pending).and_raise(*error)
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'not found error' do
|
90
|
+
let(:error) { SearchKit::Errors::Unauthorized }
|
91
|
+
|
92
|
+
it do
|
93
|
+
expect(cli.messages).to receive(:unauthorized)
|
94
|
+
subject
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'bad request error' do
|
99
|
+
let(:error) { SearchKit::Errors::BadRequest }
|
100
|
+
|
101
|
+
it do
|
102
|
+
expect(cli.messages).to receive(:bad_request)
|
103
|
+
subject
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'unprocessable error' do
|
108
|
+
let(:error) { SearchKit::Errors::Unprocessable }
|
109
|
+
|
110
|
+
it do
|
111
|
+
expect(cli.messages).to receive(:unprocessable)
|
112
|
+
subject
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'not found error' do
|
117
|
+
let(:error) { [Faraday::ConnectionFailed, "Message"] }
|
118
|
+
|
119
|
+
it do
|
120
|
+
expect(cli.messages).to receive(:no_service)
|
121
|
+
subject
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#publish' do
|
129
|
+
let(:payload) { { one_fish: true, two_fish: true } }
|
130
|
+
let(:payload_json) { payload.to_json }
|
131
|
+
|
132
|
+
before do
|
133
|
+
allow(cli.client).to receive(:publish).and_return(event)
|
134
|
+
end
|
135
|
+
|
136
|
+
subject { cli.publish(channel, payload_json) }
|
137
|
+
|
138
|
+
it "parses the given document json" do
|
139
|
+
expect(JSON).to receive(:parse).with(payload_json, symbolize_names: true)
|
140
|
+
subject
|
141
|
+
end
|
142
|
+
|
143
|
+
it "calls client.create with the slug and document" do
|
144
|
+
expect(cli.client).to receive(:publish).with(channel, payload)
|
145
|
+
subject
|
146
|
+
end
|
147
|
+
|
148
|
+
it "reports on its results" do
|
149
|
+
expect(cli.messages).to receive(:info).with(an_instance_of(String))
|
150
|
+
subject
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when given bad json' do
|
154
|
+
let(:payload) { "Arglebargle" }
|
155
|
+
|
156
|
+
it "reports an error" do
|
157
|
+
expect(cli.messages).to receive(:json_parse_error)
|
158
|
+
subject
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'error handling' do
|
163
|
+
before { allow(cli.client).to receive(:publish).and_raise(*error) }
|
164
|
+
|
165
|
+
context 'not found error' do
|
166
|
+
let(:error) { SearchKit::Errors::Unauthorized }
|
167
|
+
|
168
|
+
it do
|
169
|
+
expect(cli.messages).to receive(:unauthorized)
|
170
|
+
subject
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'bad request error' do
|
175
|
+
let(:error) { SearchKit::Errors::BadRequest }
|
176
|
+
|
177
|
+
it do
|
178
|
+
expect(cli.messages).to receive(:bad_request)
|
179
|
+
subject
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'unprocessable error' do
|
184
|
+
let(:error) { SearchKit::Errors::Unprocessable }
|
185
|
+
|
186
|
+
it do
|
187
|
+
expect(cli.messages).to receive(:unprocessable)
|
188
|
+
subject
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'not found error' do
|
193
|
+
let(:error) { [Faraday::ConnectionFailed, "Message"] }
|
194
|
+
|
195
|
+
it do
|
196
|
+
expect(cli.messages).to receive(:no_service)
|
197
|
+
subject
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe '#status' do
|
205
|
+
let(:id) { 1 }
|
206
|
+
|
207
|
+
before { allow(cli.client).to receive(:show).and_return(event) }
|
208
|
+
|
209
|
+
subject { cli.status(id) }
|
210
|
+
|
211
|
+
it "calls client.show with the event id" do
|
212
|
+
expect(cli.client).to receive(:show).with(id)
|
213
|
+
subject
|
214
|
+
end
|
215
|
+
|
216
|
+
it "reports on its results" do
|
217
|
+
expect(cli.messages).to receive(:info).with(an_instance_of(String))
|
218
|
+
subject
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'error handling' do
|
222
|
+
before { allow(cli.client).to receive(:show).and_raise(*error) }
|
223
|
+
|
224
|
+
context 'not found error' do
|
225
|
+
let(:error) { SearchKit::Errors::EventNotFound }
|
226
|
+
|
227
|
+
it do
|
228
|
+
expect(cli.messages).to receive(:not_found)
|
229
|
+
subject
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'not found error' do
|
234
|
+
let(:error) { [Faraday::ConnectionFailed, "Message"] }
|
235
|
+
|
236
|
+
it do
|
237
|
+
expect(cli.messages).to receive(:no_service)
|
238
|
+
subject
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|