2020-02-20 20:54:21 +01:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
test('Parse valid video id', () {
|
|
|
|
var id = 'en2D_5TzXCA';
|
|
|
|
expect(YoutubeExplode.parseVideoId(id), equals('en2D_5TzXCA'));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Parse id from youtube url', () {
|
|
|
|
var url = 'https://www.youtube.com/watch?v=en2D_5TzXCA';
|
|
|
|
expect(YoutubeExplode.parseVideoId(url), equals('en2D_5TzXCA'));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Get video title', () async {
|
|
|
|
var yt = YoutubeExplode();
|
|
|
|
var video = await yt.getVideo('en2D_5TzXCA');
|
|
|
|
expect(video.title, equals('Lady Gaga - Million Reasons'));
|
|
|
|
yt.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Parse invalid id', () {
|
|
|
|
var id = 'aaa';
|
|
|
|
expect(YoutubeExplode.parseVideoId(id), isNull);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Get video media stream', () async {
|
|
|
|
var yt = YoutubeExplode();
|
|
|
|
expect(await yt.getVideoMediaStream('en2D_5TzXCA'), isNotNull);
|
|
|
|
yt.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Get video media stream with invalid id', () async {
|
|
|
|
var yt = YoutubeExplode();
|
2020-03-06 23:17:34 +01:00
|
|
|
try {
|
|
|
|
await yt.getVideoMediaStream('aaa');
|
|
|
|
neverCalled();
|
|
|
|
// ignore: avoid_catches_without_on_clauses
|
|
|
|
} catch (e) {
|
|
|
|
expect(e, isArgumentError);
|
|
|
|
} finally {
|
|
|
|
yt.close();
|
|
|
|
}
|
2020-02-20 20:54:21 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: Implement more tests
|
|
|
|
}
|