Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit 1d38b33

Browse files
committed
Add another test case for when video has been published for less than 30 days
1 parent 72de92f commit 1d38b33

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

refactoring_external_service/youtube_video_list_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,25 @@ def test_when_views_unchanged_for_one_month
4949
assert_in_delta(expected[0]['monthlyViews'], actual[0]['monthlyViews'], 0.1)
5050
end
5151

52+
def test_when_one_day_has_passed
53+
video_repo_response = [{'youtubeID' => 'blahblahblah', 'views' => 0, 'monthlyViews' => 0}]
54+
youtube_client_response = {'items' =>
55+
[
56+
{
57+
'id' =>'blahblahblah',
58+
'statistics' => {'viewCount' => '3'},
59+
'snippet' => {'publishedAt' => (Date.today - 29).to_s }
60+
}
61+
]
62+
}
63+
video_service = VideoService.new(
64+
video_repo: VideoRepoStub.new(video_repo_response),
65+
video_client: YoutubeVideoClientStub.new(youtube_client_response)
66+
)
67+
actual = JSON.parse(video_service.video_list)
68+
assert_equal(3, actual[0]['views'])
69+
# I'm making an assumption here that when the video has been out less than 30 days,
70+
# the monthlyViews should be just the total views
71+
assert_equal(3, actual[0]['monthlyViews'])
72+
end
5273
end

0 commit comments

Comments
 (0)