Skip to content

Commit f7d2cd8

Browse files
committed
added a couple more tests
1 parent 8e5dff3 commit f7d2cd8

File tree

5 files changed

+81
-21
lines changed

5 files changed

+81
-21
lines changed

spec/shared/ex_bad_response.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def make_request(**kwargs)
7474
end
7575
end
7676

77-
context 'if the response is not json' do
77+
context 'if the bad response is not json' do
7878
let(:response) {{
7979
body: '<html>wtf</html>',
8080
status: 503
@@ -90,5 +90,18 @@ def make_request(**kwargs)
9090
}
9191
end
9292
end
93+
94+
context 'if the response is not json, but has a 2xx status' do
95+
let(:response) {{ body: 'ok', status: 201, headers: { 'Content-Type': 'text/plain' }}}
96+
97+
it 'should not raise an error' do
98+
expect { make_request }.to_not raise_error
99+
end
100+
101+
it 'should return the body as a string' do
102+
result = make_request
103+
result.should == 'ok'
104+
end
105+
end
93106
end
94107
end

spec/shared/ex_fetch_all.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,59 @@
205205
end
206206
end
207207

208+
context 'when an empty page is received, but with a cursor' do
209+
before do
210+
stub_fetch_all("https://#{host}/xrpc/com.example.service.fetchAll", [
211+
{ "feed": ["one", "two", "three"] },
212+
{ "feed": [] },
213+
{ "feed": ["six"] },
214+
])
215+
end
216+
217+
it 'should continue fetching until the cursor is nil' do
218+
result = subject.fetch_all('com.example.service.fetchAll', field: 'feed')
219+
result.should == ['one', 'two', 'three', 'six']
220+
end
221+
end
222+
223+
context 'when field is not passed' do
224+
before do
225+
stub_fetch_all("https://#{host}/xrpc/com.example.service.fetchAll", [
226+
{ "thingies": ["one", "two", "three"], "best": "two", "foobars": ["foo", "bar"], "total": 6 },
227+
{ "items": ["four", "five"] },
228+
])
229+
end
230+
231+
it 'should make one request and raise an error with list of array fields' do
232+
expect { subject.fetch_all('com.example.service.fetchAll') }.to raise_error { |err|
233+
err.should be_a(Minisky::FieldNotSetError)
234+
err.fields.should == ['thingies', 'foobars']
235+
}
236+
237+
WebMock.should have_requested(:get, @stubbed_urls[0]).once
238+
WebMock.should_not have_requested(:get, @stubbed_urls[1])
239+
end
240+
end
241+
242+
context 'when field is nil' do
243+
before do
244+
stub_fetch_all("https://#{host}/xrpc/com.example.service.fetchAll", [
245+
{ "thingies": ["one", "two", "three"], "best": "two", "foobars": ["foo", "bar"], "total": 6 },
246+
{ "items": ["four", "five"] },
247+
])
248+
end
249+
250+
it 'should make one request and raise an error with list of array fields' do
251+
expect { subject.fetch_all('com.example.service.fetchAll', field: nil) }.to raise_error { |err|
252+
err.should be_a(Minisky::FieldNotSetError)
253+
err.fields.should == ['thingies', 'foobars']
254+
}
255+
256+
WebMock.should have_requested(:get, @stubbed_urls[0]).once
257+
WebMock.should_not have_requested(:get, @stubbed_urls[1])
258+
end
259+
end
260+
208261
describe 'progress param' do
209262
before do
210263
stub_request(:get, "https://#{host}/xrpc/com.example.service.fetchAll")

spec/shared/ex_post_request.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,26 +216,6 @@
216216
end
217217
end
218218

219-
context 'if the response has a 4xx status' do
220-
let(:response) {{ body: '{ "error": "message" }', status: 403, headers: { 'Content-Type': 'application/json' }}}
221-
222-
it 'should raise an error' do
223-
expect { subject.post_request('com.example.service.doStuff') }.to raise_error(Minisky::ClientErrorResponse)
224-
end
225-
end
226-
227-
context 'if the response has a 2xx status, but the response is not json' do
228-
let(:response) {{ body: 'ok', status: 201, headers: { 'Content-Type': 'text/plain' }}}
229-
230-
it 'should not raise an error' do
231-
expect { subject.post_request('com.example.service.doStuff') }.to_not raise_error
232-
end
233-
234-
it 'should return the body as a string' do
235-
subject.post_request('com.example.service.doStuff').should == 'ok'
236-
end
237-
end
238-
239219
include_examples "bad response handling", :post, 'com.example.service.doStuff'
240220

241221
include_examples "authorization",

spec/shared/ex_requests.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@
143143
config['access_token'].should be_nil
144144
config['refresh_token'].should be_nil
145145
end
146+
147+
context 'if tokens are already nil' do
148+
it 'should not raise error' do
149+
subject.reset_tokens
150+
151+
expect { subject.reset_tokens }.not_to raise_error
152+
end
153+
end
146154
end
147155

148156
include_examples "get_request"

spec/shared/ex_unauthed.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
end
2020
end
2121

22+
describe '#reset_tokens' do
23+
it 'should raise AuthError' do
24+
expect { subject.reset_tokens }.to raise_error(Minisky::AuthError)
25+
end
26+
end
27+
2228
context '#user' do
2329
it 'should return nil' do
2430
subject.user.should be_nil

0 commit comments

Comments
 (0)