Permalink
Browse files
Add another test case for when video has been published for less than…
- Loading branch information...
Showing
with
21 additions
and
0 deletions.
-
+21
−0
refactoring_external_service/youtube_video_list_spec.rb
|
@@ -49,4 +49,25 @@ def test_when_views_unchanged_for_one_month |
|
|
|
assert_in_delta(expected[0]['monthlyViews'], actual[0]['monthlyViews'], 0.1) |
|
|
|
end |
|
|
|
|
|
|
|
def test_when_one_day_has_passed |
|
|
|
video_repo_response = [{'youtubeID' => 'blahblahblah', 'views' => 0, 'monthlyViews' => 0}] |
|
|
|
youtube_client_response = {'items' => |
|
|
|
[ |
|
|
|
{ |
|
|
|
'id' =>'blahblahblah', |
|
|
|
'statistics' => {'viewCount' => '3'}, |
|
|
|
'snippet' => {'publishedAt' => (Date.today - 29).to_s } |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
video_service = VideoService.new( |
|
|
|
video_repo: VideoRepoStub.new(video_repo_response), |
|
|
|
video_client: YoutubeVideoClientStub.new(youtube_client_response) |
|
|
|
) |
|
|
|
actual = JSON.parse(video_service.video_list) |
|
|
|
assert_equal(3, actual[0]['views']) |
|
|
|
# I'm making an assumption here that when the video has been out less than 30 days, |
|
|
|
# the monthlyViews should be just the total views |
|
|
|
assert_equal(3, actual[0]['monthlyViews']) |
|
|
|
end |
|
|
|
end
|
I see you're breaking your test contexts into "x" # of days that have passed now... What's that about?! What did you discover?