forked from r8/elixir-oembed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oembed_test.exs
132 lines (109 loc) · 3.99 KB
/
oembed_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
defmodule OEmbedTest do
use ExUnit.Case, async: false
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
alias OEmbed.Rich
alias OEmbed.Video
test "gets error response for nil" do
{:error, _} = OEmbed.for(nil)
end
test "gets error response for empty string" do
{:error, _} = OEmbed.for("")
end
test "gets video oembed for valid youtube url" do
use_cassette "youtube_valid" do
{:ok, %Video{} = oembed} = OEmbed.for("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
assert oembed.html =~ "<iframe"
end
end
test "gets error response for invalid youtube id" do
use_cassette "youtube_invalid" do
{:error, _} = OEmbed.for("https://www.youtube.com/watch?v=invalid_id")
end
end
test "gets video oembed for valid youtube playlist" do
use_cassette "youtube_playlist_valid" do
{:ok, %Video{} = oembed} =
OEmbed.for("https://www.youtube.com/playlist?list=PL634F2B56B8C346A2")
assert oembed.html =~ "<iframe"
end
end
test "gets video oembed for invalid youtube playlist" do
use_cassette "youtube_playlist_invalid" do
{:error, _} = OEmbed.for("https://www.youtube.com/playlist?list=invalid_list")
end
end
test "gets video oembed for valid youtu.be url" do
use_cassette "youtu_be_valid" do
{:ok, %Video{} = oembed} = OEmbed.for("https://youtu.be/dQw4w9WgXcQ")
assert oembed.html =~ "<iframe"
end
end
test "gets error response for invalid youtu.be id" do
use_cassette "youtu_be_invalid" do
{:error, _} = OEmbed.for("https://youtu.be/invalid__id")
end
end
test "gets rich oembed for valid instagram url" do
use_cassette "instagram_valid" do
{:ok, %Rich{} = oembed} = OEmbed.for("https://www.instagram.com/p/BaOHwvclrzJ/")
assert oembed.html =~ "instagram-media"
end
end
test "gets rich oembed for valid instagram short url" do
use_cassette "instagram_short_valid" do
{:ok, %Rich{} = oembed} = OEmbed.for("http://instagr.am/p/BaOHwvclrzJ/")
assert oembed.html =~ "instagram-media"
end
end
test "gets error response for invalid instagram url" do
use_cassette "instagram_invalid" do
{:error, _} = OEmbed.for("https://www.instagram.com/p/invalid_url/")
end
end
test "gets rich oembed for valid pinterest pin url" do
use_cassette "pinterest_pin_valid" do
{:ok, %Rich{} = oembed} = OEmbed.for("https://www.pinterest.com/pin/731483164446834719/")
assert oembed.html =~ "embedPin"
end
end
test "gets error response for invalid pinterest url" do
use_cassette "pinterest_pin_invalid" do
{:error, _} = OEmbed.for("https://www.pinterest.com/pin/invalid_url/")
end
end
test "gets rich oembed for valid soundcloud url" do
use_cassette "soundcloud_valid" do
{:ok, %Rich{} = oembed} = OEmbed.for("https://soundcloud.com/forss/flickermood")
assert oembed.html =~ "soundcloud.com/player"
end
end
test "gets error response for invalid soundcloud url" do
use_cassette "soundcloud_invalid" do
{:error, _} = OEmbed.for("https://soundcloud.com/invalid_user/invalid_track")
end
end
test "gets oembed for valid url with relative oembed api link using http" do
use_cassette "playbuzz_http_valid" do
{:ok, %Rich{} = oembed} =
OEmbed.for(
"http://www.playbuzz.com/avibwx10/every-southerner-must-have-these-eats-at-least-once"
)
assert oembed.html =~ "pb_feed"
end
end
test "gets oembed for valid url with relative oembed api link using https" do
use_cassette "playbuzz_https_valid" do
{:ok, %Rich{} = oembed} =
OEmbed.for(
"https://www.playbuzz.com/avibwx10/every-southerner-must-have-these-eats-at-least-once"
)
assert oembed.html =~ "pb_feed"
end
end
test "gets rich oembed for valid vimeo url" do
use_cassette "vimeo_valid", match_requests_on: [:query] do
{:ok, %Video{} = oembed} = OEmbed.for("https://player.vimeo.com/videos/123123123/")
assert oembed.html =~ "vimeo"
end
end
end