|
6 | 6 | class VideoServiceTest < MiniTest::Test |
7 | 7 |
|
8 | 8 | class VideoRepoStub |
| 9 | + attr_reader :canned_response |
| 10 | + def initialize(canned_response) |
| 11 | + @canned_response = canned_response |
| 12 | + end |
9 | 13 | def videos |
10 | | - [{'youtubeID' => 'blahblahblah', 'views' => 3, 'monthlyViews' => 3}] |
| 14 | + canned_response |
11 | 15 | end |
12 | 16 | end |
13 | 17 |
|
14 | 18 | class YoutubeVideoClientStub |
15 | | - def video_stats(ids=:NotGiven) |
16 | | - {'items' => |
17 | | - [ |
18 | | - { |
19 | | - 'id' =>'blahblahblah', |
20 | | - 'statistics' => {'viewCount' => '3'}, |
21 | | - 'snippet' => {'publishedAt' => (Date.today - 30).to_s } |
22 | | - } |
23 | | - ] |
24 | | - } |
| 19 | + attr_reader :canned_response |
| 20 | + def initialize(canned_response) |
| 21 | + @canned_response = canned_response |
| 22 | + end |
| 23 | + |
| 24 | + def video_stats(ids=:NotGivenToStub) |
| 25 | + canned_response |
25 | 26 | end |
26 | 27 | end |
27 | 28 |
|
28 | 29 | def test_video_list_returns_video_list |
29 | | - video_service = VideoService.new(video_repo: VideoRepoStub.new, video_client: YoutubeVideoClientStub.new) |
30 | | - video_array = [{'youtubeID' => 'blahblahblah', 'views' => 3, 'monthlyViews' => 3}] |
31 | | - video_json = JSON.generate(video_array) |
| 30 | + video_repo_response = [{'youtubeID' => 'blahblahblah', 'views' => 3, 'monthlyViews' => 3}] |
| 31 | + youtube_client_response = {'items' => |
| 32 | + [ |
| 33 | + { |
| 34 | + 'id' =>'blahblahblah', |
| 35 | + 'statistics' => {'viewCount' => '3'}, |
| 36 | + 'snippet' => {'publishedAt' => (Date.today - 30).to_s } |
| 37 | + } |
| 38 | + ] |
| 39 | + } |
| 40 | + video_service = VideoService.new( |
| 41 | + video_repo: VideoRepoStub.new(video_repo_response), |
| 42 | + video_client: YoutubeVideoClientStub.new(youtube_client_response) |
| 43 | + ) |
| 44 | + video_json = JSON.generate(video_repo_response) |
32 | 45 |
|
33 | 46 | result = JSON.parse(video_service.video_list) |
34 | 47 | actual = JSON.parse(video_json) |
|
0 commit comments