ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

94 lines
2.5 KiB

  1. require 'rails_helper'
  2. RSpec.describe Youtube::VideoItem do
  3. describe '#initialize' do
  4. it 'extracts fields from YouTube video API item' do
  5. item = {
  6. 'id' => 'video-1',
  7. 'snippet' => {
  8. 'title' => 'テスト動画',
  9. 'channelId' => 'UC123',
  10. 'publishedAt' => '2026-05-01T12:34:56Z',
  11. 'tags' => ['tag-a', 'tag-b'],
  12. 'thumbnails' => {
  13. 'high' => {
  14. 'url' => 'https://img.youtube.com/high.jpg'
  15. },
  16. 'medium' => {
  17. 'url' => 'https://img.youtube.com/medium.jpg'
  18. }
  19. }
  20. }
  21. }
  22. video = described_class.new(item)
  23. expect(video.id).to eq('video-1')
  24. expect(video.title).to eq('テスト動画')
  25. expect(video.channel_id).to eq('UC123')
  26. expect(video.published_at).to eq(Time.iso8601('2026-05-01T12:34:56Z'))
  27. expect(video.thumbnail_url).to eq('https://img.youtube.com/high.jpg')
  28. expect(video.raw_tags).to eq(['tag-a', 'tag-b'])
  29. expect(video.url).to eq('https://www.youtube.com/watch?v=video-1')
  30. end
  31. it 'uses highest priority thumbnail' do
  32. item = {
  33. 'id' => 'video-1',
  34. 'snippet' => {
  35. 'title' => 'テスト動画',
  36. 'channelId' => 'UC123',
  37. 'publishedAt' => '2026-05-01T12:34:56Z',
  38. 'thumbnails' => {
  39. 'default' => {
  40. 'url' => 'https://img.youtube.com/default.jpg'
  41. },
  42. 'standard' => {
  43. 'url' => 'https://img.youtube.com/standard.jpg'
  44. },
  45. 'maxres' => {
  46. 'url' => 'https://img.youtube.com/maxres.jpg'
  47. }
  48. }
  49. }
  50. }
  51. video = described_class.new(item)
  52. expect(video.thumbnail_url).to eq('https://img.youtube.com/maxres.jpg')
  53. end
  54. it 'falls back to empty raw tags' do
  55. item = {
  56. 'id' => 'video-1',
  57. 'snippet' => {
  58. 'title' => 'テスト動画',
  59. 'channelId' => 'UC123',
  60. 'publishedAt' => '2026-05-01T12:34:56Z',
  61. 'thumbnails' => {}
  62. }
  63. }
  64. video = described_class.new(item)
  65. expect(video.raw_tags).to eq([])
  66. end
  67. it 'returns nil thumbnail when no thumbnail exists' do
  68. item = {
  69. 'id' => 'video-1',
  70. 'snippet' => {
  71. 'title' => 'テスト動画',
  72. 'channelId' => 'UC123',
  73. 'publishedAt' => '2026-05-01T12:34:56Z',
  74. 'thumbnails' => {}
  75. }
  76. }
  77. video = described_class.new(item)
  78. expect(video.thumbnail_url).to be_nil
  79. end
  80. end
  81. end