Skip to content

Commit 429ffeb

Browse files
committed
Add a test for multiple series_ids
1 parent d262595 commit 429ffeb

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

spec/lib/event_service/providers/connpass_spec.rb

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,53 @@
99

1010
it do
1111
expect(subject).to be_instance_of(Hash)
12-
expect(subject['results_returned']).to eq 1
13-
expect(subject['events'].size).to eq 1
12+
expect(subject['results_returned']).to eq 2
1413
expect(subject['events'].first['event_id']).to eq 12345
1514
expect(subject['events'].first['series']['url']).to eq 'https://coderdojo-okutama.connpass.com/'
1615
expect(subject['events'].first['series']['id']).to eq 9876
16+
expect(subject['events'].second['event_id']).to eq 12346 # assuming the second event has id 12346
17+
expect(subject['events'].second['series']['url']).to eq 'https://coderdojo-okutama2.connpass.com/'
18+
expect(subject['events'].second['series']['id']).to eq 9877
1719
end
18-
end
20+
end
1921

2022
describe '#fetch_events' do
21-
subject { described_class.new.fetch_events(series_id: 9876) }
23+
context 'when a single series_id is given' do
24+
before do
25+
# Thread.currentを使用してテストのコンテキスト間でデータを共有する
26+
Thread.current[:series_ids] = [9876]
27+
end
2228

23-
it do
24-
expect(subject).to be_instance_of(Array)
25-
expect(subject.size).to eq 1
26-
expect(subject.first['event_id']).to eq 12345
27-
expect(subject.first['series']['url']).to eq 'https://coderdojo-okutama.connpass.com/'
28-
expect(subject.first['series']['id']).to eq 9876
29+
subject { described_class.new.fetch_events(series_id: 9876) }
30+
31+
it do
32+
expect(subject).to be_instance_of(Array)
33+
expect(subject.size).to eq 1
34+
expect(subject.first['event_id']).to eq 12345
35+
expect(subject.first['series']['url']).to eq 'https://coderdojo-okutama.connpass.com/'
36+
expect(subject.first['series']['id']).to eq 9876
37+
end
38+
end
39+
40+
context 'when multiple series_ids are given' do
41+
before do
42+
# Thread.currentを使用してテストのコンテキスト間でデータを共有する
43+
Thread.current[:series_ids] = [9876, 9877]
44+
end
45+
46+
subject { described_class.new.fetch_events(series_id: [9876, 9877]) }
47+
48+
# Here, you need to modify connpass_response to return multiple events for different series_ids
49+
it do
50+
expect(subject).to be_instance_of(Array)
51+
expect(subject.size).to eq 2
52+
expect(subject.first['event_id']).to eq 12345
53+
expect(subject.first['series']['url']).to eq 'https://coderdojo-okutama.connpass.com/'
54+
expect(subject.first['series']['id']).to eq 9876
55+
expect(subject.second['event_id']).to eq 12346 # assuming the second event has id 12346
56+
expect(subject.second['series']['url']).to eq 'https://coderdojo-okutama2.connpass.com/'
57+
expect(subject.second['series']['id']).to eq 9877
58+
end
2959
end
3060
end
3161
end

spec/support/shared_contexts/statistics.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@
2222
include_context 'Use stub connection of Faraday'
2323

2424
let(:connpass_response) do
25-
[
26-
200,
27-
{ 'Content-Type' => 'application/json' },
28-
'{"results_returned": 1, "events": [{"event_url": "https://coderdojo-okutama.connpass.com/event/12345/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama.connpass.com/", "id": 9876, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12345, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"}], "results_start": 200, "results_available": 518}'
29-
]
25+
if Thread.current[:series_ids] == [9876]
26+
# response for single series_id 9876
27+
[
28+
200,
29+
{ 'Content-Type' => 'application/json' },
30+
'{"results_returned": 1, "events": [{"event_url": "https://coderdojo-okutama.connpass.com/event/12345/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama.connpass.com/", "id": 9876, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12345, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"}], "results_start": 200, "results_available": 518}'
31+
]
32+
else
33+
# response for multiple series_ids 9876 and 9877
34+
[
35+
200,
36+
{ 'Content-Type' => 'application/json' },
37+
'{"results_returned": 2, "events": [{"event_url": "https://coderdojo-okutama.connpass.com/event/12345/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama.connpass.com/", "id": 9876, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12345, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"},{"event_url": "https://coderdojo-okutama.connpass.com/event/12346/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama2.connpass.com/", "id": 9877, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12346, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"}], "results_start": 200, "results_available": 518}'
38+
]
39+
end
3040
end
3141
end
3242

0 commit comments

Comments
 (0)